ezmash

State Add/Remove Commands (VX Ace)

Sep 29th, 2013
1,397
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #============================================================================
  2. # State Commands
  3. # v1.2 by Shaz
  4. #----------------------------------------------------------------------------
  5. # This script will let you run commands when a state is added or removed
  6. # from a battler.
  7. #----------------------------------------------------------------------------
  8. # To Install:
  9. # Copy and paste into a new script slot in Materials.  This script aliases
  10. # existing methods, so can go below all other custom scripts.
  11. #----------------------------------------------------------------------------
  12. # To Use:
  13. # To execute a command when a state is added, add the following line to the
  14. # state's notes:
  15. #    onadd: command
  16. #
  17. # To execute a command when a state is removed, add the following line to the
  18. # state's notes:
  19. #    onremove: command
  20. #
  21. # command is a RGSS script command that will be eval'd, so it may consist of
  22. # any valid script command.  It may extend over more than one line, and may
  23. # consist of several commands separated by semi-colons, but it must NOT be
  24. # broken by pressing the Enter key (just keep typing and let the editor put
  25. # in its own line breaks by default).
  26. #
  27. # Examples:
  28. # - this will just print a line of text to the console when the state is added
  29. #   onadd: p 'state added'
  30. #
  31. # - this will print a line of text to the console AND reserve a common event
  32. #   to be run on the map when the state is removed - note it's done over
  33. #   two commands/lines (the second line will automatically wrap to 2 lines)
  34. #   onremove: p 'state removed'
  35. #   onremove: $game_temp.reserve_common_event(1)
  36. #
  37. # - this will run one of two commands based on the battler's current hp when
  38. #   a state is added (enter key is not used here to go to a second line)
  39. #   onadd: if hp_rate < 0.5; p 'low hp - need topup';
  40. #   else; p 'hp good'; end;
  41. #----------------------------------------------------------------------------
  42. # Terms:
  43. # Use in free or commercial games
  44. # Credit Shaz
  45. #----------------------------------------------------------------------------
  46. # Versions
  47. # 1.1  initial release
  48. # 1.2  fix issue were add state is not working properly
  49. #============================================================================
  50.  
  51. class Game_Battler < Game_BattlerBase
  52.   #--------------------------------------------------------------------------
  53.   # * Clear State Information
  54.   #--------------------------------------------------------------------------
  55.   alias shaz_state_commands_clear_states clear_states
  56.   def clear_states
  57.     @states.each {|state_id| state_remove_command(state_id) } if @states
  58.     shaz_state_commands_clear_states
  59.   end
  60.   #--------------------------------------------------------------------------
  61.   # * Add New State
  62.   #--------------------------------------------------------------------------
  63.   alias shaz_state_commands_add_new_state add_new_state
  64.   def add_new_state(state_id)
  65.     if !state?(state_id)
  66.       shaz_state_commands_add_new_state(state_id)
  67.       state_add_command(state_id)
  68.     end
  69.   end
  70.   #--------------------------------------------------------------------------
  71.   # * Erase State
  72.   #--------------------------------------------------------------------------
  73.   def erase_state(state_id)
  74.     state_remove_command(state_id) if state?(state_id)
  75.     super
  76.   end
  77.   #--------------------------------------------------------------------------
  78.   # * State Add Commands
  79.   #--------------------------------------------------------------------------
  80.   def state_add_command(state_id)
  81.     $data_states[state_id].note.split(/[\r\n]/).each do |line|
  82.       case line
  83.       when /onadd:\s*(.*)/i
  84.         eval($1)
  85.       end
  86.     end
  87.   end
  88.   #--------------------------------------------------------------------------
  89.   # * State Remove Commands
  90.   #--------------------------------------------------------------------------
  91.   def state_remove_command(state_id)
  92.     $data_states[state_id].note.split(/[\r\n]/).each do |line|
  93.       case line
  94.       when /onremove:\s*(.*)/i
  95.         eval($1)
  96.       end
  97.     end
  98.   end
  99. end
RAW Paste Data