Common Event: Force Action

Hello!

I want my priest's single target skill to deal light damage to Undead, or dark damage to living targets.
In order to do so, I added the Undead status, then I created a fake skill whose task is just to call a common event.
This common event has to check whether the skill is targeting an Undead.
Finally, if the target is Undead, the common event will force to priest to use the light version of the spell; otherwise, the dark one will be used.

So the question is: how to script this common event? I'm ignorant in Javascript, and although I found a similiar topic, it was about forcing statuses, not skills, and the request was uncertain.
This is what I managed to put together:

var targetIndex = BattleManager._action._targetIndex // finds the target

var target = $gameTroop.members()[targetIndex] //finds the target's object

var undeadSID = 25 //undead state ID is 25

if (target.isStateAffected(undeadSID)){ // if object is undead

// force party member #4 to use skill #164

}

else{

//the very same, but with skill #163

);

Can you please complete this?
Thank you in advance 😀
why would you even need javascript for this? everything should be able to be done with event commands alone.

please take a step back and tell us what you want to do with details instead of how you want to do this. I don't know if I would use two skills or a common event at all, there are also other ways like using the damage formula or getting tricky with damage elements and so on.
why would you even need javascript for this? everything should be able to be done with event commands alone.

please take a step back and tell us what you want to do with details instead of how you want to do this. I don't know if I would use two skills or a common event at all, there are also other ways like using the damage formula or getting tricky with damage elements and so on.

I'd like to create a skill that deals different elemental damage depending on the enemy's status. If they're Undead, the skill will deal light damage. Otherwise, it will deal dark damage. If there's a simpler way to realize this, I'm well happy to follow it.
Use the script call list
https://forums.rpgmakerweb.com/index.php?threads/rpg-maker-mv-script-call-list.46456/

There's the force action script call you're misssing in there.
var targetIndex = BattleManager._action._targetIndex
var target = $gameTroop.members()[targetIndex]
var undeadSID = 25
if (target.isStateAffected(undeadSID)){
$gameParty.members()[4].forceAction( 164, -2);
BattleManager.forceAction($gameParty.members()[4]);
else{
$gameParty.members()[4].forceAction( 163, -2);
BattleManager.forceAction($gameParty.members()[4]);
}

No skill is executed. What's the matter?
Well the most obvious cause would be that there's no $gameParty.members()[4] in the battle. If you try to read that in english it means the fifth member of the party isn't in battle. Indexes start at 0.

You probably should use $gameActors.actor(id) instead.

If not then use $gameParty.battleMembers()[index] to only pick from the actors currently in battle, and keep in mind indexes start from 0.
Well the most obvious cause would be that there's no $gameParty.members()[4] in the battle. If you try to read that in english it means the fifth member of the party isn't in battle. Indexes start at 0.

You probably should use $gameActors.actor(id) instead.

If not then use $gameParty.battleMembers()[index] to only pick from the actors currently in battle, and keep in mind indexes start from 0.

Daaaaaamn, right, I forgot indexes start from 0!
She's the fourth member, thus the number 3.
Thank you very much <3

EDIT:
var targetIndex = BattleManager._action._targetIndex
var target = $gameTroop.members()[targetIndex]
var undeadSID = 25
if (target.isStateAffected(undeadSID)){
$gameParty.battleMembers()[3].forceAction( 164, -2);
BattleManager.forceAction($gameParty.battleMembers()[3]);
else{
$gameParty.battleMembers()[3].forceAction( 163, -2);
BattleManager.forceAction($gameParty.battleMembers()[3]);
}

Still not working D:
WHEN do you execute that code? Can you give us a screenshot of where in the game it is?
Because it could be that "last target" doesn't exist at that moment and you need a direct specification of a specific target.
(please test if it works with a direct index)
WHEN do you execute that code? Can you give us a screenshot of where in the game it is?
Because it could be that "last target" doesn't exist at that moment and you need a direct specification of a specific target.
(please test if it works with a direct index)

Uhm I thought "last target" would be right since you had just targeted that enemy with the placeholder skill.
Anyway, changing that "-2" to another number still won't force the action.
It should force the action upon the target of the placeholder skill.
then you need to answer the question I asked. where and when are you executing the code?
then you need to answer the question I asked. where and when are you executing the code?

It's a common event, called by a skill, during the battle.
It's a common event, called by a skill, during the battle.
please show us screenshots of both the skill and the common event. We need more details to guess what went wrong.
Cattura.PNG

"Castigo" is the skill. Targets 1 enemy, only in battle. Calls "Castigo" common event.
Cattura 2.PNG

This is the common event, invoking the other 2 skills.
You're missing the ending } of your if statement. This syntax error will cause your whole block to not execute.

When dealing with script calls and unintended results always bring up the console to look at the error messages. This will help you understand why and where you messed up, and allow you to fix easy to find mistakes such as this one.
You're missing the ending } of your if statement. This syntax error will cause your whole block to not execute.

When dealing with script calls and unintended results always bring up the console to look at the error messages. This will help you understand why and where you messed up, and allow you to fix easy to find mistakes such as this one.

Thank you, it's alright now <3

Original thread: https://forums.rpgmakerweb.com/threads/common-event-force-action.110397/