Seperate Items For Actors

5 de abril de 2013
Seperate Items For Actors

Seperate Items For Actors é um script que o SephirothSpawn fez a pedidos para Katzbalger a pedidos.

O Seperate Items For Actors precisa do Standard Development Kit para funcionar, e deve ser adicionado acima do Main.

Veja a demo, disponível para download, para entender melhor o script.

#==============================================================================
# Seperate Items For Actors
#==============================================================================
# SephirothSpawn
# Version 1
# 2.2.05
# Thanks to Near Fantastica for his Keyboard Module, and Katzbalger for requesting it
#==============================================================================

#------------------------------------------------------------------------------
# * SDK Log Script
#------------------------------------------------------------------------------
SDK.log("Seperate Items For Actors", "SephirothSpawn", 1, "2.2.05")

#------------------------------------------------------------------------------
# * Begin SDK Enable Test
#------------------------------------------------------------------------------
if SDK.state("Seperate Items For Actors") == true
  
#==============================================================================
# ** Keyboard Input Module
#==============================================================================
# Near Fantastica
# Version 5
# 29.11.05
#==============================================================================
# The Keyboard Input Module is designed to function as the default Input module
# dose. It is better then other methods keyboard input because as a key is
# tested it is not removed form the list. so you can test the same key multiple
# times the same loop.
#==============================================================================

