Target's luck in Yanfly's CTB ( <After CTB Eval> )

Hi. I'm trying to use this notetag with Yanfly's CTB plugin, but the debugger says target is not defined. Help...

JavaScript:
<After CTB Eval>

var temp = ( Math.randomInt(400) - 100 + user.luk - target.luk ) / 3;
if (temp < -33) temp = -33;
if (temp == 0) temp = 1;
if (temp > 33) temp = 33;
var temp2 = 5 - 5 * user.agi / 600 - 5 * temp / 100;
var tempmin = 5 * 2 / 3;
var tempmax = 5 * 4 / 3;
if (temp2 < tempmin) temp2 = tempmin;
if (temp2 > tempmax) temp2 = tempmax;
speed = - (temp2);

</After CTB Eval>

target, enemy, b... It's not working. 5 is just a super slow action recovery time I'm using for test purposes.

And yes, I'm basically using luck along with agility and randomness to decide the delay that the action's user will receive (in a similar way to how Final Fantasy X ranks work, I mean, the action deciding the time it will take until the user's next turn instead of agility alone)
Moved to: Javascript/Plugin Support
Hi. I'm trying to use this notetag with Yanfly's CTB plugin, but the debugger says target is not defined. Help...

JavaScript:
<After CTB Eval>

var temp = ( Math.randomInt(400) - 100 + user.luk - target.luk ) / 3;
if (temp < -33) temp = -33;
if (temp == 0) temp = 1;
if (temp > 33) temp = 33;
var temp2 = 5 - 5 * user.agi / 600 - 5 * temp / 100;
var tempmin = 5 * 2 / 3;
var tempmax = 5 * 4 / 3;
if (temp2 < tempmin) temp2 = tempmin;
if (temp2 > tempmax) temp2 = tempmax;
speed = - (temp2);

</After CTB Eval>

target, enemy, b... It's not working. 5 is just a super slow action recovery time I'm using for test purposes.

And yes, I'm basically using luck along with agility and randomness to decide the delay that the action's user will receive (in a similar way to how Final Fantasy X ranks work, I mean, the action deciding the time it will take until the user's next turn instead of agility alone)
As you said, it's not defined. Since it's run on every action, the <after CTB eval> only uses values on the battler that just completed an action. While there are likely a multitude of reasons why it doesn't look at the target of the action that just occurred, I will point out a couple of obvious ones.
  • What if the action taken had no target (guard), or the target was the user?
  • If the target of an attack was an enemy and it died, values on it might not exist anymore at all, and actually cause the game to crash.
I'd rethink how this system works, and consider why the targets luk should affect the random delay of the attacker in any way in the first place.

Original thread: https://forums.rpgmakerweb.com/threads/targets-luck-in-yanflys-ctb-after-ctb-eval.118106/