Disable skill until HP is below a certain threshold script?

I am looking for an RPG Maker VX Ace script that prohibits the user from using certain skills until that character's HP is below a certain percentage of their maximum.

Ideally, I would put in the skill's notebox something like

<Available Below: 30> meaning the skill becomes available when the character's HP is below 30%

I would like this to prevent spamming of clutch HP draining moves unless the character actually needs it.


Could I please get someone to make me something like this? Please and thank you.
Yanfly skill restrictions
<restrict eval>
a.hp < (a.mhp * 30)
</restrict eval>

Not tested.
Might be 'self' and not 'a' like Trihan says below.
<restrict eval>
self.hp < (self.mhp * 30)
</restrict eval>
That method always crashes the game with

Code:
Yanfly cooldown:760:in `eval': undefined local variable or method `a' for #<Game_Actor:0xcaf15e8>, NameError
    from Yanfly cooldown:760:in `eval'
    from Yanfly cooldown:760:in `restrict_eval?'
    from Yanfly cooldown:576:in `skill_restriction?'
    from Yanfly cooldown:919:in `skill_restriction?'
    from Yanfly cooldown:906:in `draw_item'
    from Window_Selectable:409:in `block in draw_all_items'
    from Window_Selectable:409:in `times'
    from Window_Selectable:409:in `draw_all_items'
    from Window_SkillList:119:in `refresh'
    from Window_SkillList:32:in `stype_id='
    from Scene_Battle:346:in `command_skill'
    from Window_Selectable:212:in `call'
    from Window_Selectable:212:in `call_handler'
    from Window_Command:136:in `call_ok_handler'
    from Window_Selectable:322:in `process_ok'
    from Window_Selectable:297:in `process_handling'
    from Window_Selectable:276:in `update'
    from Scene_Base:95:in `block in update_all_windows'
    from Scene_Base:93:in `each'
    from Scene_Base:93:in `update_all_windows'
    from Scene_Base:49:in `update_basic'
    from Screenshot Take:144:in `update_basic'
    from Scene_Battle:56:in `update_basic'
    from Scene_Base:41:in `update'
    from Scene_Battle:45:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:22:in `run'
    from Mapshot:986:in `run'
    from Screenshot Take:156:in `run'
    from Backtrace:10:in `block in <main>'

line 760 is the restrict eval line.


And it crashes the moment I bring up the skill list before I even select anything
That method always crashes the game with

Code:
Yanfly cooldown:760:in `eval': undefined local variable or method `a' for #<Game_Actor:0xcaf15e8>, NameError
    from Yanfly cooldown:760:in `eval'
    from Yanfly cooldown:760:in `restrict_eval?'
    from Yanfly cooldown:576:in `skill_restriction?'
    from Yanfly cooldown:919:in `skill_restriction?'
    from Yanfly cooldown:906:in `draw_item'
    from Window_Selectable:409:in `block in draw_all_items'
    from Window_Selectable:409:in `times'
    from Window_Selectable:409:in `draw_all_items'
    from Window_SkillList:119:in `refresh'
    from Window_SkillList:32:in `stype_id='
    from Scene_Battle:346:in `command_skill'
    from Window_Selectable:212:in `call'
    from Window_Selectable:212:in `call_handler'
    from Window_Command:136:in `call_ok_handler'
    from Window_Selectable:322:in `process_ok'
    from Window_Selectable:297:in `process_handling'
    from Window_Selectable:276:in `update'
    from Scene_Base:95:in `block in update_all_windows'
    from Scene_Base:93:in `each'
    from Scene_Base:93:in `update_all_windows'
    from Scene_Base:49:in `update_basic'
    from Screenshot Take:144:in `update_basic'
    from Scene_Battle:56:in `update_basic'
    from Scene_Base:41:in `update'
    from Scene_Battle:45:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:22:in `run'
    from Mapshot:986:in `run'
    from Screenshot Take:156:in `run'
    from Backtrace:10:in `block in <main>'

line 760 is the restrict eval line.


And it crashes the moment I bring up the skill list before I even select anything
Replace "a" with "self".
Same error with "user"

Code:
Yanfly cooldown:760:in `eval': undefined local variable or method `user' for #<Game_Actor:0xcb11e38>, NameError
    from Yanfly cooldown:760:in `eval'
    from Yanfly cooldown:760:in `restrict_eval?'
    from Yanfly cooldown:576:in `skill_restriction?'
    from Yanfly cooldown:919:in `skill_restriction?'
    from Yanfly cooldown:906:in `draw_item'
    from Window_Selectable:409:in `block in draw_all_items'
    from Window_Selectable:409:in `times'
    from Window_Selectable:409:in `draw_all_items'
    from Window_SkillList:119:in `refresh'
    from Window_SkillList:32:in `stype_id='
    from Scene_Battle:346:in `command_skill'
    from Window_Selectable:212:in `call'
    from Window_Selectable:212:in `call_handler'
    from Window_Command:136:in `call_ok_handler'
    from Window_Selectable:322:in `process_ok'
    from Window_Selectable:297:in `process_handling'
    from Window_Selectable:276:in `update'
    from Scene_Base:95:in `block in update_all_windows'
    from Scene_Base:93:in `each'
    from Scene_Base:93:in `update_all_windows'
    from Scene_Base:49:in `update_basic'
    from Screenshot Take:144:in `update_basic'
    from Scene_Battle:56:in `update_basic'
    from Scene_Base:41:in `update'
    from Scene_Battle:45:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:22:in `run'
    from Mapshot:986:in `run'
    from Screenshot Take:156:in `run'
    from Backtrace:10:in `block in <main>'
