The RPG Maker Resource Kit

RMRK RPG Maker Creation => Requests => Script Request => Topic started by: apoclaydon on August 21, 2012, 11:58:18 PM

Title: [RPG Maker VXAce] Enemy Start States
Post by: apoclaydon on August 21, 2012, 11:58:18 PM
i would like a script that allows you to define the starting states of enemies (like if you want an enemy to always be confused then you can add a note tag or add a table in the script that states that the enemy starts off with the confused state already in play
Title: Re: [RPG Maker VXAce] Enemy Start States
Post by: modern algebra on August 22, 2012, 01:28:19 AM
Haven't tried it, but is there any reason you couldn't just go into all the troops with the auto-stated enemies and make a battle event running at Turn 0 to apply the state to the enemies?

Alternately, maybe Yanfly's Passive Skills script would have a feature like that, though I haven't looked into that.
Title: Re: [RPG Maker VXAce] Enemy Start States
Post by: TDS on August 22, 2012, 01:58:33 AM
This should do it.


#==============================================================================
# ** Game_Enemy
#------------------------------------------------------------------------------
#  This class handles enemies. It used within the Game_Troop class
# ($game_troop).
#==============================================================================

class Game_Enemy < Game_Battler
  #--------------------------------------------------------------------------
  # * Alias Listing
  #-------------------------------------------------------------------------- 
  alias tds_enemy_starting_states_game_enemy_on_battle_start  on_battle_start
  #--------------------------------------------------------------------------
  # * Processing at Start of Battle
  #--------------------------------------------------------------------------
  def on_battle_start(*args, &block)
    # Run Original Method
    tds_enemy_starting_states_game_enemy_on_battle_start(*args, &block)
    # Match Enemy Notes for Starting States
    enemy.note[/<Starting_States: (.+)>/i]
    # Add Starting States if Match is not nil
    $1.split(/\s+/).each {|id| add_state(id.to_i)} if !$1.nil?
  end
end


Just add this to the enemy note box:


<Starting_States: state_id>


state_id is the ID of the state you want the enemy to start with. You can have as many ID's as you can fit, like so:


<Starting_States: 2 3 4 5 6 7 8 9 10 11>


Or


<Starting_States: 1>


Let me know if that works and if you want anything added/removed.

Have a nice day.
Title: Re: [RPG Maker VXAce] Enemy Start States
Post by: modern algebra on August 22, 2012, 02:30:29 AM
Looks good TDS! :) My only suggestion would be accomodate for more than one space between IDs by changing: $1.split(/\s/) to $1.split(/\s+/)

It literally makes no difference, as even as it is, the empty spots would just become 0s and when you try to add them as a state they will return false at state_addable?

Additionally, the collect is a bit redundant. It could equivalently be:

$1.split(/\s+/).each {|id| add_state(id.to_i)} if !$1.nil?

Anyway, neither of those comments are meaningful problems; it's a very smooth and efficient script.
Title: Re: [RPG Maker VXAce] Enemy Start States
Post by: TDS on August 22, 2012, 02:48:35 AM
Thanks, I always appreciate the advice. As for the collect, now that I see it I can't understand why I was using it in the first place, I must really be off my game.
Title: Re: [RPG Maker VXAce] Enemy Start States
Post by: apoclaydon on August 22, 2012, 06:25:44 AM
thank you and will try it out when i get home
Title: Re: [RPG Maker VXAce] Enemy Start States
Post by: apoclaydon on August 22, 2012, 07:58:33 PM
that works really well thank you