[Review]DoubleX RMVXA State Triggers

Purpose
Sets some states to trigger additional effects when conditions are met

Notetag
  1. #  * State Notetags:                                                           |
  2. #    1. <timing state trigger: stcx, stax>                                     |
  3. #       - Sets a state to trigger stax when timing and stcx are met            |
  4. #       - timing can be add, turn, remove or custom timings set by you         |
  5. #       - add means the state's just added                                     |
  6. #       - turn means the state's remaining turn's just reduced by 1            |
  7. #       - remove means the state's just removed                                |
  8. #       - while means the stax effects are active as long as the state's active|
  9. #       - timing must only consist of alphanumeric characters                  |
  10. #       - stcx can be set in State Trigger Condition Notetag Values            |
  11. #       - stax can be set in State Trigger Action Notetag Values               |
Expand to see the code.

  1.    #--------------------------------------------------------------------------|
  2.     #  State Trigger Condition Notetag Values                                  |
  3.     #  - Setups stcx used by this script's notetags                            |
  4.     #--------------------------------------------------------------------------|
  5.     # stcx are read at:
  6.     # 1. RPG::State
  7.     #    - (@state_triggers[$1.downcase.to_sym] ||= []).push(
  8.     #      [$2.downcase, $3.downcase]) in load_state_triggers_notes
  9.     # stcx are used at:
  10.     # 1. Game_BattlerBase
  11.     #    - triggers.any? { |trigger| st.send(trigger[0], self, state) } in
  12.     #      meet_any_state_trigger?
  13.     #    - st.send(trigger[0], self, state) in state_trigger_features
  14.     # 2. Game_Battler
  15.     #    - st.send(trigger[1], self) if st.send(trigger[0], self) in
  16.     #      exec_state_triggers
  17.     # stcx are strings names of methods under DoubleX_RMVXA::State_Triggers
  18.     # stcx names can only use alphanumeric characters and can't use uppercase
  19.     # letters
  20.     # battler is the battler calling the stcx
  21.     # state is the state using the stcx
  22.     # The below stcx are examples added to help you set your stcx
  23.     # You can freely use, rewrite and/or delete these examples
  24.  
  25.     # Sets the state trigger condition as always true
  26.     def self.stc1(battler, state)
  27.       true
  28.     end
  29.  
  30.     # Sets the state trigger condition as always false
  31.     def self.stc2(battler, state)
  32.       false
  33.     end
  34.  
  35.     # Sets the state trigger condition as needing switch with id x to be on
  36.     def self.stc3(battler, state)
  37.       $game_switches[x]
  38.     end
  39.  
  40.     # Sets the state trigger condition as needing the state using this stcx to
  41.     # have its number of remaining turns greater than x
  42.     def self.stc4(battler, state)
  43.       battler.instance_exec { @state_turns[state_id] > x }
  44.     end
  45.  
  46.     # Adds new stcx here
  47.    
  48.  
  49.     #--------------------------------------------------------------------------|
  50.     #  State Trigger Action Notetag Values                                     |
  51.     #  - Setups stax used by this script's notetags                            |
  52.     #--------------------------------------------------------------------------|
  53.     # stax are read at:
  54.     # 1. RPG::State
  55.     #    - (@state_triggers[$1.downcase.to_sym] ||= []).push(
  56.     #      [$2.downcase, $3.downcase]) in load_state_triggers_notes
  57.     # stax are used at:
  58.     # 1. Game_BattlerBase
  59.     #    - }.collect! { |trigger| st.send(trigger[1], self, state) }.flatten! in
  60.     #      state_trigger_features
  61.     # 2. Game_Battler
  62.     #    - st.send(trigger[1], self) if st.send(trigger[0], self) in
  63.     #      exec_state_triggers
  64.     # stax are strings of names of methods under DoubleX_RMVXA::State_Triggers
  65.     # stax names can only use alphanumeric characters and can't use uppercase
  66.     # letters
  67.     # battler is the battler calling the stax
  68.     # state is the state using the stax
  69.     # If the timing using the stax is while, the stax must return an array of
  70.     # RPG::BaseItem::Feature
  71.     # You can refer to Game_BattlerBase and RPG::BaseItem::Feature for more info
  72.     # The below stax are examples added to help you set your stax
  73.     # You can freely use, rewrite and/or delete these examples
  74.  
  75.     # Sets the state trigger action as what Special Effect Escape does
  76.     # This stax's not supposed to work with the timing while as it doesn't
  77.     # return an array of RPG::BaseItem::Feature
  78.     def self.sta1(battler, state)
  79.       battler.hide
  80.     end
  81.  
  82.     # Sets the state trigger action as calling common event with id
  83.     # common_event_id
  84.     # This stax's not supposed to work with the timing while as it doesn't
  85.     # return an array of RPG::BaseItem::Feature
  86.     def self.sta2(battler, state)
  87.       $game_temp.reserve_common_event(common_event_id)
  88.     end
  89.  
  90.     # Sets the state trigger action as executing damage equal to the value of
  91.     # game variable with id x to self with type equal to that of skill with id
  92.     # equal to y
  93.     # This stax's not supposed to work with the timing while as it doesn't
  94.     # return an array of RPG::BaseItem::Feature
  95.     def self.sta3(battler, state)
  96.       battler.result.clear
  97.       battler.result.make_damage($game_variables[x], $data_skills[y])
  98.       battler.execute_damage(battler)
  99.     end
  100.  
  101.     # Sets the state trigger action as multiplying the battler's atk by x * 100%
  102.     # This stax's supposed to work with the timing while as it returns an array
  103.     # of RPG::BaseItem::Feature
  104.     def self.sta4(battler, state)
  105.       [RPG::BaseItem::Feature.new(21, 2, x)]
  106.     end
  107.  
  108.     # Adds new stax here
  109.    
