(Solved) Apply damage to actor on missed skill

Is there a way I can make an actor take damage with a common event when they miss their skill?
1682332974198.png

I tried this, but it only manages to correctly get the current actor.
I don't have time to look now, but my guess is that Game_ActionResult is not what you want there - that's a class, not an object. Try BattleManager._subject.result().missed or BattleManager._target.result().missed (though it looks like it's _targets as in multiple, so some extra playing needed there)
BattleManager._targets[0].result().missed should probably do what you want.

Note that using this in a common event will make it happen after the actor has finished using the skill and everything else has displayed. I would use a notetag from Yanfly's Skill Core to make it happen during the skill for a smoother look.
By default, BattleManager._targets is populated with the full target list when the action starts. However, immediately prior to invoking the action on a target, that target gets shifted out of the list. So by the time your common event runs, BattleManager._targets will be empty.

I don't think you need to check the result, though, since the damage formula only gets evaluated when the action hits. Without a plugin, you could try something like this in the damage formula:

$gameSwitches.setValue(123, true); 50
I.e. "turn on switch 123, then return a value of 50". Replace 50 with your damage formula and 123 with an appropriate switch ID. In the common event attached to the skill:
  • Check if that switch is off (i.e. miss).
  • At the end, always turn the switch off.
That way, the switch should be off at all times except when the skill hits.

Or like Turan mentions, just find an appropriate plugin, e.g. with YEP Skill Core (untested):

<After Eval> if (target.result().missed) { user.gainHp(-50); } </After Eval>
By default, BattleManager._targets is populated with the full target list when the action starts. However, immediately prior to invoking the action on a target, that target gets shifted out of the list. So by the time your common event runs, BattleManager._targets will be empty.

I don't think you need to check the result, though, since the damage formula only gets evaluated when the action hits. Without a plugin, you could try something like this in the damage formula:

$gameSwitches.setValue(123, true); 50

I.e. "turn on switch 123, then return a value of 50". Replace 50 with your damage formula and 123 with an appropriate switch ID. In the common event attached to the skill:
  • Check if that switch is off (i.e. miss).
  • At the end, always turn the switch off.
That way, the switch should be off at all times except when the skill hits.

Or like Turan mentions, just find an appropriate plugin, e.g. with YEP Skill Core (untested):

<After Eval> if (target.result().missed) { user.gainHp(-50); } </After Eval>

The YEP Skill Core script worked perfectly, thanks for the help

Original thread: https://forums.rpgmakerweb.com/threads/solved-apply-damage-to-actor-on-missed-skill.156949/