module Keyboard
  #--------------------------------------------------------------------------
  @keys = []
  @pressed = []
  Mouse_Left = 1
  Mouse_Right = 2
  Back= 8
  Tab = 9
  Enter = 13
  Shift = 16
  Ctrl = 17
  Alt = 18
  Esc = 27
  Space = 32
  Numberkeys = {}
  Numberkeys[0] = 48
  Numberkeys[1] = 49
  Numberkeys[2] = 50
  Numberkeys[3] = 51
  Numberkeys[4] = 52
  Numberkeys[5] = 53
  Numberkeys[6] = 54
  Numberkeys[7] = 55
  Numberkeys[8] = 56
  Numberkeys[9] = 57
  Numberpad = {}
  Numberpad[0] = 45
  Numberpad[1] = 35
  Numberpad[2] = 40
  Numberpad[3] = 34
  Numberpad[4] = 37
  Numberpad[5] = 12
  Numberpad[6] = 39
  Numberpad[7] = 36
  Numberpad[8] = 38
  Numberpad[9] = 33
  Letters = {}
  Letters["A"] = 65
  Letters["B"] = 66
  Letters["C"] = 67
  Letters["D"] = 68
  Letters["E"] = 69
  Letters["F"] = 70
  Letters["G"] = 71
  Letters["H"] = 72
  Letters["I"] = 73
  Letters["J"] = 74
  Letters["K"] = 75
  Letters["L"] = 76
  Letters["M"] = 77
  Letters["N"] = 78
  Letters["O"] = 79
  Letters["P"] = 80
  Letters["Q"] = 81
  Letters["R"] = 82
  Letters["S"] = 83
  Letters["T"] = 84
  Letters["U"] = 85
  Letters["V"] = 86
  Letters["W"] = 87
  Letters["X"] = 88
  Letters["Y"] = 89
  Letters["Z"] = 90
  Fkeys = {}
  Fkeys[1] = 112
  Fkeys[2] = 113
  Fkeys[3] = 114
  Fkeys[4] = 115
  Fkeys[5] = 116
  Fkeys[6] = 117
  Fkeys[7] = 118
  Fkeys[8] = 119
  Fkeys[9] = 120
  Fkeys[10] = 121
  Fkeys[11] = 122
  Fkeys[12] = 123
  Collon = 186
  Equal = 187
  Comma = 188
  Underscore = 189
  Dot = 190
  Backslash = 191
  Lb = 219
  Rb = 221
  Quote = 222
  State = Win32API.new("user32","GetKeyState",['i'],'i')
  Key = Win32API.new("user32","GetAsyncKeyState",['i'],'i')
  #--------------------------------------------------------------------------
  def Keyboard.getstate(key)
    return true unless State.call(key).between?(0, 1)
    return false
  end
  #--------------------------------------------------------------------------
  def Keyboard.testkey(key)
    Key.call(key) & 0x01 == 1
  end
  #--------------------------------------------------------------------------
  def Keyboard.update
    @keys = []
    @keys.push(Keyboard::Mouse_Left) if Keyboard.testkey(Keyboard::Mouse_Left)
    @keys.push(Keyboard::Mouse_Right) if Keyboard.testkey(Keyboard::Mouse_Right)
    @keys.push(Keyboard::Back) if Keyboard.testkey(Keyboard::Back)
    @keys.push(Keyboard::Tab) if Keyboard.testkey(Keyboard::Tab)
    @keys.push(Keyboard::Enter) if Keyboard.testkey(Keyboard::Enter)
    @keys.push(Keyboard::Shift) if Keyboard.testkey(Keyboard::Shift)
    @keys.push(Keyboard::Ctrl) if Keyboard.testkey(Keyboard::Ctrl)
    @keys.push(Keyboard::Alt) if Keyboard.testkey(Keyboard::Alt)
    @keys.push(Keyboard::Esc) if Keyboard.testkey(Keyboard::Esc)
    @keys.push(Keyboard::Space) if Keyboard.testkey(Keyboard::Space)
    for key in Keyboard::Numberkeys.values
      @keys.push(key) if Keyboard.testkey(key)
    end
    for key in Keyboard::Numberpad.values
      @keys.push(key) if Keyboard.testkey(key)
    end
    for key in Keyboard::Letters.values
      @keys.push(key) if Keyboard.testkey(key)
    end
    for key in Keyboard::Fkeys.values
      @keys.push(key) if Keyboard.testkey(key)
    end
    @keys.push(Keyboard::Collon) if Keyboard.testkey(Keyboard::Collon)
    @keys.push(Keyboard::Equal) if Keyboard.testkey(Keyboard::Equal)
    @keys.push(Keyboard::Comma) if Keyboard.testkey(Keyboard::Comma)
    @keys.push(Keyboard::Underscore) if Keyboard.testkey(Keyboard::Underscore)
    @keys.push(Keyboard::Dot) if Keyboard.testkey(Keyboard::Dot)
    @keys.push(Keyboard::Backslash) if Keyboard.testkey(Keyboard::Backslash)
    @keys.push(Keyboard::Lb) if Keyboard.testkey(Keyboard::Lb)
    @keys.push(Keyboard::Rb) if Keyboard.testkey(Keyboard::Rb)
    @keys.push(Keyboard::Quote) if Keyboard.testkey(Keyboard::Quote)
    @pressed = []
    @pressed.push(Keyboard::Mouse_Left) if Keyboard.getstate(Keyboard::Mouse_Left)
    @pressed.push(Keyboard::Mouse_Right) if Keyboard.getstate(Keyboard::Mouse_Right)
    @pressed.push(Keyboard::Back) if Keyboard.getstate(Keyboard::Back)
    @pressed.push(Keyboard::Tab) if Keyboard.getstate(Keyboard::Tab)
    @pressed.push(Keyboard::Enter) if Keyboard.getstate(Keyboard::Enter)
    @pressed.push(Keyboard::Shift) if Keyboard.getstate(Keyboard::Shift)
    @pressed.push(Keyboard::Ctrl) if Keyboard.getstate(Keyboard::Ctrl)
    @pressed.push(Keyboard::Alt) if Keyboard.getstate(Keyboard::Alt)
    @pressed.push(Keyboard::Esc) if Keyboard.getstate(Keyboard::Esc)
    @pressed.push(Keyboard::Space) if Keyboard.getstate(Keyboard::Space)
    for key in Keyboard::Numberkeys.values
      @pressed.push(key) if Keyboard.getstate(key)
    end
    for key in Keyboard::Numberpad.values
      @pressed.push(key) if Keyboard.getstate(key)
    end
    for key in Keyboard::Letters.values
      @pressed.push(key) if Keyboard.getstate(key)
    end
    for key in Keyboard::Fkeys.values
      @pressed.push(key) if Keyboard.getstate(key)
    end
    @pressed.push(Keyboard::Collon) if Keyboard.getstate(Keyboard::Collon)
    @pressed.push(Keyboard::Equal) if Keyboard.getstate(Keyboard::Equal)
    @pressed.push(Keyboard::Comma) if Keyboard.getstate(Keyboard::Comma)
    @pressed.push(Keyboard::Underscore) if Keyboard.getstate(Keyboard::Underscore)
    @pressed.push(Keyboard::Dot) if Keyboard.getstate(Keyboard::Dot)
    @pressed.push(Keyboard::Backslash) if Keyboard.getstate(Keyboard::Backslash)
    @pressed.push(Keyboard::Lb) if Keyboard.getstate(Keyboard::Lb)
    @pressed.push(Keyboard::Rb) if Keyboard.getstate(Keyboard::Rb)
    @pressed.push(Keyboard::Quote) if Keyboard.getstate(Keyboard::Quote)
  end
  #--------------------------------------------------------------------------
  def Keyboard.trigger?(key)
    return true if @keys.include?(key)
    return false
  end
  #--------------------------------------------------------------------------
  def Keyboard.pressed?(key)
    return true if @pressed.include?(key)
    return false
  end
end

#==============================================================================
# ** Bitmap
#==============================================================================

class Bitmap
  #--------------------------------------------------------------------------
  # * Scale Blt
  #--------------------------------------------------------------------------
  def scale_blt(dest_rect, src_bitmap, 
    src_rect = Rect.new(0, 0, src_bitmap.width, src_bitmap.height), opacity = 255)
    w, h = src_rect.width, src_rect.height
    scale = [w / dest_rect.width.to_f, h / dest_rect.height.to_f].max
    ow, oh = (w / scale).to_i, (h / scale).to_i
    ox, oy = (dest_rect.width - ow) / 2, (dest_rect.height - oh) / 2
    stretch_blt(Rect.new(ox + dest_rect.x, oy + dest_rect.y, ow, oh), 
      src_bitmap, src_rect )
  end
end

#==============================================================================
# ** Game_Party
#==============================================================================

class Game_Party
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :items
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_individualactorcache_gameparty_item_number item_number
  #--------------------------------------------------------------------------
  # * Get Number of Items Possessed
  #     item_id : item ID
  #--------------------------------------------------------------------------
  def item_number(item_id)
    # If In Battle, loads Active Battler Numbers
    if $game_temp.in_battle
      n = 0
      for item in $scene.active_battler.item_cache
        if item.id == item_id
          n += 1
        end
      end
      return n
    else
      # If quantity data is in the hash, use it. If not, return 0
      return @items.include?(item_id) ? @items[item_id] : 0
    end
  end
end

#==============================================================================
# ** Game_Actor
#==============================================================================

class Game_Actor
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_accessor :item_cache
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_individualactorcache_gameactor_setup setup
  #--------------------------------------------------------------------------
  # * Setup
  #--------------------------------------------------------------------------
  def setup(actor_id)
    # Sets Item Cache
    @item_cache = []
    # Original Actor Setup Method
    seph_individualactorcache_gameactor_setup(actor_id)
  end
  #--------------------------------------------------------------------------
  # * Assign Item
  #     item_id : Items ID #
  #--------------------------------------------------------------------------
  def assign_item(item_id)
    item = $data_items[item_id]
    unless item.nil?
      @item_cache << item
      @item_cache.sort! {|a, b| a.id<=>b.id}
      item_number = $game_party.items.include?(item_id) ? $game_party.items[item_id] : 0
      $game_party.items[item_id] = [[item_number - 1, 0].max, 99].min
    end
  end
  #--------------------------------------------------------------------------
  # * Unassign Item
  #     item_id : Items ID #
  #--------------------------------------------------------------------------
  def unassign_item(item_id)
    item = $data_items[item_id]
    unless item.nil?
      if @item_cache.include?(item)
        use_item(item_id)
        $game_party.gain_item(item_id, 1)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Use Item
  #     item_id : Items ID #
  #--------------------------------------------------------------------------
  def use_item(item_id)
    item = $data_items[item_id]
    unless item.nil?
      for i in 0...@item_cache.size
        if item == @item_cache[i]
          @item_cache.delete_at(i)
          break
        end
      end
    end
  end
end

#==============================================================================
# ** Scene_Battle
#==============================================================================

class Scene_Battle
  #--------------------------------------------------------------------------
  # * Public Instance Variables
  #--------------------------------------------------------------------------
  attr_reader :active_battler
end

#==============================================================================
# ** Window_Item
#==============================================================================

class Window_Item < Window_Selectable
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # For Out Of Battle Use
    unless $game_temp.in_battle
      # Add item
      for i in 1...$data_items.size
        if $game_party.item_number(i) > 0
          @data.push($data_items[i])
        end
      end
      # Adds In Actor Item Cache
      for actor in $game_party.actors
        for item in actor.item_cache
          @data << item unless @data.include?(item)
        end
      end
      # Also add weapons and items if outside of battle
      for i in 1...$data_weapons.size
        if $game_party.weapon_number(i) > 0
          @data.push($data_weapons[i])
        end
      end
      for i in 1...$data_armors.size
        if $game_party.armor_number(i) > 0
          @data.push($data_armors[i])
        end
      end
    # For In Battle Use
    else
      for item in $scene.active_battler.item_cache
        @data << item
      end
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
end

#==============================================================================
# ** Window_ItemCacheHeading
#==============================================================================

class Window_ItemCacheHeading < Window_Base
  #--------------------------------------------------------------------------
  # * Constant
  #--------------------------------------------------------------------------
  DRAW_CHARACTER = true
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor_index)
    super(actor_index * 160, 64, 160, 160)
    self.contents = Bitmap.new(width - 32, height - 32)
    @frame = 0
    refresh(@actor = $game_party.actors[actor_index])
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh(actor = @actor)
    self.contents.clear
    @actor = actor
    return if @actor.nil?
    # Draws Actors Name
    self.contents.draw_text(4, 0, contents.width - 8, 32, @actor.name, 1)
    # Draws Actors Sprite
    if DRAW_CHARACTER
      draw_sprite(0, 32, 128, 96, @actor.character_name, @actor.character_hue, 0, @frame)
    else
      bitmap = RPG::Cache.battler(@actor.battler_name, @actor.battler_hue)
      self.contents.scale_blt(Rect.new(0, 32, 128, 96), bitmap)
    end
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    super
    # If Character Sprite
    if DRAW_CHARACTER
      if Graphics.frame_count % 10 == 0
        @frame == 3 ? @frame = 0 : @frame += 1
        refresh
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Sprite
  #--------------------------------------------------------------------------
  def draw_sprite(x, y, w, h, name, hue, stance, frame)
    # Gets Bitmap
    bitmap = RPG::Cache.character(name, hue)
    # Bitmap Division
    cw, ch = bitmap.width / 4,  bitmap.height / 4
    # Gets Animation Offsets
    x_off, y_off = cw * frame, ch * stance
    # Draws Bitmap
    self.contents.scale_blt(Rect.new(x, y, w, h), bitmap, Rect.new(x_off, y_off, cw, ch))
  end
end

#==============================================================================
# ** Window_ItemCache
#==============================================================================

class Window_ItemCache < Window_Selectable
  #--------------------------------------------------------------------------
  # * Object Initialization
  #--------------------------------------------------------------------------
  def initialize(actor_index)
    super(actor_index * 160, 224, 160, 256)
    @actor = $game_party.actors[actor_index]
    refresh
    self.index = 0
    self.active = false
  end
  #--------------------------------------------------------------------------
  # * Get Item
  #--------------------------------------------------------------------------
  def item
    return @data[self.index]
  end
  #--------------------------------------------------------------------------
  # * Refresh
  #--------------------------------------------------------------------------
  def refresh
    if self.contents != nil
      self.contents.dispose
      self.contents = nil
    end
    @data = []
    # Adds In Actor Item Cache
    @actor.item_cache.sort! {|a, b| a.id<=>b.id}
    for item in @actor.item_cache
      @data << item
    end
    # If item count is not 0, make a bit map and draw all items
    @item_max = @data.size
    if @item_max > 0
      self.contents = Bitmap.new(width - 32, row_max * 32)
      for i in 0...@item_max
        draw_item(i)
      end
    end
  end
  #--------------------------------------------------------------------------
  # * Draw Item
  #     index : item number
  #--------------------------------------------------------------------------
  def draw_item(index)
    item, y = @data[index], index * 32
    bitmap = RPG::Cache.icon(item.icon_name)
    self.contents.blt(0, y + 4, bitmap, Rect.new(0, 0, 24, 24))
    self.contents.draw_text(32, y, 212, 32, item.name)
  end
end

#==============================================================================
# ** Scene_ActorCache
#==============================================================================

