Strange problem - Actor gets effectively stun-locked on Turn 5

def custom_formula_normalatk(a, value = (a.atk - b.def) + rand(5) c = (a.mat - b.mat) d = (b.agi + b.luk) if c > 14 and c > d if b.state?(68) a.tp -= 10 b.tp += 10 return value else b.add_state (68) a.tp -= 10 b.tp += 10 return value end else a.tp -= 10 b.tp += 10 return value endend-This is the code I've used to determine whether or not a skill (normal attack) adds stun (state 68).

-I've purposely written it so that if the target is already stunned, it does not refresh the state.

-in my game, stun lasts 2 turns (because 1 turn is effectively 0 if the user always acts before the enemy in a 1on1 fight).

Everything works perfectly until turn 5, and what's REALLY strange is that it deviates from how things work at turn 3 (which is how it's intended to work).

Here's what happens:

Turn1

Actor attacks Enemy.  Enemy attacks (and stuns) Actor.

Turn 2

Actor is stunned. Enemy attacks actor.

-Stun is removed from Actor-

Turn 3

Actor attacks Enemy. Enemy attacks (and stuns) Actor.

Turn 4

Actor is stunned. Enemy attacks actor.

-Stun is removed from Actor-

Turn5

After selecting attack, the Enemy attacks (and stuns) me before I can act. 

This is unlike Turn 3, where I had just recovered from stun, was able to select attack, and successfully got in a hit before he re-stunned me.

The pattern continues like this; Turn 3 is the only time where the Actor's selected action manifests before he is re-stunned.

So not only am I dumbfounded as to why this is, I obviously want it to be so that after the stun expires, the actor's action takes place (assuming his speed is high enough, which it is in this case) before the Enemy's (since it will re-apply the stun).
The sequence of the actions in default battles is NOT fixed, it does contain a random element and depends on both the AGI of the battlers as well as the speed of the skills.


Please provide screenshots of the skills used as well as screenshots of both the enemy and actor values.


Depending on those values we can determin how high the chance is that the enemy has first action and how often the actor will have first action.


If you do not use default battle, please provide a link to your battlescript in addition to the other info.
Yes I am aware of that, I've ruled that out because I've tried different agility values AND I've tested this exhaustively.  The Actor always "acts" first, his action simply does not register before the enemy's....except on Turn 3.   But here are the screenshots you asked for, attached.

actorvalues.jpg

enemyvalues.jpg

attackskill.jpg
Also before it's suggested:  I have tried it without those added states (overwhelm / loss of focus etc.) - makes no difference. 

Here is a link to the battlescript I use:  https://yanflychannel.wordpress.com/rmvxa/battle-scripts/ace-battle-engine/
I have a suggestion that might work around this problem. Are you trying to effectively give the enemy 2 turns for the actors one? If so, why not just set the action times to +100% on that enemy, and avoid this problem altogether?
No, this is just a specific scenario where it's only two people battling, so a stun = 2 turns for the stunner vs. 1 for the receiver.  if more party members / enemies were involved, I wouldn't want to reward the stunner with more actions, but punish the receiver with less.  Thanks for feedback though...
What's troubling about this problem is that it doesn't occur at Turn 3.   If it did, that would tell me that even though the game is telling me Actor is no longer stunned, something about the stun hasn't finished rubbing off, i.e. that first action would be the last half of the full stunned turn or something.   But the Actor is allowed to both act AND register his action on turn 3, just not on any subsequent turns.  So no idea what it could be.
jonthefox, please avoid double posting, as it is against the forum rules. You can review our forum rules here. Thank you.


Please test and post what happens in the turns after 5 - how long does it take for the sequence to repeat?
From Turn 5 it continues like this:

Turn5

Actor selects attack and targets Enemy.  Enemy attacks first and stuns Actor before he can manifest the action.

Turn6

Actor is stunned.  Enemy attacks Actor.

-Stun is removed from Actor-

Turn7

Actor selects attack and targets enemy.  Enemy attacks first and stuns Actor, before he can manifest the action.

etc.
Ok, though the reason I was asking is you make it sound like it is always stun on turn 1, so you miss turn 2, stun on turn 3, so you miss turn 4. That's why I was suggesting just going to double actions to balance it out instead, as it will give the exact same effect in that battle. You could even make a copy of this enemy (if you ever fight it again with more people) that you fight just this once in the 1 on 1 battle.
yeah, the issue isn't about this specific battle, this specific battle is just a test; I don't want this issue to come up in my game.
I don't have any suggestions to help with your issue, but I do want to point out that your code is unnecessarily long and complex.

If you are going to adjust the attacker's and target's TP and return the damage value under every one of those conditions, you don't need to put it IN each condition - just put it right at the end.

Turn this:

Code:
def custom_formula_normalatk(a, B)   value = (a.atk - b.def) + rand(5)  c = (a.mat - b.mat)  d = (b.agi + b.luk)    if c > 14 and c > d      if b.state?(68)      a.tp -= 10      b.tp += 10      return value      else      b.add_state (68)      a.tp -= 10      b.tp += 10      return value      end    else      a.tp -= 10      b.tp += 10      return value    endend
into this:
Code:
def custom_formula_normalatk(a, B)   value = (a.atk - b.def) + rand(5)  c = (a.mat - b.mat)  d = (b.agi + b.luk)  b.add_state(68) if c > 14 and c > d and !b.state?(68)  a.tp -= 10  b.tp += 10  return valueend
Ahhh, thanks Shaz.

Original thread: https://forums.rpgmakerweb.com/threads/strange-problem-actor-gets-effectively-stun-locked-on-turn-5.37022/