MV Yanfly Battle System ATB afterATBEval set speed depending on enemy status

First of all, Im not sure how I move on that forum so sorry if this thread is under bad topic (and please help me to move it)

I need help with setting "speed" variable in Yanfly's ATB battle system plugin in notetag "After ATB Eval"
The docs says :
<After ATB Eval>

speed = x;

</After ATB Eval>

so in general after skill is done it sets speed to x
I want to set speed to x only if enemy has status (so enemy has to be alive), lets say, with id "5"

So in pseudocode its looks like that

if enemy.hasStatus(5)
speed = 100
else
speed = 0

But
I got errors like
1728297481970.png

and after some debugging i see that
afterATBEval function doesn't have "target" or anything related to enemy
BUT i have found this:
1728297553352.png


this is body of the function, and it uses $gameSwitches_data as 's'
$gameSwitches_data has two interesting for me functions (according to kinoar.github.io)
value(ID) and setValue(ID,bool)
so i thought that code like this

<After ATB Eval>
if (s.value(301))
{
s.setValue(301, false);
speed = 75;
}
</After ATB Eval>

Would work - but no, if switch with id 301 is on (this switch indicaties if enemy has status) it should set speed to the value
but it crashes just like two images above

Using switch instead of something like
(target.isStateAffected(5))
is workaround already but it still dont work

im aware that
eval(item.atbAfterEval);
cause error but i do not understand why and how can i fix it
ill preface this with i dont use the plugin.

I need help with setting "speed" variable in Yanfly's ATB battle system plugin in notetag "After ATB Eval
the speed of who, as who? according to the documentation, the <After ATB Eval> tag runs effects on the user of the skill, while the <Target ATB Eval> runs effects on the target of the skill. if youre trying to have a battler affect the speed of any other battler, youre not using the right tag

Would work - but no, if switch with id 301 is on (this switch indicaties if enemy has status) it should set speed to the value
but it crashes just like two images above
youre misunderstanding what the s is. the s is the ._data property of $gameSwitches, which is an array. it doesnt have those functions. value and setValue() are functions of $gameSwitches. you want $gameSwitches.setValue(301, false), or s[301] = false

im aware that
eval(item.atbAfterEval);
cause error but i do not understand why and how can i fix it
the line just executes the code you have set as the skill's <After ATB Eval>. if its throwing an error, its not because something is wrong with the line. Its because the <After ATB Eval> its trying to run from the current skill has an error in it. which it does. cause s.value() is a function that doesnt exist
ill preface this with i dont use the plugin.


the speed of who, as who? according to the documentation, the <After ATB Eval> tag runs effects on the user of the skill, while the <Target ATB Eval> runs effects on the target of the skill. if youre trying to have a battler affect the speed of any other battler, youre not using the right tag


youre misunderstanding what the s is. the s is the ._data property of $gameSwitches, which is an array. it doesnt have those functions. value and setValue() are functions of $gameSwitches. you want $gameSwitches.setValue(301, false), or s[301] = false


the line just executes the code you have set as the skill's <After ATB Eval>. if its throwing an error, its not because something is wrong with the line. Its because the <After ATB Eval> its trying to run from the current skill has an error in it. which it does. cause s.value() is a function that doesnt exist
Thanks for the reply, im losing my mind with this
1) If target has status id 5 then set USER speed to X. <After ATB Eval> is fine
2) Thanks for clarification, in fact i have had problem to understand this

The only way to check enemy status is put in formula damage

if (b.isStateAffected(5)) { v[35] = 50;
(...)
}
i gave up on using switch, i used variable with id 35 to set to 50;
later in tag i use:

<After ATB Eval>

speed = v[35];

</After ATB Eval>

I thought this will do - i set speed to variable, later set variable to speed
The game does not crash, but i doesnt set speed to 50 anyway
the screenshot you provided shows a function for setting speed. something you can try is using the other notetag that has access to the target to run it on the user.

Code:
<Target ATB Eval>
if (target.isStateAffected(5))
  user.setATBSpeed(50);
</Target ATB Eval>
the screenshot you provided shows a function for setting speed. something you can try is using the other notetag that has access to the target to run it on the user.

Code:
<Target ATB Eval>
if (target.isStateAffected(5))
  user.setATBSpeed(50);
</Target ATB Eval>
Thats clever idea too but it looks like it doesnt work too. No idea why, this is super weird

EDIT: Ok, i understand it now
My another misunderstanding was that setATBSpeed sets to % of gauge
So user.setATBSpeed(50); in my mind should set to 50%
But this is wrong
Full gauge is

Math.max(5000, BattleManager.highestBaseAgi() * 100)

To make this work i had to read doc again to learn that there is "max" variable (lol)

And my solution was:
1.in damage formula set switch:

if (b.isStateAffected(5)) { s[301]=true;
(...)
}
and then
2.
<After ATB Eval>
if (s[301])
{
speed = max * 0.5;
}
</After ATB Eval>

on "else" i set s[301] to false and it works perfectly
Thats clever idea too but it looks like it doesnt work too. No idea why, this is super weird
just gave the plugin a glance and little test. try this
Code:
<After ATB Eval>
if (BattleManager._targets[0].isStateAffected(5))
speed = 5000;
</After ATB Eval>
BattleManager.atbTarget() tells you how much speed is needed in order to act, and its based on the full gauge parameter for the plugin, which defaults to
Code:
Math.max(5000, BattleManager.highestBaseAgi() * 100)
50 is nowhere near enough to be noticeable without customization.

EDIT:
I see the edit now. good to see you have something working
just gave the plugin a glance and little test. try this
Code:
<After ATB Eval>
if (BattleManager._targets[0].isStateAffected(5))
speed = 5000;
</After ATB Eval>
BattleManager.atbTarget() tells you how much speed is needed in order to act, and its based on the full gauge parameter for the plugin, which defaults to
Code:
Math.max(5000, BattleManager.highestBaseAgi() * 100)
50 is nowhere near enough to be noticeable without customization.

EDIT:
I see the edit now. good to see you have something working
Thanks for help Robro🙂

Original thread: https://forums.rpgmakerweb.com/threads/yanfly-battle-system-atb-afteratbeval-set-speed-depending-on-enemy-status.172444/