class Scene_ItemCache
  #--------------------------------------------------------------------------
  # * Main Processing
  #--------------------------------------------------------------------------
  def main
    @help_window = Window_Help.new
      @help_window.set_text('Select Item To Unassign', 1)
    @scene_objects = [@help_window]
    for i in 0..3
      eval "@actor_#{i}_heading = Window_ItemCacheHeading.new(#{i})"
      eval "@scene_objects << @actor_#{i}_heading"
      eval "@actor_#{i}_cache = Window_ItemCache.new(#{i})"
      eval "@scene_objects << @actor_#{i}_cache"
    end
    @actor_0_cache.active = true
    @actor_index = 0
    # Execute transition
    Graphics.transition
    # Main loop
    while $scene == self
      # Update game screen
      Graphics.update
      # Update input information
      Input.update
      # Updates Scene Objects
      @scene_objects.each {|x| x.update}
      # Frame update
      update
    end
    # Prepare for transition
    Graphics.freeze
    # Dispose Scene Objects
    @scene_objects.each {|x| x.dispose}
  end
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # If B button is pressed
    if Input.trigger?(Input::B)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to menu screen
      $scene = Scene_Menu.new
    end
    # If C button is pressed
    if Input.trigger?(Input::C)
      item = eval "@[email protected]_index}_cache.item"
      if item.nil?
        # Plays Buzzer SE
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Plays Decision SE
      $game_system.se_play($data_system.decision_se)
      # Usassins Item
      $game_party.actors[@actor_index].unassign_item(item.id)
      # Refreshes Window
      eval "@[email protected]_index}_cache.refresh"
    end
    # If Left or Right Buttons Are Pressed
    if Input.trigger?(Input::LEFT)
      # Plays Cursor SE
      $game_system.se_play($data_system.cursor_se)
      # Deativates Current Window
      eval "@[email protected]_index}_cache.active = false"
      # Changes Window Index
      @actor_index == 0 ? @actor_index = 3 : @actor_index -= 1
      # Actives New Window
      eval "@[email protected]_index}_cache.active = true"
    elsif Input.trigger?(Input::RIGHT)
      # Plays Cursor SE
      $game_system.se_play($data_system.cursor_se)
      # Deativates Current Window
      eval "@[email protected]_index}_cache.active = false"
      # Changes Window Index
      @actor_index == 3 ? @actor_index = 0 : @actor_index += 1
      # Actives New Window
      eval "@[email protected]_index}_cache.active = true"
    end
    # If A button is pressed
    if Input.trigger?(Input::A)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to Item Cache screen
      $scene = Scene_Item.new
      return
    end
  end
end

#==============================================================================
# ** Scene_Item
#==============================================================================

class Scene_Item
  #--------------------------------------------------------------------------
  # * Alias Listings
  #--------------------------------------------------------------------------
  alias seph_individualactorcache_sceneitem_update update
  #--------------------------------------------------------------------------
  # * Frame Update
  #--------------------------------------------------------------------------
  def update
    # Updates Near's Keyboard Module
    Keyboard.update
    # Assign To Player 1
    if Keyboard.trigger?(Keyboard::Numberkeys[1])
      # If Actor is nil
      if $game_party.actors[0].nil?
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Plays Decison SE
      $game_system.se_play($data_system.decision_se)
      # Assigns Item
      $game_party.actors[0].assign_item(@item_window.item.id)
      # Refreshs Window
      @item_window.refresh
    end
    # Assign To Player 2
    if Keyboard.trigger?(Keyboard::Numberkeys[2])
      # If Actor is nil
      if $game_party.actors[1].nil?
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Plays Decison SE
      $game_system.se_play($data_system.decision_se)
      # Assigns Item
      $game_party.actors[1].assign_item(@item_window.item.id)
      # Refreshs Window
      @item_window.refresh
    end
    # Assign To Player 3
    if Keyboard.trigger?(Keyboard::Numberkeys[3])
      # If Actor is nil
      if $game_party.actors[2].nil?
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Plays Decison SE
      $game_system.se_play($data_system.decision_se)
      # Assigns Item
      $game_party.actors[2].assign_item(@item_window.item.id)
      # Refreshs Window
      @item_window.refresh
    end
    # Assign To Player 4
    if Keyboard.trigger?(Keyboard::Numberkeys[4])
      # If Actor is nil
      if $game_party.actors[3].nil?
        $game_system.se_play($data_system.buzzer_se)
        return
      end
      # Plays Decison SE
      $game_system.se_play($data_system.decision_se)
      # Assigns Item
      $game_party.actors[3].assign_item(@item_window.item.id)
      # Refreshs Window
      @item_window.refresh
    end
    # If A button is pressed
    if Input.trigger?(Input::A)
      # Play cancel SE
      $game_system.se_play($data_system.cancel_se)
      # Switch to item screen
      $scene = Scene_ItemCache.new
    end
    # Orginal Update Method
    seph_individualactorcache_sceneitem_update
  end
end

#--------------------------------------------------------------------------
# * End SDK Enable Test
#--------------------------------------------------------------------------
end
site ou autor do arquivo SephirothSpawn tamanho do arquivo 209KB sistemas operacionais compativeisWindows 98/98SE/Me/2000/XP/Vista/7 Download

Deixe um comentário

  • Seja social e nos siga!

           
  • Páginas

  • Tags Especiais

  • Categorias

  • Parceiros

  • eXTReMe Tracker
    Copyright © 2001 - 2017 Gaming Room. Todos os Direitos Reservados - É expressamente proibida a reprodução total ou parcial deste site sem o consentimento dos autores.