Altering a "substitute" script to activate based on a variable.

I originally found the script below on this site. There is a link to the exact page below. Anyway, I would like to know if it is possible to edit this script so that it uses a variable instead of an HP percentage. More specifically, if an actor has the substitute flag, I want them to cover for any actor whose HP is lower than or equal to the value in the specified variable.

Where I found the script: http://forums.rpgmak...ult-substitute/

  1. class Scene_Battle < Scene_Base
  2. #--------------------------------------------------------------------------
  3. # * Check Substitute Condition
  4. #--------------------------------------------------------------------------
  5. def check_substitute(target, item)
  6. # default value is 25%, change it to whatever you want
  7. target.hp < target.mhp / 4 && (!item || !item.certain?)
  8. end
  9. end
Just change "target.mhp / 4" with $game_variables[id] and it should work  🙂  
Just change "target.mhp / 4" with $game_variables[id] and it should work  🙂  
Worked like a charm, thank you.

Original thread: https://forums.rpgmakerweb.com/threads/altering-a-substitute-script-to-activate-based-on-a-variable.37901/