Same error with "user"

Code:
Yanfly cooldown:760:in `eval': undefined local variable or method `user' for #<Game_Actor:0xcb11e38>, NameError
    from Yanfly cooldown:760:in `eval'
    from Yanfly cooldown:760:in `restrict_eval?'
    from Yanfly cooldown:576:in `skill_restriction?'
    from Yanfly cooldown:919:in `skill_restriction?'
    from Yanfly cooldown:906:in `draw_item'
    from Window_Selectable:409:in `block in draw_all_items'
    from Window_Selectable:409:in `times'
    from Window_Selectable:409:in `draw_all_items'
    from Window_SkillList:119:in `refresh'
    from Window_SkillList:32:in `stype_id='
    from Scene_Battle:346:in `command_skill'
    from Window_Selectable:212:in `call'
    from Window_Selectable:212:in `call_handler'
    from Window_Command:136:in `call_ok_handler'
    from Window_Selectable:322:in `process_ok'
    from Window_Selectable:297:in `process_handling'
    from Window_Selectable:276:in `update'
    from Scene_Base:95:in `block in update_all_windows'
    from Scene_Base:93:in `each'
    from Scene_Base:93:in `update_all_windows'
    from Scene_Base:49:in `update_basic'
    from Screenshot Take:144:in `update_basic'
    from Scene_Battle:56:in `update_basic'
    from Scene_Base:41:in `update'
    from Scene_Battle:45:in `update'
    from Scene_Base:14:in `main'
    from SceneManager:22:in `run'
    from Mapshot:986:in `run'
    from Screenshot Take:156:in `run'
    from Backtrace:10:in `block in <main>'
You missed my edit. Use "self".
self works but the move was available even at 100% health.

However, ChatGPT told me to make it

Ruby:
<restrict eval>
self.hp > (self.mhp * 0.30)
</restrict eval>


Because it disables if true, not if false and this disables it unless HP is less than 30%



Now is it possible to make an item only usable when the entire party is less than 30% with restrict eval?
Because it disables if true
Yes forgot about that. restrict equals don't do it unless false.

<restrict eval>
$game_party.members.each { |a| a.hp > (a.mhp * 0.30) }
</restrict eval>

Not sure if the curly bracket goes in front of the pipe or after. Trihan can correct me.
And again not tested.
Yes forgot about that. restrict equals don't do it unless false.

<restrict eval>
$game_party.members.each { |a| a.hp > (a.mhp * 0.30) }
</restrict eval>

Not sure if the curly bracket goes in front of the pipe or after. Trihan can correct me.
And again not tested.
It goes before, that should be correct.
Will this cause a crash

{ |a| a.hp > (a.mhp * 0.30) }

Like it did with the other skill with the a variable?
Ruby:
$game_party.members.each { |a| a.hp > (a.mhp * 0.30) }
How weird, it should work as it is. Well, there the parentheses () are optional.
What's the exact error message you're getting there?
I am just asking because it crashed with the healing bird summon, which prompted you folks to tell me to change it to .self

So, under that same logic, wouldn't a.hp do the same error here?


I do not want to get in a heated battle where I need to use this item and have it crash since it's supposed to be an expensive clutch save move that one will use when they are far into battle and are in a bind.
That piece of code uses a because it's a block variable as defined in |a| so the syntax is fine.
Tell me, does the game crash throw any error message? If not, that might complicate things a bit more than first expected.
The code is not working whatsoever.

The Emergency Medic is available even when everybody's health is at maximum


Even:

<restrict eval>
true
</restrict eval>

Does not work (used this to test)


Does Yanfly Skill Restrictions not work with items?
The code is not working whatsoever.

The Emergency Medic is available even when everybody's health is at maximum


Even:

<restrict eval>
true
</restrict eval>

Does not work (used this to test)


Does Yanfly Skill Restrictions not work with items?
You know what, I didn't even clue into the fact that you said you were using the last option for items.
The <restrict eval> is not an option in the script for items. *read through the script header and you will see.

More code will have to be added if it is to be used.

Original thread: https://forums.rpgmakerweb.com/threads/disable-skill-until-hp-is-below-a-certain-threshold-script.180137/