bgillisp

Low MP State

Aug 18th, 2014
603
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.33 KB | None | 0 0
  1. # Script Low MP State, version 1.00
  2. # Author: bgillisp
  3. # Released: 5/24/2015
  4.  
  5. # This script causes a state to be added if you either took enough
  6. # MP damage to drop your MP below a fixed percent, or if you used
  7. # a skill which dropped your MP below a fixed percent. The state
  8. # can be removed by normal means, and only will last for as long
  9. # as it is set in the database to last.
  10.  
  11. # Conflicts: None known of.
  12. #
  13. # Methods overwritten: None
  14. # Methods aliased:
  15. # use_item, from Class Scene_Battle
  16. # execute_damage, from Class Game_Battler
  17.  
  18. # Make sure this scripe is below any scripts which overwrtie all methods
  19. # that are aliased above, else it will not work.
  20.  
  21. # To use: Place in the materials section, above main.
  22. #
  23. # By default, the script is disabled. To enable it, either change the
  24. # the settings in the editbale region to add a global value which will
  25. # apply a global state, or use notetags to add it one by one to invidivual
  26. # actors and enemies.
  27.  
  28. # Notetags:
  29. #
  30. # <Low MP Value: x>
  31. # -Apply to an actor or an enemy to make a state apply when their MP
  32. # is below a certain percent of their maximum. x should be that
  33. # percent in decimal form. So if you want the state to apply when
  34. # someone's MP is below 50%, enter <Low MP Value: 0.50>
  35.  
  36. # <Low MP State: x>
  37. # -Apply to override the default state in the editable region. This will
  38. # take priority over the state below, and will be the state applied
  39. # when the MP drops below a certain percent.
  40.  
  41. # To Set it up so that the state applies when MP is zero, you need
  42. # to do both of the following: First, set the global value to 0.0. Then
  43. # add this notetag to anyone who is to be affected by having zero MP.
  44. # <Apply On Zero>
  45.  
  46. # Unfortunately, there is no way to have a different global minimum
  47. # and have apply on zero still work for select actors, due to the
  48. # way notetags are read by the system. If a solution can be found,
  49. # if will be posted in a patch.
  50.  
  51. #Terms of Use:
  52. # Free for use in commercial and non-commercial projects, with
  53. # credit given.
  54.  
  55. # Revisio History
  56. # 5.24.2015: Intial Release of version 1.0
  57.  
  58. #----------------------------------------------------------------------------
  59. # Editable region
  60.  
  61. module BG_lowmpstate
  62.  
  63. #Set the state you wish to be added when MP drops below a certain percent
  64. #threshold. By default it is set to state 8, which is Stun.
  65. Mp_zero_state = 8
  66.  
  67. #Set the global percent value for the state to kick in at.
  68. #Enter all numbers as a percent, in decimal form (0.10 = 10%, and so on)
  69. #Set at 0.0 to disable (barring states)
  70.  
  71. #Warning: Even if disabled, if you add the states below in the script,
  72. #it will become active. If you want to disable this totally except for
  73. #notetagged enemies and actors, follow the steps to disable the states
  74. #below as well!
  75. Mp_zero_value = 0.0
  76.  
  77. #Enter here any states that modify the threshold. To disable, just change it
  78. #to read [0], or some unused state in your game.
  79. MP_modify_threshold_states = [28, 29]
  80.  
  81. #Enter here the amount each state adds or subtracts from the threshold.
  82. #Must have one entry per state listed above, else the game *will* crash
  83. #Use 0.0 for the state to add nothing to the threshold.
  84. #Use negative numbers to decrease it, positive numbers to increase it.
  85. #You can make the threshold go above 1.0 and below 0.0 with this, so be
  86. #careful.
  87. MP_modify_threshold_add = [0.25, -0.25]
  88.  
  89. #Enter here the amount each state multiplies to the threshold.
  90. #Must have one entry per state listed above, else the game *will* crash
  91. #Use 1.0 if you wish for the threshold to be unchanged by the times step.
  92. #Use -1.0 to short term disbale the threshold while the state is in effect.
  93. MP_modify_threshold_multiply = [1.0, 1.0]
  94.  
  95. end
  96.  
  97. #End of Editable Region
  98. #--------------------------------------------------------------------------
  99.  
  100.  
  101. #Do not edit anything below here unless you know what you are doing.
  102. #Failure to ahead to this warning may result in unpredictable behavior in
  103. #your game. Consider yourself warned
  104. #__________________________________________________________________________
  105.  
  106.  
  107. module DataManager
  108.  
  109. #Alias method, load notetags
  110. class <<self; alias bg_lowmpstate_load_database load_database; end
  111. def self.load_database
  112. bg_lowmpstate_load_database
  113. bg_lowmpstate_load_notetags
  114. end
  115.  
  116. #New method, bg_lowmpstate_load_notetags
  117. def self.bg_lowmpstate_load_notetags
  118. groups = [$data_actors, $data_classes, $data_enemies]
  119. for group in groups
  120. for obj in group
  121. next if obj.nil?
  122. obj.bg_lowmpstate_load_notetags
  123. end
  124. end
  125. end
  126.  
  127. end # End module DataManager
  128.  
  129.  
  130.  
  131. class RPG::BaseItem
  132.  
  133.  
  134. attr_accessor :low_mp_state
  135. attr_accessor :low_mp_value
  136. attr_accessor :apply_on_zero
  137.  
  138. #New method, bg_lowmpstate_load_notetags
  139. def bg_lowmpstate_load_notetags
  140.  
  141. #Set the defaults. These will be used if no notetag is found
  142. self.low_mp_state = BG_lowmpstate::Mp_zero_state
  143. self.low_mp_value = BG_lowmpstate::Mp_zero_value
  144. self.apply_on_zero = false
  145.  
  146. @store = self.note[/(?<=<Low MP Value: ).*?(?=[>])/].to_f
  147. if(@store && @store != 0)
  148. @low_mp_value = @store
  149. end
  150.  
  151. @store2 = self.note[/(?<=<Low MP State: ).*?(?=[>])/].to_f
  152. if(@store2 && @store2 != 0)
  153. @low_mp_state = @store2
  154. @low_mp_state = @low_mp_state.to_i
  155. end
  156.  
  157. if(self.note[/<Apply On Zero>/im])
  158. @apply_on_zero = true
  159. end
  160.  
  161. end
  162.  
  163. end # RPG::BaseItem
  164.  
  165.  
  166. #Class Scene_Battle
  167. class Scene_Battle < Scene_Base
  168.  
  169. alias bg_lowmpstate_use_item use_item
  170.  
  171. #Aliased method, use item
  172. def use_item
  173.  
  174. #Store the previous mp before using the item
  175. oldmp = @subject.mp
  176.  
  177. #Call aliased method
  178. bg_lowmpstate_use_item
  179.  
  180. #Calculate the threshold value for an actor
  181. if(@subject.actor?)
  182. mpthreshold = (@subject.mmp * @subject.actor.low_mp_value).to_i
  183. end
  184.  
  185. #Calculcate the threshold value for an enemy
  186. if(@subject.enemy?)
  187. mpthreshold = (@subject.mmp * @subject.enemy.low_mp_value).to_i
  188. end
  189.  
  190. #If you have battlers that are neither actor or enemy, add their code
  191. #at this point of the script.
  192.  
  193. ctr = 0 #Counter for upcoming for loop
  194.  
  195. #Parse the arrays, see if we need to modify the threshold based on states
  196. #applied to the subject using the item.
  197. #Takes into account states that were just added by using the item.
  198. for state_parse in BG_lowmpstate::MP_modify_threshold_states
  199. if(@subject.state?(state_parse))
  200. mpthreshold += (@subject.mmp * BG_lowmpstate::MP_modify_threshold_add[ctr]).to_i
  201. mpthreshold *= BG_lowmpstate::MP_modify_threshold_multiply[ctr]
  202. mpthreshold = mpthreshold.to_i
  203. end #End if loop
  204.  
  205. ctr += 1 #Increment the counter
  206. end #End for loop
  207.  
  208. #Check to see if we have fallen below the MP threahold.
  209. #Check if it is an actor first
  210. if(@subject.actor?)
  211. if(@subject.mp != 0 && oldmp != @subject.mp && oldmp > mpthreshold && @subject.mp <= mpthreshold)
  212. @subject.add_state(@subject.actor.low_mp_state)
  213. end
  214.  
  215. #Check for the apply on zero condition
  216. if(@subject.actor.apply_on_zero == true && @subject.mp != oldmp && @subject.mp == 0 && mpthreshold == 0)
  217. @subject.add_state(@subject.actor.low_mp_state)
  218. end
  219.  
  220. end
  221.  
  222. #Check to see if it is an enemy and it has fallen below the threshold
  223. if(@subject.enemy?)
  224. if(@subject.mp != 0 && oldmp != @subject.mp && oldmp > mpthreshold && @subject.mp <= mpthreshold)
  225. @subject.add_state(@subject.enemy.low_mp_state)
  226. end
  227.  
  228. #Check for the apply on zero condition
  229. if(@subject.enemy.apply_on_zero == true && @subject.mp != oldmp && @subject.mp == 0 && mpthreshold == 0)
  230. @subject.add_state(@subject.enemy.low_mp_state)
  231. end
  232.  
  233. end
  234.  
  235. end #End def use_item
  236.  
  237. end #End Scene_Battle class
  238.  
  239.  
  240. #Class Game_Battler
  241. class Game_Battler < Game_BattlerBase
  242.  
  243. alias bg_lowmpstate_execute_damage execute_damage
  244.  
  245. #alias method, Execute Damage
  246. def execute_damage(user)
  247.  
  248. #Store the old mp before damage is applied
  249. oldmp = self.mp
  250.  
  251. #Store the threshold value for an actor
  252. if(actor?)
  253. mpthreshold = (self.mmp * self.actor.low_mp_value).to_i
  254. end
  255.  
  256. #Store the threshld value for an enemy
  257. if(enemy?)
  258. mpthreshold = (self.mmp * self.enemy.low_mp_value).to_i
  259. end
  260.  
  261. #If you have battlers that are neither actors or enemies, enter their
  262. #code here.
  263.  
  264. #Parse the states, to see if we need to adjust the threshold now
  265. ctr = 0 #Counter for the for loop
  266. for state_parse in BG_lowmpstate::MP_modify_threshold_states
  267. if(self.state?(state_parse))
  268. mpthreshold += (self.mmp * BG_lowmpstate::MP_modify_threshold_add[ctr]).to_i
  269. mpthreshold *= BG_lowmpstate::MP_modify_threshold_multiply[ctr]
  270. mpthreshold = mpthreshold.to_i
  271. end
  272.  
  273. ctr += 1 #increment the counter
  274. end #End the for loop
  275.  
  276. #Call aliased method
  277. bg_lowmpstate_execute_damage(user)
  278.  
  279. #Add the state if the damage took us below the threshhold
  280. if(actor?)
  281. if(self.mp != 0 && self.mp != oldmp && self.mp <= mpthreshold && oldmp > mpthreshold)
  282. add_state(actor.low_mp_state)
  283. end
  284.  
  285. #Check to see if we are to apply the state on zero now
  286. if(actor.apply_on_zero == true && self.mp != oldmp && self.mp == 0 && mpthreshold == 0)
  287. add_state(actor.low_mp_state)
  288. end
  289.  
  290. end
  291.  
  292. if(enemy?)
  293. if(self.mp != 0 && self.mp != oldmp && self.mp <= mpthreshold && oldmp > mpthreshold)
  294. add_state(enemy.low_mp_state)
  295. end
  296.  
  297. #Check to see if we are to apply the state on zero now
  298. if(enemy.apply_on_zero == true && self.mp != oldmp && self.mp == 0 && mpthreshold == 0)
  299. add_state(enemy.low_mp_state)
  300. end
  301. end
  302.  
  303. end
  304.  
  305. end #End Game_Battler Class
Advertisement
Add Comment
Please, Sign In to add comment