[Solved] Enemies use healing spells only if there's something to heal

I'm surprised this hasn't been asked before. But I can't find it in the Master List.


See this?
 

Spoiler
trhythy.png



"Experimento uses Revive." It's great to have someone reviving you. The problem is there is no dead enemy to revive. This enemy is basicly wasting a turn and losing mana for no reason. This happens with non-reviving spells too:

Spoiler
t45ty5.png



"Experimento used Heal." But everyone's HP is full already. It's the same as before.


Another problem is that the target of the spell is randomized, meaning that even if there is someone to heal, the spell might get used on someone that has full HP.


It would be very nice if someone could make a script that solves this. Having enemies use healing spells only if there is someone missing HP. You could, for example, make it so that if you write <healing> in the notetag, enemies only use it if there is someone to heal and only on enemies that are missing HP. I don't know. You're the genious mind here, I'm just a casul' who can't even script.


Thank you for reading. I hope someone will make my little wish come true *_*


Have a great day ^^


Solved: Use https://yanflychannel.wordpress.com/rmvxa/gameplay-scripts/skill-restrictions/,


https://yanflychannel.wordpress.com/rmvxa/battle-scripts/lunatic-targets/


and https://yanflychannel.wordpress.com/rmvxa/battle-scripts/lunatic-targets/ltp-conditions/


Put this in the notetags of reviving spells:

Spoiler
<restrict eval>
gtdm = $game_troop.dead_members.size;
return false if gtdm > 0;
return true;
</restrict eval>



And this into the notetags of healing spells:

Spoiler
<custom target: allies HP below 99%>
<restrict eval>
am = $game_troop.alive_members;
p = 0.99;
mh = am.select{|m| m.hp <= (m.mhp * p)};
return false if mh.size > 0;
return true;
</restrict eval>


'p' is the percentage of health the enemy needs to be at or below before the skill is enabled.
check for enemy AI scripts instead - iirc some of them have additional targeting options as well as the usual skill use conditions.


You won't find such scripts as a separate function, it's usually more general for all enemy skill uses.
check for enemy AI scripts instead - iirc some of them have additional targeting options as well as the usual skill use conditions.


You won't find such scripts as a separate function, it's usually more general for all enemy skill uses.

Thanks! I'll have a look, I'll see what I find.
I haven't found anything that works. Anyone willing to help me? 😀D
Should I bump this? Guess I should.
I used Yanfly Skill Restrictions and Lunatic Targets. Then I created healing and reviving skills for enemy use only, so the restrictions would not carry over to the player. To restrict healing to allies with HP lower than a certain percentage of health, you can put the following into the 'note' box of the skill.


<custom target: allies HP below 65%>


For restricting a revive skill (raising a dead member)

Code:
<restrict eval>
gtdm = $game_troop.dead_members.size;
return false if gtdm > 0;
return true;
</restrict eval>
I used Yanfly Skill Restrictions and Lunatic Targets. Then I created healing and reviving skills for enemy use only, so the restrictions would not carry over to the player. To restrict healing to allies with HP lower than a certain percentage of health, you can put the following into the 'note' box of the skill.



<custom target: allies HP below 65%>


For restricting a revive skill (raising a dead member)



<restrict eval>
gtdm = $game_troop.dead_members.size;
return false if gtdm > 0;
return true;
</restrict eval>

Thank you! The second one works perfectly. The first one doesn't thought.
I used Yanfly Skill Restrictions and Lunatic Targets. Then I created healing and reviving skills for enemy use only, so the restrictions would not carry over to the player. To restrict healing to allies with HP lower than a certain percentage of health, you can put the following into the 'note' box of the skill.
I used Yanfly Skill Restrictions and Lunatic Targets. Then I created healing and reviving skills for enemy use only, so the restrictions would not carry over to the player. To restrict healing to allies with HP lower than a certain percentage of health, you can put the following into the 'note' box of the skill.



<custom target: allies HP below 65%>


For restricting a revive skill (raising a dead member)



<restrict eval>
gtdm = $game_troop.dead_members.size;
return false if gtdm > 0;
return true;
</restrict eval>



Thank you! The second one works perfectly. The first one doesn't thought.
@xdan Oops, you'll need this script as well to make the first one work. LTP Conditions
@xdan Oops, you'll need this script as well to make the first one work. LTP Conditions

Almost there. At first they don't use the skill, but once someone loses hp, they keep using it for the rest of the battle even if everyone is already healed.
@xdan Hmm, well, add the following into the heal skill along with the custom target. This should detect when an alive enemy in the party is below a certain percentage of health. If an enemy is, then the custom target will kick in and only heal that person ... in theory.


'p' is the percentage of health the enemy needs to be at or below before the skill is enabled. I have not tested this code, so it might blow up.

Code:
<restrict eval>
am = $game_troop.alive_members;
p = 0.65;
mh = am.select(|m| m.hp <= (m.mhp * p));
return false if mh.size > 0;
return true;
</restrict eval>
<custom target: allies HP below 65%>
@xdan Hmm, well, add the following into the heal skill along with the custom target. This should detect when an alive enemy in the party is below a certain percentage of health. If an enemy is, then the custom target will kick in and only heal that person ... in theory.


'p' is the percentage of health the enemy needs to be at or below before the skill is enabled. I have not tested this code, so it might blow up.



<restrict eval>
am = $game_troop.alive_members;
p = 0.65;
mh = am.select(|m| m.hp <= (m.mhp * p));
return false if mh.size > 0;
return true;
</restrict eval>
<custom target: allies HP below 65%>



Apparently your syntax is wrong (?)


fewt4.png


It keeps resisting. He wants to use heal and we're not going te forbide it XD


By the way, thanks a lot ^^
@xdan Oh, whoops ... I used parenthesis where I should have used brackets. Here, this should work.

Code:
<restrict eval>
am = $game_troop.alive_members;
p = 0.65;
mh = am.select{|m| m.hp <= (m.mhp * p)};
return false if mh.size > 0;
return true;
</restrict eval>
<custom target: allies HP below 65%>
@xdan Oh, whoops ... I used parenthesis where I should have used brackets. Here, this should work.



<restrict eval>
am = $game_troop.alive_members;
p = 0.65;
mh = am.select{|m| m.hp <= (m.mhp * p)};
return false if mh.size > 0;
return true;
</restrict eval>
<custom target: allies HP below 65%>



I hate RPG Maker.


ythyth.png
@xdan Hmm ... ok, put the custom target part before the restrict eval part.

Code:
<custom target: allies HP below 65%>
<restrict eval>
am = $game_troop.alive_members;
p = 0.65;
mh = am.select{|m| m.hp <= (m.mhp * p)};
return false if mh.size > 0;
return true;
</restrict eval>
@xdan Hmm ... ok, put the custom target part before the restrict eval part.



<custom target: allies HP below 65%>
<restrict eval>
am = $game_troop.alive_members;
p = 0.65;
mh = am.select{|m| m.hp <= (m.mhp * p)};
return false if mh.size > 0;
return true;
</restrict eval>



It worked perfectly. Thanks a lot, seriously ^^
This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/solved-enemies-use-healing-spells-only-if-theres-something-to-heal.67167/