MZ Getting a battler's ID and target's ID for use in VisuStella Action Sequences

(I apologize in advance if I posted in the wrong forum section -- this is only my second time posting)

Hello!

Does anyone know how to get a current battler's ID and their target(s) ID(s), store them as variables, and use them in a formula?

Background:

I am trying to create a custom "hit chance" formula, using VisuStella action sequences to implement it. My end goal is to have actor parameters influence the chance of successfully hitting an enemy. For simplicity while testing the concept, the initial formula is just (user's Attack / Target's defense) * 0.75 (as in, when the user's Attack equals the target's Defense, the chance of landing a hit is 75%).

My plan to implement this is to ignore the Evasion parameter (all classes and enemies have an Evasion of 0%) and set everyone's base Hit Rate to 0%, then do all the formula calculations in custom action sequences for each skill and add it to the user's Hit Rate using the MECH: Multipliers plugin command (adding to the Flat of Hit Rate).

The formula I wrote was this:


($gameActors.actor($gameVariables.value(1)).atk / $gameTroop.members()[$gameVariables.value(2)].def) * 0.75

Where control variables 1 and 2 are the current battler/user and the target of the skill, respectively.


Problem is that after hours of searching online -- MZ/VisuStella script call lists and forum posts -- I have not found a way to get the actor ID of the current battler and the enemy ID of the targeted enemy.

I frequently get an error when performing the test skill saying that it is unable to get the property "atk" of either "null" or "undefined", depending on the method I was testing, implying that whatever calls I was using were not grabbing any usable data. "null" occurred when using stuff like BattleManager._subject or this._targetIndex to set the variables. "undefined" occurred when attempting some of the shortcuts used for other formulas, such as the damage formula (using 'a' for current battler, 'b' for target; or 'user' for current battler and 'target' for target).

One post suggested using MV's built-in "last" options to set control variables, but it looks like they only refer to prior actions and are incapable of referring to the actor and enemy in the skill being actively used. (This method would not produce an error if at least one other character acted first before testing the skill; otherwise, if the skill was the first one used, it returned an error).

Another post suggested setting variables in the damage formula, as that uses the 'a' and 'b' setup, but that returned an "undefined" error. I think that either the suggested v[1] = a._actorId and v[2] = b._enemyId formulas are incorrect, or VisuStella's action sequences operate first before reading the skill's damage formula, and thus the variables are never set up.


If anybody knows how to get the IDs of the current battler and their current target, I would be very appreciative.
(Or if anybody knows a better way of implementing this concept, which I failed to stumble across in my search of the internet for solutions).

Thanks in advance!
(I apologize in advance if I posted in the wrong forum section -- this is only my second time posting)

Hello!

Does anyone know how to get a current battler's ID and their target(s) ID(s), store them as variables, and use them in a formula?

Background:

I am trying to create a custom "hit chance" formula, using VisuStella action sequences to implement it. My end goal is to have actor parameters influence the chance of successfully hitting an enemy. For simplicity while testing the concept, the initial formula is just (user's Attack / Target's defense) * 0.75 (as in, when the user's Attack equals the target's Defense, the chance of landing a hit is 75%).

My plan to implement this is to ignore the Evasion parameter (all classes and enemies have an Evasion of 0%) and set everyone's base Hit Rate to 0%, then do all the formula calculations in custom action sequences for each skill and add it to the user's Hit Rate using the MECH: Multipliers plugin command (adding to the Flat of Hit Rate).

The formula I wrote was this:


($gameActors.actor($gameVariables.value(1)).atk / $gameTroop.members()[$gameVariables.value(2)].def) * 0.75

Where control variables 1 and 2 are the current battler/user and the target of the skill, respectively.


Problem is that after hours of searching online -- MZ/VisuStella script call lists and forum posts -- I have not found a way to get the actor ID of the current battler and the enemy ID of the targeted enemy.

I frequently get an error when performing the test skill saying that it is unable to get the property "atk" of either "null" or "undefined", depending on the method I was testing, implying that whatever calls I was using were not grabbing any usable data. "null" occurred when using stuff like BattleManager._subject or this._targetIndex to set the variables. "undefined" occurred when attempting some of the shortcuts used for other formulas, such as the damage formula (using 'a' for current battler, 'b' for target; or 'user' for current battler and 'target' for target).

One post suggested using MV's built-in "last" options to set control variables, but it looks like they only refer to prior actions and are incapable of referring to the actor and enemy in the skill being actively used. (This method would not produce an error if at least one other character acted first before testing the skill; otherwise, if the skill was the first one used, it returned an error).

Another post suggested setting variables in the damage formula, as that uses the 'a' and 'b' setup, but that returned an "undefined" error. I think that either the suggested v[1] = a._actorId and v[2] = b._enemyId formulas are incorrect, or VisuStella's action sequences operate first before reading the skill's damage formula, and thus the variables are never set up.


If anybody knows how to get the IDs of the current battler and their current target, I would be very appreciative.
(Or if anybody knows a better way of implementing this concept, which I failed to stumble across in my search of the internet for solutions).

Thanks in advance!
It's worth noting that the solution that NaosoX pointed out requires you to have VisuStella Core Engine installed. For those who aren't using that plugin, the way to get the subject's actor ID is:
JavaScript:
BattleManager._subject.actorId()

Supposing that there is only one target, the way to get the target's index is:
JavaScript:
BattleManager._targets[0].index()
Welp -- that's what I get for not reading the help doc thoroughly enough. >.<

Thanks for the help -- the formula worked without a hitch after putting in those shortcuts!

(Kind of surprised my internet searches didn't return such a simple solution, or the solution that Arthran proposed.)
JavaScript:
BattleManager._targets[0].index()
Unfortunately I don't think this one will work in the damage formula, because BattleManager#updateAction shifts each target out of BattleManager._targets immediately before invoking the action on that target.
Spoiler: variables - game data - last
Also, to get the most recent actor subject's ID, you can use either:
  • Control Variables -> Game Data -> Last -> Actor ID to Act, or
  • $gameTemp.lastActionData(2)
This is set immediately before the action starts: Game_Action#applyGlobal <- BattleManager.startAction.

Note: the "Game Data -> Last Target" values are updated after the action is applied to the target, i.e. at the end of Game_Action#apply. So they should reference:
  • The current target if used in a Common Event attached to a skill/item;
  • The previous target if used in the damage formula.
Regardless, in this case it's safer to use the plugin's shortcuts for subject/target because those should be guaranteed to work correctly with all the plugin's features. 😮‍💨
Unfortunately I don't think this one will work in the damage formula, because BattleManager#updateAction shifts each target out of BattleManager._targets immediately before invoking the action on that target.
I wasn't suggesting that he use it in a damage formula directly. His proposed formula seems to be assuming that the index is stored in a game variable, so I was suggesting that he use BattleManager._targets[0].index() to assign that index to the game variable earlier in the action sequence. And he's not talking about a damage formula, but rather he's talking about calculating a custom hit chance, and applying it using the MECH: Multipliers action sequence.

VisuStella action sequences get executed before BattleManager.updateAction is called, so it wouldn't be a problem. But that aside, Battle Core actually completely overwrites BattleManager.updateAction, and it no longer shifts the _targets array anyway.

Regardless, in this case it's safer to use the plugin's shortcuts for subject/target because those should be guaranteed to work correctly with all the plugin's features. 😮‍💨
Well, the issue that I was trying to point out is that those shortcuts are *not* part of the plugin in question. They're part of another plugin, which the OP didn't indicate he/she was using, and anyone else who might wind up having this same question may not be using. The OP was talking about VS Battle Core, and the changelog snippet that NaosoX posted is from VS Core Engine.
I wasn't suggesting that he use it in the damage formula directly. His proposed formula seems to be assuming that the index is stored in a game variable, so I was suggesting that he use BattleManager._targets[0].index() to assign that index to the game variable earlier in the action sequence.

VisuStella action sequences get executed before BattleManager.updateAction is called, so it shouldn't be a problem. But that aside, Battle Core actually completely overwrites BattleManager.updateAction, and it no longer shifts the _targets array anyway.


Well, the issue that I was trying to point out is that those shortcuts are *not* part of the plugin (VS Battle Core) in question. They're part of another plugin (VS Core Engine), which the OP didn't indicate he/she was using, and anyone else who might wind up having this same question may not be using.
I am trying to create a custom "hit chance" formula, using VisuStella action sequences to implement it.
@NaosoX
Action Sequences aren't part of Core Engine. They're part of Battle Core.
@Arthran - is VisuStella Core Engine no longer a required plugin for VisuStella Battle Core?

I didn't know about the order of execution for their action sequences. Good to know your approach will work in there~
@caethyril
Nope, Battle Core doesn't have any dependencies.

Original thread: https://forums.rpgmakerweb.com/threads/getting-a-battlers-id-and-targets-id-for-use-in-visustella-action-sequences.148500/