Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Script Low MP State, version 1.00
- # Author: bgillisp
- # Released: 5/24/2015
- # This script causes a state to be added if you either took enough
- # MP damage to drop your MP below a fixed percent, or if you used
- # a skill which dropped your MP below a fixed percent. The state
- # can be removed by normal means, and only will last for as long
- # as it is set in the database to last.
- # Conflicts: None known of.
- #
- # Methods overwritten: None
- # Methods aliased:
- # use_item, from Class Scene_Battle
- # execute_damage, from Class Game_Battler
- # Make sure this scripe is below any scripts which overwrtie all methods
- # that are aliased above, else it will not work.
- # To use: Place in the materials section, above main.
- #
- # By default, the script is disabled. To enable it, either change the
- # the settings in the editbale region to add a global value which will
- # apply a global state, or use notetags to add it one by one to invidivual
- # actors and enemies.
- # Notetags:
- #
- # <Low MP Value: x>
- # -Apply to an actor or an enemy to make a state apply when their MP
- # is below a certain percent of their maximum. x should be that
- # percent in decimal form. So if you want the state to apply when
- # someone's MP is below 50%, enter <Low MP Value: 0.50>
- # <Low MP State: x>
- # -Apply to override the default state in the editable region. This will
- # take priority over the state below, and will be the state applied
- # when the MP drops below a certain percent.
- # To Set it up so that the state applies when MP is zero, you need
- # to do both of the following: First, set the global value to 0.0. Then
- # add this notetag to anyone who is to be affected by having zero MP.
- # <Apply On Zero>
- # Unfortunately, there is no way to have a different global minimum
- # and have apply on zero still work for select actors, due to the
- # way notetags are read by the system. If a solution can be found,
- # if will be posted in a patch.
- #Terms of Use:
- # Free for use in commercial and non-commercial projects, with
- # credit given.
- # Revisio History
- # 5.24.2015: Intial Release of version 1.0
- #----------------------------------------------------------------------------
- # Editable region
- module BG_lowmpstate
- #Set the state you wish to be added when MP drops below a certain percent
- #threshold. By default it is set to state 8, which is Stun.
- Mp_zero_state = 8
- #Set the global percent value for the state to kick in at.
- #Enter all numbers as a percent, in decimal form (0.10 = 10%, and so on)
- #Set at 0.0 to disable (barring states)
- #Warning: Even if disabled, if you add the states below in the script,
- #it will become active. If you want to disable this totally except for
- #notetagged enemies and actors, follow the steps to disable the states
- #below as well!
- Mp_zero_value = 0.0
- #Enter here any states that modify the threshold. To disable, just change it
- #to read [0], or some unused state in your game.
- MP_modify_threshold_states = [28, 29]
- #Enter here the amount each state adds or subtracts from the threshold.
- #Must have one entry per state listed above, else the game *will* crash
- #Use 0.0 for the state to add nothing to the threshold.
- #Use negative numbers to decrease it, positive numbers to increase it.
- #You can make the threshold go above 1.0 and below 0.0 with this, so be
- #careful.
- MP_modify_threshold_add = [0.25, -0.25]
- #Enter here the amount each state multiplies to the threshold.
- #Must have one entry per state listed above, else the game *will* crash
- #Use 1.0 if you wish for the threshold to be unchanged by the times step.
- #Use -1.0 to short term disbale the threshold while the state is in effect.
- MP_modify_threshold_multiply = [1.0, 1.0]
- end
- #End of Editable Region
- #--------------------------------------------------------------------------
- #Do not edit anything below here unless you know what you are doing.
- #Failure to ahead to this warning may result in unpredictable behavior in
- #your game. Consider yourself warned
- #__________________________________________________________________________
- module DataManager
- #Alias method, load notetags
- class <<self; alias bg_lowmpstate_load_database load_database; end
- def self.load_database
- bg_lowmpstate_load_database
- bg_lowmpstate_load_notetags
- end
- #New method, bg_lowmpstate_load_notetags
- def self.bg_lowmpstate_load_notetags
- groups = [$data_actors, $data_classes, $data_enemies]
- for group in groups
- for obj in group
- next if obj.nil?
- obj.bg_lowmpstate_load_notetags
- end
- end
- end
- end # End module DataManager
- class RPG::BaseItem
- attr_accessor :low_mp_state
- attr_accessor :low_mp_value
- attr_accessor :apply_on_zero
- #New method, bg_lowmpstate_load_notetags
- def bg_lowmpstate_load_notetags
- #Set the defaults. These will be used if no notetag is found
- self.low_mp_state = BG_lowmpstate::Mp_zero_state
- self.low_mp_value = BG_lowmpstate::Mp_zero_value
- self.apply_on_zero = false
- @store = self.note[/(?<=<Low MP Value: ).*?(?=[>])/].to_f
- if(@store && @store != 0)
- @low_mp_value = @store
- end
- @store2 = self.note[/(?<=<Low MP State: ).*?(?=[>])/].to_f
- if(@store2 && @store2 != 0)
- @low_mp_state = @store2
- @low_mp_state = @low_mp_state.to_i
- end
- if(self.note[/<Apply On Zero>/im])
- @apply_on_zero = true
- end
- end
- end # RPG::BaseItem
- #Class Scene_Battle
- class Scene_Battle < Scene_Base
- alias bg_lowmpstate_use_item use_item
- #Aliased method, use item
- def use_item
- #Store the previous mp before using the item
- oldmp = @subject.mp
- #Call aliased method
- bg_lowmpstate_use_item
- #Calculate the threshold value for an actor
- if(@subject.actor?)
- mpthreshold = (@subject.mmp * @subject.actor.low_mp_value).to_i
- end
- #Calculcate the threshold value for an enemy
- if(@subject.enemy?)
- mpthreshold = (@subject.mmp * @subject.enemy.low_mp_value).to_i
- end
- #If you have battlers that are neither actor or enemy, add their code
- #at this point of the script.
- ctr = 0 #Counter for upcoming for loop
- #Parse the arrays, see if we need to modify the threshold based on states
- #applied to the subject using the item.
- #Takes into account states that were just added by using the item.
- for state_parse in BG_lowmpstate::MP_modify_threshold_states
- if(@subject.state?(state_parse))
- mpthreshold += (@subject.mmp * BG_lowmpstate::MP_modify_threshold_add[ctr]).to_i
- mpthreshold *= BG_lowmpstate::MP_modify_threshold_multiply[ctr]
- mpthreshold = mpthreshold.to_i
- end #End if loop
- ctr += 1 #Increment the counter
- end #End for loop
- #Check to see if we have fallen below the MP threahold.
- #Check if it is an actor first
- if(@subject.actor?)
- if(@subject.mp != 0 && oldmp != @subject.mp && oldmp > mpthreshold && @subject.mp <= mpthreshold)
- @subject.add_state(@subject.actor.low_mp_state)
- end
- #Check for the apply on zero condition
- if(@subject.actor.apply_on_zero == true && @subject.mp != oldmp && @subject.mp == 0 && mpthreshold == 0)
- @subject.add_state(@subject.actor.low_mp_state)
- end
- end
- #Check to see if it is an enemy and it has fallen below the threshold
- if(@subject.enemy?)
- if(@subject.mp != 0 && oldmp != @subject.mp && oldmp > mpthreshold && @subject.mp <= mpthreshold)
- @subject.add_state(@subject.enemy.low_mp_state)
- end
- #Check for the apply on zero condition
- if(@subject.enemy.apply_on_zero == true && @subject.mp != oldmp && @subject.mp == 0 && mpthreshold == 0)
- @subject.add_state(@subject.enemy.low_mp_state)
- end
- end
- end #End def use_item
- end #End Scene_Battle class
- #Class Game_Battler
- class Game_Battler < Game_BattlerBase
- alias bg_lowmpstate_execute_damage execute_damage
- #alias method, Execute Damage
- def execute_damage(user)
- #Store the old mp before damage is applied
- oldmp = self.mp
- #Store the threshold value for an actor
- if(actor?)
- mpthreshold = (self.mmp * self.actor.low_mp_value).to_i
- end
- #Store the threshld value for an enemy
- if(enemy?)
- mpthreshold = (self.mmp * self.enemy.low_mp_value).to_i
- end
- #If you have battlers that are neither actors or enemies, enter their
- #code here.
- #Parse the states, to see if we need to adjust the threshold now
- ctr = 0 #Counter for the for loop
- for state_parse in BG_lowmpstate::MP_modify_threshold_states
- if(self.state?(state_parse))
- mpthreshold += (self.mmp * BG_lowmpstate::MP_modify_threshold_add[ctr]).to_i
- mpthreshold *= BG_lowmpstate::MP_modify_threshold_multiply[ctr]
- mpthreshold = mpthreshold.to_i
- end
- ctr += 1 #increment the counter
- end #End the for loop
- #Call aliased method
- bg_lowmpstate_execute_damage(user)
- #Add the state if the damage took us below the threshhold
- if(actor?)
- if(self.mp != 0 && self.mp != oldmp && self.mp <= mpthreshold && oldmp > mpthreshold)
- add_state(actor.low_mp_state)
- end
- #Check to see if we are to apply the state on zero now
- if(actor.apply_on_zero == true && self.mp != oldmp && self.mp == 0 && mpthreshold == 0)
- add_state(actor.low_mp_state)
- end
- end
- if(enemy?)
- if(self.mp != 0 && self.mp != oldmp && self.mp <= mpthreshold && oldmp > mpthreshold)
- add_state(enemy.low_mp_state)
- end
- #Check to see if we are to apply the state on zero now
- if(enemy.apply_on_zero == true && self.mp != oldmp && self.mp == 0 && mpthreshold == 0)
- add_state(enemy.low_mp_state)
- end
- end
- end
- end #End Game_Battler Class
Advertisement
Add Comment
Please, Sign In to add comment