Advertisement
Double_X

DoubleX RMVXA State Triggers v1.03b

May 11th, 2015 (edited)
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 19.36 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA State Triggers                                              |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Sets some states to trigger additional effects when conditions are met    |
  9. #------------------------------------------------------------------------------|
  10. #  * Terms Of Use                                                              |
  11. #    You shall keep this script's Script Info part's contents intact           |
  12. #    You shalln't claim that this script is written by anyone other than       |
  13. #    DoubleX or his aliases                                                    |
  14. #    None of the above applies to DoubleX or his aliases                       |
  15. #------------------------------------------------------------------------------|
  16. #  * Prerequisites                                                             |
  17. #    Abilities:                                                                |
  18. #    1. Decent RGSS3 scripting proficiency to fully utilize this script        |
  19. #------------------------------------------------------------------------------|
  20. #  * Instructions                                                              |
  21. #    1. Open the script editor and put this script into an open slot between   |
  22. #       Materials and Main, save to take effect.                               |
  23. #------------------------------------------------------------------------------|
  24. #  * Links                                                                     |
  25. #    Script Usage 101:                                                         |
  26. #    1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/  |
  27. #    2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/                  |
  28. #    This script:                                                              |
  29. #    1. http://www.rpgmakervxace.net/topic/31374-doublex-rmvxa-state-triggers/ |
  30. #    Mentioned Patreon Supporters:                                             |
  31. #    https://www.patreon.com/posts/71738797                                    |
  32. #------------------------------------------------------------------------------|
  33. #  * Authors                                                                   |
  34. #    DoubleX                                                                   |
  35. #------------------------------------------------------------------------------|
  36. #  * Changelog                                                                 |
  37. #    v1.03b(GMT 1400 10-5-2016):                                               |
  38. #    1. timing while won't replace but will combine the state's existing       |
  39. #       features with all stax meeting the corresponding stcx                  |
  40. #    v1.03a(GMT 1500 9-5-2016):                                                |
  41. #    1. adding the timing while to <timing state trigger: stcx, stax>          |
  42. #    v1.02a(GMT 1300 26-2-2016):                                               |
  43. #    1. stcx and stax take the state calling them as an argument as well       |
  44. #    v1.01b(GMT 0300 7-11-2015):                                               |
  45. #    1. Notetag values are now symbols of methods in the configuration regions |
  46. #    2. This script doesn't need DoubleX RMVXA State Triggers Compatibility to |
  47. #       be compatible with all its addressed scripts                           |
  48. #    3. Further improved this script's compatibility, efficiency and simplicity|
  49. #    v1.01a(GMT 1100 8-5-2015):                                                |
  50. #    1. Lets users use state triggers with timings set by them                 |
  51. #    v1.00g(GMT 1600 4-5-2015):                                                |
  52. #    1. Improved this script's efficiency                                      |
  53. #    v1.00f(GMT 0300 25-4-2015):                                               |
  54. #    1. Improved this script's effectiveness                                   |
  55. #    v1.00e(GMT 1400 21-4-2015):                                               |
  56. #    1. Further improved this script's robustness                              |
  57. #    v1.00d(GMT 1500 14-4-2015):                                               |
  58. #    1. Improved this script's robustness                                      |
  59. #    v1.00c(GMT 0200 12-4-2015):                                               |
  60. #    1. Fixed triggering remove actions upon adding state resists bug          |
  61. #    2. Fixed not triggering remove actions upon death, escape and recovery bug|
  62. #    v1.00b(GMT 1400 11-4-2015):                                               |
  63. #    1. Fixed not supporting multiple notetags on the same state bug           |
  64. #    v1.00a(GMT 1100 11-4-2015):                                               |
  65. #    1. 1st version of this script finished                                    |
  66. #==============================================================================|
  67.  
  68. #==============================================================================|
  69. #  ** Notetag Info                                                             |
  70. #------------------------------------------------------------------------------|
  71. #  * State Notetags:                                                           |
  72. #    1. <timing state trigger: stcx, stax>                                     |
  73. #       - Sets a state to trigger stax when timing and stcx are met            |
  74. #       - timing can be add, turn, remove or custom timings set by you         |
  75. #       - add means the state's just added                                     |
  76. #       - turn means the state's remaining turn's just reduced by 1            |
  77. #       - remove means the state's just removed                                |
  78. #       - while means the stax effects are active as long as the state's active|
  79. #       - timing must only consist of alphanumeric characters                  |
  80. #       - stcx can be set in State Trigger Condition Notetag Values            |
  81. #       - stax can be set in State Trigger Action Notetag Values               |
  82. #==============================================================================|
  83.  
  84. #==============================================================================|
  85. #  ** Script Call Info                                                         |
  86. #------------------------------------------------------------------------------|
  87. #  * Battler manipulations                                                     |
  88. #    1. exec_state_triggers(state_id, timing)                                  |
  89. #       - Executes all state triggers with timing timing of state with id      |
  90. #         state_id                                                             |
  91. #    2. state_trigger_features(state, timing)                                  |
  92. #       - Returns an array of features returned by all stax meeting stcx with  |
  93. #         timing timing of state                                               |
  94. #       - This script call's not supposed to work with timing add, turn nor    |
  95. #         remove but supposed to work with timing while                        |
  96. #==============================================================================|
  97.  
  98. ($doublex_rmvxa ||= {})[:State_Triggers] = "v1.03b"
  99.  
  100. #==============================================================================|
  101. #  ** Script Configurations                                                    |
  102. #     You only need to edit this part as it's about what this script does      |
  103. #------------------------------------------------------------------------------|
  104.  
  105. module DoubleX_RMVXA
  106.  
  107.   module State_Triggers
  108.  
  109.     #--------------------------------------------------------------------------|
  110.     #  State Trigger Condition Notetag Values                                  |
  111.     #  - Setups stcx used by this script's notetags                            |
  112.     #--------------------------------------------------------------------------|
  113.     # stcx are read at:
  114.     # 1. RPG::State
  115.     #    - (@state_triggers[$1.downcase.to_sym] ||= []).push(
  116.     #      [$2.downcase, $3.downcase]) in load_state_triggers_notes
  117.     # stcx are used at:
  118.     # 1. Game_BattlerBase
  119.     #    - st.send(trigger[0], self, state) in state_trigger_features
  120.     # 2. Game_Battler
  121.     #    - st.send(trigger[1], self) if st.send(trigger[0], self) in
  122.     #      exec_state_triggers
  123.     # stcx are strings names of methods under DoubleX_RMVXA::State_Triggers
  124.     # stcx names can only use alphanumeric characters and can't use uppercase
  125.     # letters
  126.     # battler is the battler calling the stcx
  127.     # state is the state using the stcx
  128.     # The below stcx are examples added to help you set your stcx
  129.     # You can freely use, rewrite and/or delete these examples
  130.  
  131.     # Sets the state trigger condition as always true
  132.     def self.stc1(battler, state)
  133.       true
  134.     end
  135.  
  136.     # Sets the state trigger condition as always false
  137.     def self.stc2(battler, state)
  138.       false
  139.     end
  140.  
  141.     # Sets the state trigger condition as needing switch with id x to be on
  142.     def self.stc3(battler, state)
  143.       $game_switches[x]
  144.     end
  145.  
  146.     # Sets the state trigger condition as needing the state using this stcx to
  147.     # have its number of remaining turns greater than x
  148.     def self.stc4(battler, state)
  149.       battler.instance_exec { @state_turns[state_id] > x }
  150.     end
  151.  
  152.     # Adds new stcx here
  153.    
  154.  
  155.     #--------------------------------------------------------------------------|
  156.     #  State Trigger Action Notetag Values                                     |
  157.     #  - Setups stax used by this script's notetags                            |
  158.     #--------------------------------------------------------------------------|
  159.     # stax are read at:
  160.     # 1. RPG::State
  161.     #    - (@state_triggers[$1.downcase.to_sym] ||= []).push(
  162.     #      [$2.downcase, $3.downcase]) in load_state_triggers_notes
  163.     # stax are used at:
  164.     # 1. Game_BattlerBase
  165.     #    - }.collect! { |trigger| st.send(trigger[1], self, state) }.flatten! in
  166.     #      state_trigger_features
  167.     # 2. Game_Battler
  168.     #    - st.send(trigger[1], self) if st.send(trigger[0], self) in
  169.     #      exec_state_triggers
  170.     # stax are strings of names of methods under DoubleX_RMVXA::State_Triggers
  171.     # stax names can only use alphanumeric characters and can't use uppercase
  172.     # letters
  173.     # battler is the battler calling the stax
  174.     # state is the state using the stax
  175.     # If the timing using the stax is while, the stax must return an array of
  176.     # RPG::BaseItem::Feature
  177.     # You can refer to Game_BattlerBase and RPG::BaseItem::Feature for more info
  178.     # The below stax are examples added to help you set your stax
  179.     # You can freely use, rewrite and/or delete these examples
  180.  
  181.     # Sets the state trigger action as what Special Effect Escape does
  182.     # This stax's not supposed to work with the timing while as it doesn't
  183.     # return an array of RPG::BaseItem::Feature
  184.     def self.sta1(battler, state)
  185.       battler.hide
  186.     end
  187.  
  188.     # Sets the state trigger action as calling common event with id
  189.     # common_event_id
  190.     # This stax's not supposed to work with the timing while as it doesn't
  191.     # return an array of RPG::BaseItem::Feature
  192.     def self.sta2(battler, state)
  193.       $game_temp.reserve_common_event(common_event_id)
  194.     end
  195.  
  196.     # Sets the state trigger action as executing damage equal to the value of
  197.     # game variable with id x to self with type equal to that of skill with id
  198.     # equal to y
  199.     # This stax's not supposed to work with the timing while as it doesn't
  200.     # return an array of RPG::BaseItem::Feature
  201.     def self.sta3(battler, state)
  202.       battler.result.clear
  203.       battler.result.make_damage($game_variables[x], $data_skills[y])
  204.       battler.execute_damage(battler)
  205.     end
  206.  
  207.     # Sets the state trigger action as multiplying the battler's atk by x * 100%
  208.     # This stax's supposed to work with the timing while as it returns an array
  209.     # of RPG::BaseItem::Feature
  210.     def self.sta4(battler, state)
  211.       [RPG::BaseItem::Feature.new(21, 2, x)]
  212.     end
  213.  
  214.     # Adds new stax here
  215.    
  216.  
  217.   end # State_Triggers
  218.  
  219. end # DoubleX_RMVXA
  220.  
  221. #==============================================================================|
  222. #  ** Script Implementations                                                   |
  223. #     You need not edit this part as it's about how this script works          |
  224. #------------------------------------------------------------------------------|
  225. #  * Script Support Info:                                                      |
  226. #    1. Prerequisites                                                          |
  227. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  228. #    2. Method documentation                                                   |
  229. #       - The 1st part describes why this method's rewritten/aliased for       |
  230. #         rewritten/aliased methods or what the method does for new methods    |
  231. #       - The 2nd part describes what the arguments of the method are          |
  232. #       - The 3rd part informs which version rewritten, aliased or created this|
  233. #         method                                                               |
  234. #       - The 4th part informs whether the method's rewritten or new           |
  235. #       - The 5th part informs whether the method's a real or potential hotspot|
  236. #       - The 6th part describes how this method works for new methods only,   |
  237. #         and describes the parts added, removed or rewritten for rewritten or |
  238. #         aliased methods only                                                 |
  239. #       Example:                                                               |
  240. # #--------------------------------------------------------------------------| |
  241. # #  Why rewrite/alias/What this method does                                 | |
  242. # #--------------------------------------------------------------------------| |
  243. # # *argv: What these variables are                                            |
  244. # # &argb: What this block is                                                  |
  245. # def def_name(*argv, &argb) # Version X+; Rewrite/New; Hotspot                |
  246. #   # Added/Removed/Rewritten to do something/How this method works            |
  247. #   def_name_code                                                              |
  248. #   #                                                                          |
  249. # end # def_name                                                               |
  250. #------------------------------------------------------------------------------|
  251.  
  252. class << DataManager # Edit
  253.  
  254.   alias load_database_state_triggers load_database
  255.   def load_database(*argv, &argb)
  256.     load_database_state_triggers(*argv, &argb)
  257.     $data_states.each { |obj| obj.load_state_triggers_notes if obj } # Added
  258.   end # load_database
  259.  
  260. end # DataManager
  261.  
  262. class RPG::State < RPG::BaseItem # Edit
  263.  
  264.   #----------------------------------------------------------------------------|
  265.   #  New public instance variable                                              |
  266.   #----------------------------------------------------------------------------|
  267.   attr_accessor :state_triggers # The storage of all state trigger notetags
  268.  
  269.   def load_state_triggers_notes
  270.     # Stores all timing, stcx and stax triples from matching lines sequentially
  271.     @state_triggers = {}
  272.     @note.split(/[\r\n]+/).each { |line|
  273.       next unless line =~ /< *(\w+) +state +trigger *: *(\w+) *, *(\w+) *>/i
  274.       (@state_triggers[$1.downcase.to_sym] ||= []).push(
  275.       [$2.downcase.to_sym, $3.downcase.to_sym])
  276.     }
  277.     #
  278.   end # load_state_triggers_notes
  279.  
  280. end # RPG::State
  281.  
  282. class Game_BattlerBase # Edit
  283.  
  284.   alias all_features_state_triggers all_features
  285.   def all_features(*argv, &argb) # v1.03a+
  286.     # Rewritten to use features returned by stax for states meeting any stcx
  287.     states.inject([]) {|r, obj|
  288.       r + state_trigger_features(obj, :while)
  289.     } + all_features_state_triggers(*argv, &argb)
  290.     #
  291.   end # all_features
  292.  
  293.   alias erase_state_triggers erase_state
  294.   def erase_state(state_id, &argb)
  295.     # Added to store the state existence flag right before it's erased
  296.     trigger = @states.include?(state_id)
  297.     #
  298.     erase_state_triggers(state_id, &argb)
  299.     # Added to trigger the remove actions when the remove conditions are met
  300.     exec_state_triggers(state_id, :remove) if trigger
  301.     #
  302.   end # erase_state
  303.  
  304.   # state: The state having its features returned by stax collected
  305.   # timing: The timing of the state collecting features returned by stax
  306.   def state_trigger_features(state, timing) # v1.03a+
  307.     return [] unless triggers = state.state_triggers[timing]
  308.     st = DoubleX_RMVXA::State_Triggers
  309.     # Collects all features returned by stax meeting stcx with timing timing
  310.     triggers.select { |trigger|
  311.       st.send(trigger[0], self, state)
  312.     }.collect! { |trigger| st.send(trigger[1], self, state) }.flatten!
  313.     #
  314.   end # state_trigger_features
  315.  
  316. end # Game_BattlerBase
  317.  
  318. class Game_Battler < Game_BattlerBase # Edit
  319.  
  320.   alias clear_states_triggers clear_states
  321.   def clear_states(*argv, &argb)
  322.     # Added to store the state array right before it's cleared
  323.     last_states = @states
  324.     #
  325.     clear_states_triggers(*argv, &argb)
  326.     # Added to trigger the remove actions when the remove conditions are met
  327.     return unless last_states
  328.     last_states.each { |state_id| exec_state_triggers(state_id, :remove) }
  329.     #
  330.   end # clear_states
  331.  
  332.   alias reset_state_counts_state_triggers reset_state_counts
  333.   def reset_state_counts(state_id, &argb)
  334.     reset_state_counts_state_triggers(state_id, &argb)
  335.     # Added to trigger the add actions when the add conditions are met
  336.     exec_state_triggers(state_id, :add) if @states.include?(state_id)
  337.     #
  338.   end # reset_state_counts
  339.  
  340.   alias update_state_turns_state_triggers update_state_turns
  341.   def update_state_turns(*argv, &argb)
  342.     update_state_turns_state_triggers(*argv, &argb)
  343.     # Added to trigger the turn actions when the turn conditions are met
  344.     @states.each { |state_id| exec_state_triggers(state_id, :turn) }
  345.     #
  346.   end # update_state_turns
  347.  
  348.   #----------------------------------------------------------------------------|
  349.   #  Triggers each state action when each respective condition's met           |
  350.   #----------------------------------------------------------------------------|
  351.   # state_id: The id of the state triggering its actions
  352.   # timing: The timing of the state triggering its actions
  353.   def exec_state_triggers(state_id, timing) # New
  354.     # Evaluates each stcx to see if its corresponding stax should be evaluated
  355.     state = $data_states[state_id]
  356.     return unless triggers = state.state_triggers[timing]
  357.     st = DoubleX_RMVXA::State_Triggers
  358.     triggers.each { |trigger|
  359.       st.send(trigger[1], self, state) if st.send(trigger[0], self, state)
  360.     }
  361.     #
  362.   end # exec_state_triggers
  363.  
  364. end # Game_Battler
  365.  
  366. #------------------------------------------------------------------------------|
  367.  
  368. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement