neonblack

Gem Drop

Jan 27th, 2013
144
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #==============================================================================
  2. # ** Archeia Gem Parade
  3. #------------------------------------------------------------------------------
  4. #  How to use: GEM_DROP: item_id drop_rate skill_id/actor_id
  5. #  Example: GEM_DROP: 28 0 Actor 5
  6. #  Skill_id 0 means it drops from any skill
  7. #  0 drop rate = 100% Guaranteed. It follows VX Drop Rate EX 100 = 1/100
  8. #==============================================================================
  9.  
  10. class Scene_Battle < Scene_Base
  11.   WAIT_TIME = 50
  12.  
  13.   #--------------------------------------------------------------------------
  14.   # * Alias Listings
  15.   #--------------------------------------------------------------------------  
  16.   alias tds_archeia_gem_parade_scene_battle_execute_action     execute_action  
  17.   #--------------------------------------------------------------------------
  18.   # * Execute Battle Actions
  19.   #--------------------------------------------------------------------------
  20.   def execute_action
  21.     # Run Original Method
  22.     tds_archeia_gem_parade_scene_battle_execute_action
  23.     # Return if Subject is an enemy
  24.     return if @subject.enemy?
  25.     # If Subject Gem Drops is not nil or empty
  26.     if !@subject.gem_drops.nil? and !@subject.gem_drops.empty?
  27.       # Go Through Gem Drops
  28.       @subject.gem_drops.each_value {|array|
  29.         array.each do |item|
  30.           # Show Drop Message
  31.           @log_window.add_pop_array(item.icon_index, "#{item.name} obtained")
  32.           abs_wait(WAIT_TIME)
  33.           # Gain Item
  34.           $game_party.gain_item(item, 1)
  35.         end
  36.       }
  37.       # Subject Clear Gem Drops
  38.       # Changed into a hash ~Kread
  39.       @subject.gem_drops = {}
  40.     end
  41.   end
  42. end
  43.  
  44.  
  45. #==============================================================================
  46. # ** Game_Battler
  47. #------------------------------------------------------------------------------
  48. #  This class deals with battlers. It's used as a superclass of the Game_Actor
  49. # and Game_Enemy classes.
  50. #==============================================================================
  51.  
  52. class Game_Battler < Game_BattlerBase
  53.   #--------------------------------------------------------------------------
  54.   # * Public Instance Variables
  55.   #--------------------------------------------------------------------------
  56.   attr_accessor :gem_drops                                  # Gem Drops Array
  57.   #--------------------------------------------------------------------------
  58.   # * Alias Listings
  59.   #--------------------------------------------------------------------------  
  60.   alias tds_archeia_gem_parade_game_battler_item_apply            item_apply
  61.   #--------------------------------------------------------------------------
  62.   # * Apply Item Effect
  63.   #--------------------------------------------------------------------------
  64.   def item_apply(user, item)    
  65.     # Run Original Method
  66.     tds_archeia_gem_parade_game_battler_item_apply(user, item)
  67.     # If User is an actor and Target is not
  68.     if user.actor? and self.enemy? and self.dead?
  69.       # Clear User Gem Drops Array (Hash and Array now ~Kread)
  70.       user.gem_drops = {} if user.gem_drops.nil?
  71.       # Fixes multi hits attacks ~Kread
  72.       return if user.gem_drops[self.index] != nil
  73.       self.enemy.note.scan(/GEM_DROP: (\d+) (\d+) (\w+) (\d+)/) {|id, drop, obj, obj_id|
  74.         next if obj == "Skill" and obj_id.to_i > 0 and item.id != obj_id.to_i
  75.         next if obj == "Actor" and user.id != obj_id.to_i
  76.         next if rand(drop.to_i).to_i > 0        
  77.         # Add Item to Gem Drops
  78.         user.gem_drops[self.index] = [] if user.gem_drops[self.index].nil?
  79.         user.gem_drops[self.index] << $data_items[id.to_i]
  80.       }      
  81.     end
  82.   end  
  83. end
  84.  
  85. # Puts this in your Gem Parade script to fix the counter attack issue.
  86.  
  87. #==============================================================================
  88. # ** Scene_Battle
  89. #==============================================================================
  90.  
  91. class Scene_Battle < Scene_Base
  92.   #--------------------------------------------------------------------------
  93.   # * Counterattack execution
  94.   #--------------------------------------------------------------------------
  95.   alias_method(:krx_nessy_gem_sb_ic, :invoke_counter_attack)
  96.   def invoke_counter_attack(target, item)
  97.     krx_nessy_gem_sb_ic(target, item)
  98.     if @subject.enemy?
  99.       if !target.gem_drops.nil? && !target.gem_drops.empty?
  100.         #target.gem_drops.each {|gem|
  101.         target.gem_drops.each_value {|array|
  102.           array.each do |gem|
  103.             @log_window.add_pop_array(gem.icon_index, "#{gem.name} obtained")
  104.             abs_wait(WAIT_TIME)
  105.             $game_party.gain_item(gem, 1)
  106.           end
  107.         }
  108.         target.gem_drops = {}
  109.       end
  110.     end
  111.   end
  112. end
RAW Paste Data