Advertisement
Double_X

(Obsolete)DoubleX RMVXA State Triggers Compatibility v1.00a

May 30th, 2015
814
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.66 KB | None | 0 0
  1. #==============================================================================|
  2. # ** Script Info |
  3. #------------------------------------------------------------------------------|
  4. # * Script Name |
  5. # DoubleX RMVXA State Triggers Compatibility |
  6. #------------------------------------------------------------------------------|
  7. # * Functions |
  8. # Fixes compatibility issues in DoubleX RMVXA State Triggers |
  9. # Scripts Addressed: |
  10. # 1. DoubleX RMVXA Dynamic Data |
  11. # 2. Mr.Bubble's Tactics Ogre PSP Crafting System |
  12. # 3. Theolized Sideview Battle System |
  13. # 4. Tsukihime's Instance Items |
  14. #------------------------------------------------------------------------------|
  15. # * Terms Of Use |
  16. # You shall keep this script's Script Info part's contents intact |
  17. # You shalln't claim that this script is written by anyone other than |
  18. # DoubleX or his aliases |
  19. # None of the above applies to DoubleX or his aliases |
  20. #------------------------------------------------------------------------------|
  21. # * Prerequisites |
  22. # Scripts: |
  23. # 1. DoubleX RMVXA State Triggers |
  24. #------------------------------------------------------------------------------|
  25. # * Instructions |
  26. # 1. Open the script editor and put this script into an open slot between |
  27. # Materials and Main, save to take effect. |
  28. #------------------------------------------------------------------------------|
  29. # * Links |
  30. # Script Usage 101: |
  31. # 1. forums.rpgmakerweb.com/index.php?/topic/32752-rmvxa-script-usage-101/ |
  32. # 2. rpgmakervxace.net/topic/27475-rmvxa-script-usage-101/ |
  33. # This script: |
  34. # 1. http://pastebin.com/7YR3Z0bP |
  35. #------------------------------------------------------------------------------|
  36. # * Authors |
  37. # DoubleX |
  38. #------------------------------------------------------------------------------|
  39. # * Changelog |
  40. # v1.00a(GMT 0800 30-5-2015): |
  41. # 1. 1st version of this script finished |
  42. #==============================================================================|
  43.  
  44. ($doublex_rmvxa ||= {})[:State_Triggers_Compatibility] = "v1.00a"
  45.  
  46. #==============================================================================|
  47. # ** Script Implementations |
  48. # You need not edit this part as it's about how this script works |
  49. #------------------------------------------------------------------------------|
  50. # * Script Support Info: |
  51. # 1. Prerequisites |
  52. # - Decent understanding of how the addressed scripts work |
  53. # 2. Method documentation |
  54. # - The 1st part informs which version rewritten, aliased or created this|
  55. # method |
  56. # - The 2nd part informs whether the method's rewritten, aliased or new |
  57. # - The 3rd part describes what the method does for new methods only |
  58. # - The 4th part describes what the arguments of the method are |
  59. # - The 5th part describes how this method works for new methods only, |
  60. # and describes the parts added or rewritten for rewritten or aliased |
  61. # methods only |
  62. # Example: |
  63. # #----------------------------------------------------------------------------|
  64. # # (Version X+)Rewrite/Alias/New method: def_name |
  65. # # - What this method does |
  66. # #----------------------------------------------------------------------------|
  67. # # *args: What these arguments are |
  68. # def def_name(*args) |
  69. # # How this method works |
  70. # def_name_code |
  71. # # |
  72. # end # def_name |
  73. #------------------------------------------------------------------------------|
  74.  
  75. if $doublex_rmvxa[:State_Triggers]
  76.  
  77. if $doublex_rmvxa[:Dynamic_Data] || $imported["TH_InstanceItems"] ||
  78. $imported[:TSBS]
  79.  
  80. # Stores the object lambda clearance and reset methods
  81. CLEAR_RESET_STATE_TRIGGER_LAMBDAS = %Q(
  82. def clear_state_triggers_lambdas(obj)
  83. #{$imported["BubsTOCrafting"] ? %Q(
  84. if obj.ingredient_list
  85. obj.ingredient_list.each { |ingredient|
  86. clear_state_triggers_lambdas(ingredient) if ingredient.is_a?(RPG::State)
  87. }
  88. end
  89. ) : %Q()}
  90. obj.state_triggers = nil
  91. end
  92.  
  93. def reset_state_triggers_lambdas(obj)
  94. #{$imported["BubsTOCrafting"] ? %Q(
  95. if obj.ingredient_list
  96. obj.ingredient_list.each { |ingredient|
  97. reset_state_triggers_lambdas(ingredient) if ingredient.is_a?(RPG::State)
  98. }
  99. end
  100. ) : %Q()}
  101. obj.reset_notetags_state_triggers
  102. end
  103. )
  104.  
  105. end # if $doublex_rmvxa[:Dynamic_Data] || $imported["TH_InstanceItems"] ||
  106. # $imported[:TSBS]
  107.  
  108. if $imported["TH_InstanceItems"]
  109.  
  110. #------------------------------------------------------------------------------|
  111. # * Edit module: InstanceManager |
  112. #------------------------------------------------------------------------------|
  113.  
  114. class << InstanceManager
  115.  
  116. #----------------------------------------------------------------------------|
  117. # Alias method: make_full_copy |
  118. #----------------------------------------------------------------------------|
  119. alias make_full_copy_state_triggers make_full_copy
  120. def make_full_copy(obj)
  121. # Added to clear all lambdas right before using marshal
  122. state = obj.is_a?(RPG::State)
  123. clear_state_triggers_lambdas(obj) if state
  124. #
  125. clone = make_full_copy_state_triggers(obj)
  126. # Added to reset all lambdas right after using marshal
  127. reset_state_triggers_lambdas(clone) if state
  128. reset_state_triggers_lambdas(obj) if state
  129. #
  130. clone
  131. end # make_full_copy
  132.  
  133. #----------------------------------------------------------------------------|
  134. # New methods |
  135. # - Clears and resets all lambdas contained by the passed object |
  136. #----------------------------------------------------------------------------|
  137. module_eval(CLEAR_RESET_STATE_TRIGGER_LAMBDAS)
  138.  
  139. end # InstanceManager
  140.  
  141. end # if $imported["TH_InstanceItems"]
  142.  
  143. if $imported[:TSBS]
  144.  
  145. #------------------------------------------------------------------------------|
  146. # Alias method: copy |
  147. #------------------------------------------------------------------------------|
  148. alias copy_state_triggers copy
  149. def copy(obj)
  150. # Added to clear all lambdas right before using marshal
  151. state = obj.is_a?(RPG::State)
  152. clear_state_triggers_lambdas(obj) if state
  153. #
  154. clone = copy_state_triggers(obj)
  155. # Added to reset all lambdas right after using marshal
  156. reset_state_triggers_lambdas(clone) if state
  157. reset_state_triggers_lambdas(obj) if state
  158. #
  159. clone
  160. end # copy
  161.  
  162. #------------------------------------------------------------------------------|
  163. # New methods |
  164. # - Clears and resets all lambdas contained by the passed object |
  165. #------------------------------------------------------------------------------|
  166. eval(CLEAR_RESET_STATE_TRIGGER_LAMBDAS)
  167.  
  168. end # $imported[:TSBS]
  169.  
  170. if $doublex_rmvxa[:Dynamic_Data]
  171.  
  172. #------------------------------------------------------------------------------|
  173. # * Edit module: DataManager |
  174. #------------------------------------------------------------------------------|
  175.  
  176. class << DataManager
  177.  
  178. #----------------------------------------------------------------------------|
  179. # Alias method: save_game_without_rescue |
  180. #----------------------------------------------------------------------------|
  181. alias save_game_without_rescue_state_triggers save_game_without_rescue
  182. def save_game_without_rescue(index)
  183. # Added to clear all state triggers lambdas before saving
  184. $data_states.each { |obj| clear_state_triggers_lambdas(obj) if obj }
  185. #
  186. save_game_without_rescue_state_triggers(index)
  187. # Added to restore all state triggers lambdas after saving
  188. $data_states.each { |obj| reset_state_triggers_lambdas(obj) if obj }
  189. #
  190. end # save_game_without_rescue
  191.  
  192. #----------------------------------------------------------------------------|
  193. # Alias method: extract_save_contents |
  194. #----------------------------------------------------------------------------|
  195. alias extract_save_contents_state_triggers extract_save_contents
  196. def extract_save_contents(contents)
  197. extract_save_contents_state_triggers(contents)
  198. # Added to restore all state triggers lambdas after loading
  199. $data_states.each { |obj| reset_state_triggers_lambdas(obj) if obj }
  200. #
  201. end # extract_save_contents
  202.  
  203. #----------------------------------------------------------------------------|
  204. # New methods |
  205. # - Clears and resets all lambdas contained by the passed object |
  206. #----------------------------------------------------------------------------|
  207. module_eval(CLEAR_RESET_STATE_TRIGGER_LAMBDAS)
  208.  
  209. end # DataManager
  210.  
  211. #------------------------------------------------------------------------------|
  212. # * Edit class: RPG::State |
  213. #------------------------------------------------------------------------------|
  214.  
  215. class RPG::State < RPG::BaseItem
  216.  
  217. #----------------------------------------------------------------------------|
  218. # New public instance variable |
  219. #----------------------------------------------------------------------------|
  220. attr_accessor :state_triggers_string # Stores the notetag values as strings
  221.  
  222. #----------------------------------------------------------------------------|
  223. # Alias method: load_notetags_state_triggers |
  224. #----------------------------------------------------------------------------|
  225. alias load_notetags_state_triggers_compatibility load_notetags_state_triggers
  226. def load_notetags_state_triggers
  227. load_notetags_state_triggers_compatibility
  228. # Added to store all notetag values in the string form as well
  229. @state_triggers_string = {}
  230. st = "DoubleX_RMVXA::State_Triggers::"
  231. @note.split(/[\r\n]+/).each { |line|
  232. next unless line =~ /<(\w+) state trigger:\s*(\w+)\s*,\s*(\w+)\s*>/
  233. @state_triggers_string[$1.to_sym] ||= []
  234. @state_triggers_string[$1.to_sym].push(
  235. [eval("#{st}#{$2}"), eval("#{st}#{$3}")])
  236. }
  237. #
  238. end # load_notetags_state_triggers
  239.  
  240. #----------------------------------------------------------------------------|
  241. # New method: reset_notetags_state_triggers |
  242. # - Resets all lambdas used by the notetag values of the passed notetag |
  243. #----------------------------------------------------------------------------|
  244. def reset_notetags_state_triggers
  245. # Uses stored strings of notetag values to reset the lambdas
  246. @state_triggers_string.each { |timing, triggers|
  247. @state_triggers[timing] = triggers.collect { |trigger|
  248. eval("-> battler { battler.instance_exec { #{trigger} } }")
  249. }
  250. }
  251. #
  252. end # reset_notetags_state_triggers
  253.  
  254. end # RPG::State
  255.  
  256. end # if $doublex_rmvxa[:Dynamic_Data]
  257.  
  258. #------------------------------------------------------------------------------|
  259.  
  260. else
  261.  
  262. # Informs users that they didn't place State Triggers above this script
  263. msgbox("To use DoubleX RMVXA State Triggers Compatibility, " +
  264. "put it below:\n DoubleX RMVXA State Triggers\n but above Main")
  265.  
  266. end # if $doublex_rmvxa[:State_Triggers]
  267.  
  268. #==============================================================================|
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement