Advertisement
Double_X

DoubleX RMVXA Item Triggers v1.01a

May 11th, 2015 (edited)
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 13.46 KB | None | 0 0
  1. #==============================================================================|
  2. #  ** Script Info                                                              |
  3. #------------------------------------------------------------------------------|
  4. #  * Script Name                                                               |
  5. #    DoubleX RMVXA Item Triggers                                               |
  6. #------------------------------------------------------------------------------|
  7. #  * Functions                                                                 |
  8. #    Sets some skills/items to trigger effects before and/or after being used  |
  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. https://pastebin.com/FUeT6D0u                                          |
  30. #    Mentioned Patreon Supporters:                                             |
  31. #    https://www.patreon.com/posts/71738797                                    |
  32. #------------------------------------------------------------------------------|
  33. #  * Authors                                                                   |
  34. #    DoubleX                                                                   |
  35. #------------------------------------------------------------------------------|
  36. #  * Changelog                                                                 |
  37. #    v1.01a(GMT 1300 26-2-2016):                                               |
  38. #    1. itcx and itax take the skill/item calling them as an argument as well  |
  39. #    2. Fixed passing Scene_battle instead of a battler into itcx/itax bug     |
  40. #    v1.00b(GMT 0400 7-11-2015):                                               |
  41. #    1. Notetag values are now symbols of methods in the configuration regions |
  42. #    2. This script doesn't need DoubleX RMVXA Item Triggers Compatibility to  |
  43. #       be compatible with all its addressed scripts                           |
  44. #    3. Further improved this script's compatibility, efficiency and simplicity|
  45. #    v1.00a(GMT 1300 11-5-2015):                                               |
  46. #    1. 1st version of this script finished                                    |
  47. #==============================================================================|
  48.  
  49. #==============================================================================|
  50. #  ** Notetag Info                                                             |
  51. #------------------------------------------------------------------------------|
  52. #  * Skill/Item Notetags:                                                      |
  53. #    1. <timing item trigger: itcx, itax>                                      |
  54. #       - Sets a skill/item to trigger itax when timing and itcx are met       |
  55. #       - It only works in battles using the default battle scene(Scene_Battle)|
  56. #       - timing can be pre, post or custom timings set by you                 |
  57. #       - pre means right before using the skill/item                          |
  58. #       - post means right after using the skill/item                          |
  59. #       - timing must only consist of alphanumeric characters                  |
  60. #       - itcx can be set in Item Trigger Condition Notetag Values             |
  61. #       - itax can be set in Item Trigger Action Notetag Values                |
  62. #==============================================================================|
  63.  
  64. #==============================================================================|
  65. #  ** Script Call Info                                                         |
  66. #------------------------------------------------------------------------------|
  67. #  * Scene manipulations                                                       |
  68. #    1. exec_item_triggers(item, timing)                                       |
  69. #       - Executes all item triggers with timing timing of item item           |
  70. #==============================================================================|
  71.  
  72. ($doublex_rmvxa ||= {})[:Item_Triggers] = "v1.01a"
  73.  
  74. #==============================================================================|
  75. #  ** Script Configurations                                                    |
  76. #     You only need to edit this part as it's about what this script does      |
  77. #------------------------------------------------------------------------------|
  78.  
  79. module DoubleX_RMVXA
  80.  
  81.   module Item_Triggers
  82.  
  83.     #--------------------------------------------------------------------------|
  84.     #  Item Trigger Condition Notetag Values                                   |
  85.     #  - Setups itcx used by <timing item trigger: itcx, itax>                 |
  86.     #--------------------------------------------------------------------------|
  87.     # itcx are used at:
  88.     # 1. Scene_Battle
  89.     #    - it.send(trigger[1], self) if it.send(trigger[0], self) in
  90.     #      exec_item_triggers
  91.     # itcx are strings of names of methods under DoubleX_RMVXA::Item_Triggers
  92.     # itcx names can only use alphanumeric characters
  93.     # battler is the battler using item
  94.     # item is the skill/item using the itcx
  95.     # The below itcx are examples added to help you set your itcx
  96.     # You can freely use, rewrite and/or delete these examples
  97.  
  98.     # Sets the item trigger condition as always true
  99.     def self.itc1(battler, item)
  100.       true
  101.     end
  102.  
  103.     # Sets the item trigger condition as always false
  104.     def self.itc2(battler, item)
  105.       false
  106.     end
  107.  
  108.     # Sets the item trigger condition as needing switch with id x to be on
  109.     def self.itc3(battler, item)
  110.       $game_switches[x]
  111.     end
  112.  
  113.     # Adds new itcx here
  114.    
  115.  
  116.     #--------------------------------------------------------------------------|
  117.     #  Item Trigger Action Notetag Values                                      |
  118.     #  - Setups itax used by <timing item trigger: itcx, itax>                 |
  119.     #--------------------------------------------------------------------------|
  120.     # itax are used at:
  121.     # 1. Scene_Battle
  122.     #    - it.send(trigger[1], self) if it.send(trigger[0], self) in
  123.     #      exec_item_triggers
  124.     # itax are strings of names of methods under DoubleX_RMVXA::Item_Triggers
  125.     # itax names can only use alphanumeric characters
  126.     # battler is the battler using item
  127.     # item is the skill/item using the itax
  128.     # The below itax are examples added to help you set your itax
  129.     # You can freely use, rewrite and/or delete these examples
  130.  
  131.     # Sets the item trigger action as what Special Effect Escape does
  132.     def self.ita1(battler, item)
  133.       battler.hide
  134.     end
  135.  
  136.     # Sets the item trigger action as calling common event with id
  137.     # common_event_id
  138.     def self.ita2(battler, item)
  139.       $game_temp.reserve_common_event(common_event_id)
  140.       SceneManager.scene.process_event
  141.     end
  142.  
  143.     # Sets the item trigger action as executing damage equal to the value of
  144.     # game variable with id x to self with type equal to that of skill with id
  145.     # equal to y
  146.     def self.ita3(battler, item)
  147.       battler.result.clear
  148.       battler.result.make_damage($game_variables[x], $data_skills[y])
  149.       battler.execute_damage(battler)
  150.     end
  151.  
  152.     # Adds new itax here
  153.    
  154.  
  155.   end # Item_Triggers
  156.  
  157. end # DoubleX_RMVXA
  158.  
  159. #==============================================================================|
  160. #  ** Script Implementations                                                   |
  161. #     You need not edit this part as it's about how this script works          |
  162. #------------------------------------------------------------------------------|
  163. #  * Script Support Info:                                                      |
  164. #    1. Prerequisites                                                          |
  165. #       - Some RGSS3 scripting proficiency to fully comprehend this script     |
  166. #    2. Method documentation                                                   |
  167. #       - The 1st part describes why this method's rewritten/aliased for       |
  168. #         rewritten/aliased methods or what the method does for new methods    |
  169. #       - The 2nd part describes what the arguments of the method are          |
  170. #       - The 3rd part informs which version rewritten, aliased or created this|
  171. #         method                                                               |
  172. #       - The 4th part informs whether the method's rewritten or new           |
  173. #       - The 5th part informs whether the method's a real or potential hotspot|
  174. #       - The 6th part describes how this method works for new methods only,   |
  175. #         and describes the parts added, removed or rewritten for rewritten or |
  176. #         aliased methods only                                                 |
  177. #       Example:                                                               |
  178. # #--------------------------------------------------------------------------| |
  179. # #  Why rewrite/alias/What this method does                                 | |
  180. # #--------------------------------------------------------------------------| |
  181. # # *argv: What these variables are                                            |
  182. # # &argb: What this block is                                                  |
  183. # def def_name(*argv, &argb) # Version X+; Rewrite/New; Hotspot                |
  184. #   # Added/Removed/Rewritten to do something/How this method works            |
  185. #   def_name_code                                                              |
  186. #   #                                                                          |
  187. # end # def_name                                                               |
  188. #------------------------------------------------------------------------------|
  189.  
  190. class << DataManager # Edit
  191.  
  192.   alias load_database_item_triggers load_database
  193.   def load_database
  194.     load_database_item_triggers
  195.     # Added
  196.     $data_skills.each { |obj| obj.load_item_triggers_notes if obj }
  197.     $data_items.each { |obj| obj.load_item_triggers_notes if obj }
  198.     #
  199.   end # load_database
  200.  
  201. end # DataManager
  202.  
  203. class RPG::UsableItem < RPG::BaseItem # Edit
  204.  
  205.   #----------------------------------------------------------------------------|
  206.   #  New public instance variable                                              |
  207.   #----------------------------------------------------------------------------|
  208.   attr_accessor :item_triggers # The storage of all item trigger notetags
  209.  
  210.   def load_item_triggers_notes
  211.     # Stores all timing, itcx and itax triples from matching lines sequentially
  212.     @item_triggers = {}
  213.     @note.split(/[\r\n]+/).each { |line|
  214.       next unless line =~ /< *(\w+) +item +trigger *: *(\w+) *, *(\w+) *>/i
  215.       (@item_triggers[$1.downcase.to_sym] ||= []).push(
  216.       [$2.downcase.to_sym, $3.downcase.to_sym])
  217.     }
  218.     #
  219.   end # load_item_triggers_notes
  220.  
  221. end # RPG::UsableItem
  222.  
  223. class Scene_Battle < Scene_Base # Edit
  224.  
  225.   alias use_item_triggers use_item
  226.   def use_item
  227.     # Added to execute the item triggers with timing pre
  228.     item = @subject.current_action.item
  229.     exec_item_triggers(item, :pre)
  230.     #
  231.     use_item_triggers
  232.     # Added to execute the item triggers with timing post
  233.     exec_item_triggers(item, :post)
  234.     #
  235.   end # use_item
  236.  
  237.   #----------------------------------------------------------------------------|
  238.   #  Triggers each item action when each respective condition's met            |
  239.   #----------------------------------------------------------------------------|
  240.   # item: The item triggering its actions
  241.   # timing: The timing of the item triggering its actions
  242.   def exec_item_triggers(item, timing)
  243.     # Evaluates each itcx to see if its corresponding itax should be evaluated
  244.     return unless triggers = item.item_triggers[timing]
  245.     it = DoubleX_RMVXA::Item_Triggers
  246.     triggers.each { |trigger|
  247.       it.send(trigger[1], @subject, item) if it.send(trigger[0], @subject, item)
  248.     }
  249.     #
  250.   end # exec_item_triggers
  251.  
  252. end # Scene_Battle
  253.  
  254. #------------------------------------------------------------------------------|
  255.  
  256. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement