Assigning variable to actor ID during battle.

I'm having trouble with assigning variables to an actor's ID during battles.

At the moment, I have an item that, when used, sets a variable (35) to the ID of the actor using it, and then calls a common event that does conditional processing.

It works great outside of battles, but does not function in the battle scene.

The formula in the damage box is:

(SceneManager._scene.constructor == Scene_Battle) ? $gameVariables.setValue(35, $gameParty._actors[this._targetIndex]) : $gameVariables.setValue(35, $gameParty._targetActorId);

Image1.png


Image4.png


When the item is used in battles, it just reads "Actor lost no HP"
alternate way of doing this is having item apply a blank placeholder state on the user and then the event checks for the state instead of variable number. remember to have the event also remove the placeholder state.
formula a.addState(n)
$gameParty._actors[this._targetIndex]) is going to give you the actor, not the actor id.

In damage formula, a is the user and b is the target. You can use a OR b in this case, because the item's target is the user. So you can just do this, and not worry about if you're in battle or not:

Code:
$gameVariables.setValue(35, a.actorId());

Now, you've got that set as HP Recover, but you're not actually returning anything. So maybe something like this:

Code:
$gameVariables.setValue(35, a.actorId()); 0

which will return 0 as the actual damage.



formula a.addState(n)

If you do it via a state, just make the item apply a state. Don't need to worry about doing it in a damage formula.
i do it in formula because items i use this mechanic with aren't always self target
But the OP IS using an item that's self-target, and they want a solution for THEIR issue 🙂
thats why i said "alternate way." just switching variable for placeholder state. same state can be used as markers for user, ally and/or enemy targeted common events triggered by skills or items.

and truth be told i still dont understand script, but knew a method to fix his issue.
but thanks for giving him the version that work for his current method.
Thanks for the help! I had tried this before:
$gameVariables.setValue(35, a.actorId());
but I had no luck, which I guess is because I was missing the 0 value at the end.

In the end I went with:

(SceneManager._scene.constructor == Scene_Battle) ? $gameVariables.setValue(35, a.actorId()) : $gameVariables.setValue(35, $gameParty._targetActorId); a.mhp*0.3+10

I then made a few changes to the common event to incorporate luck attributes and so on, and shuffle some things around.

And I actually used
a.addState(n)
to solve another problem I was having with a skill that I wanted to target an enemy, but also have a passive effect on the user, so that was super helpful too!

Original thread: https://forums.rpgmakerweb.com/threads/assigning-variable-to-actor-id-during-battle.118405/