[ACE] Including states in Tsukihime's monster hunter script

So looking at the monster hunter script I wanted to see if I could tweak it to add a conditional to check states, which would affect the monster's capture rate. Note I am also using stacked states for the stack_state check to see if states are stacked. If stacked it increases chance of capture.

The error I get after all of my actors use their battle commands is "nil cant be coerced to fixnum.

Default code, where enemy capture rate = enemy capture rate, self explanatory

  alias monster_hunter_enemy_initialize initialize  def initialize(index, enemy_id)    monster_hunter_enemy_initialize(index, enemy_id)    @capture_rate = enemy.capture_rate    @no_capture = enemy.no_capture    @last_hit_item = Game_BaseItem.new    @last_hit_user = nil  endWhen I modified it, didn't work.

Code:
  alias monster_hunter_enemy_initialize initialize  def initialize(index, enemy_id)    monster_hunter_enemy_initialize(index, enemy_id)       size = $game_troop.members.size    i = 0    while i < size      a = $game_troop.members[i]      if a.state?(25)        @capture_rate = ((a.state_stack(25)*10) + enemy.capture_rate)      else        @capture_rate = enemy.capture_rate      end      i = i+1    end      @no_capture = enemy.no_capture    @last_hit_item = Game_BaseItem.new    @last_hit_user = nil  end
You made it in initialize method, which is called when creating enemy and not called anymore after that.

Remember that when the first enemy is created, the size of $game_troop.members is 0. This leads to @capture_rate not being initialized.

You might want to overwrite Hime's Game_Enemy's is_captured? method for this.
Ya I'd overwrite it. This thing is just hardcoded and pretty terrible

Code:
@last_hit_item.capture_rate + @capture_rate - rand(100) > 0
Oh wow, I completely ignored to see it was in initialize, thanks for pointing that out. Now everything seems to work, somewhat.

Original thread: https://forums.rpgmakerweb.com/threads/ace-including-states-in-tsukihimes-monster-hunter-script.25672/