Expand to see the code.


Script Call
  1. #  * Battler manipulations                                                     |
  2. #    1. exec_state_triggers(state_id, timing)                                  |
  3. #       - Executes all state triggers with timing timing of state with id      |
  4. #         state_id                                                             |
  5. #    2. meet_any_state_trigger?(state, timing)                                 |
  6. #       - Checks if any stcx with timing timing of state state is met          |
  7. #    3. state_trigger_features(state, timing)                                  |
  8. #       - Returns an array of features returned by all stax meeting stcx with  |
  9. #         timing timing of state                                               |
  10. #       - This script call's not supposed to work with timing add, turn nor    |
  11. #         remove but supposed to work with timing while                        |
Expand to see the code.


Games Using This Script
None so far

Prerequisites
Abilities:
1. Decent RGSS3 scripting proficiency to fully utilize this script

Terms Of Use
You shall keep this script's Script Info part's contents intact
You shalln't claim that this script is written by anyone other than DoubleX or his aliases
None of the above applies to DoubleX or his aliases

Instructions
1. Open the script editor and put this script into an open slot between Materials and Main, save to take effect.

Authors
DoubleX

Changelog
  1. #    v1.03a(GMT 1500 9-5-2016):                                                |
  2. #    1. adding the timing while to <timing state trigger: stcx, stax>          |
  3. #    v1.02a(GMT 1300 26-2-2016):                                               |
  4. #    1. stcx and stax take the state calling them as an argument as well       |
  5. #    v1.01b(GMT 0300 7-11-2015):                                               |
  6. #    1. Notetag values are now symbols of methods in the configuration regions |
  7. #    2. This script doesn't need DoubleX RMVXA State Triggers Compatibility to |
  8. #       be compatible with all its addressed scripts                           |
  9. #    3. Further improved this script's compatibility, efficiency and simplicity|
  10. #    v1.01a(GMT 1100 8-5-2015):                                                |
  11. #    1. Lets users use state triggers with timings set by them                 |
  12. #    v1.00g(GMT 1600 4-5-2015):                                                |
  13. #    1. Improved this script's efficiency                                      |
  14. #    v1.00f(GMT 0300 25-4-2015):                                               |
  15. #    1. Improved this script's effectiveness                                   |
  16. #    v1.00e(GMT 1400 21-4-2015):                                               |
  17. #    1. Further improved this script's robustness                              |
  18. #    v1.00d(GMT 1500 14-4-2015):                                               |
  19. #    1. Improved this script's robustness                                      |
  20. #    v1.00c(GMT 0200 12-4-2015):                                               |
  21. #    1. Fixed triggering remove actions upon adding state resists bug          |
  22. #    2. Fixed not triggering remove actions upon death, escape and recovery bug|
  23. #    v1.00b(GMT 1400 11-4-2015):                                               |
  24. #    1. Fixed not supporting multiple notetags on the same state bug           |
  25. #    v1.00a(GMT 1100 11-4-2015):                                               |
  26. #    1. 1st version of this script finished                                    |
Expand to see the code.


Download Link
http://pastebin.com/BBNR4MBR
Updates
  1. #    v1.02a(GMT 1300 26-2-2016):                                               |
  2. #    1. stcx and stax take the state calling them as an argument as well       |
Expand to see the code.
Updates
  1. #    v1.03a(GMT 1500 9-5-2016):                                                |
  2. #    1. adding the timing while to <timing state trigger: stcx, stax>          |
Expand to see the code.

Original thread: https://www.hbgames.org/forums/viewtopic.php?t=78861