MV Number of Hits based on Target's TP

My battle system uses TP (reffered to in-game as SP) for skill cost. A character's Max TP is 3.

I'm working a boss ability that involves the boss grabbing one of the characters, and on the next turn "detonating" that character's TP, hitting once for each point of TP they have.

I've gotten pretty far already:

Screenshot (452).png

Spoiler: Action Sequences:
Code:
<target action>
perform action
motion wait: user
if BattleManager._targets[0].tp > 0
        EVAL:  BattleManager._logWindow.addText("\\c[\\v[6]]\\n[" + BattleManager._targets[0].actorId() + "]\\c[0]'s \\c[\\v[5]]SP\\c[0] detonates.");
        action animation
        wait for animation
        TP -1: target
        action effect
    if BattleManager._targets[0].tp > 0
            action animation
            wait for animation
            TP -1: target
            action effect
        if BattleManager._targets[0].tp > 0
                action animation
                wait for animation
                TP -1: target
                action effect
        end
    end
remove state 21: target
else
eval:        BattleManager._logWindow.push('wait');
eval:        BattleManager._logWindow.push('wait');
    action common event
death break
</target action>

<finish action>
immortal: targets, false
wait for new line
clear battle log
perform finish
wait for movement
wait for effect
</finish action>

Screenshot (451).png


Things work as intended when the character has 0 TP or 2 TP

With 2TP, the animation plays twice in a row and then the two battle log messages with respective damage sound effect and screenshake appear, as intended.
With 3TP however, it shows like this:

Animation
Animation
Damage Feedback
Animation
Damage Feedback
Damage Feedback

Causing the effect to be muddled.

I suspected it had something to do with the yanfly double hit issue, so I disabled the plugin I use for that, but the default Battle Core was even more chaotic. *

The other major issue I have is when the character is at 1 TP, it still activates the common event for when they have 0 TP. This has me pretty perplexed, because I've never seen an if statement that executes both the if AND else, and I have no idea why that would happen at 1 TP, but not 2 or 3 TP.


* I don't use Turan's snippet since it plays the damage sound once before the battlelog messages, and I find for mechanical feedback and gamefeel purposes it's much better to have the hit effect accompany each battle log message reporting the damage.
It's a work in progress, I still get doubling from Scope: X random enemies and Substitute but here's what I got for reference:

Spoiler: YanflyDouble_Fix.js
Code:
Game_Battler.prototype.performResultEffects = function() {
    var result = this.result();
    if (result.missed && result.physical) this.performMiss();
    if (result.evaded) {
      if (result.physical) {
        this.performEvasion();
      } else {
        this.performMagicEvasion();
      }
    }
    if (result.hpAffected) {
    }
    if (this.isAlive() && result.mpDamage !== 0 && result.mpDamage < 0) {
      this.performRecovery();
    }
    if (this.isAlive() && result.tpDamage !== 0 && result.tpDamage < 0) {
      this.performRecovery();
    }
};

Edit: For the sake of thoroughness, I've also tried an implementation using Scope Extend. The help file says javascript expressions can be used, but my attempts did not execute.
Code:
<SERandomNum: BattleManager._targets[0].tp>
Not sure why your conditions are nested, and you're also missing a closing "end" there. But generally you could just
Code:
if target.tp > 0
    action animation
    action effect
    tp -1: target
end
if target.tp > 0
    action animation
    action effect
    tp -1: target
end
if target.tp > 0
    action animation
    action effect
    tp -1: target
end
Not sure why your conditions are nested, and you're also missing a closing "end" there. But generally you could just
Yeah, what 'e said!


but also...
With 2TP, the animation plays twice in a row and then the two battle log messages with respective damage sound effect and screenshake appear, as intended.
With 3TP however, it shows like this:
IIRC, yanfly's AS conditional statements dont function when nested. You'd need Serge's extension to fix that if you dont already have it

I suspected it had something to do with the yanfly double hit issue, so I disabled the plugin I use for that, but the default Battle Core was even more chaotic. *
Im not familiar with a double hit issue with yanfly's plugins when in the right order. got any additional details?

The other major issue I have is when the character is at 1 TP, it still activates the common event for when they have 0 TP. This has me pretty perplexed, because I've never seen an if statement that executes both the if AND else, and I have no idea why that would happen at 1 TP, but not 2 or 3 TP.
common events are usually not ran immediately when called. theyre reserved and run at the soonest available time for them to run. it can cause weird stuff when timing is important. Im not sure if the AS command for it is different in that regard

But that aside, why use a common event? you did 90% of the effect in the one AS. you could have set up a condition at the start to check if the target has no TP, used the same code in the CE in the AS, and then had the rest of the skill play as an else branch for not having TP.
Not sure why your conditions are nested, and you're also missing a closing "end" there. But generally you could just
Originally I thought it was going need to be nested at least once to accomodate the 0 TP condition as well, but with your two's suggestion I was able to restructure in a way that there's no nested statements anymore.
This has solved the 1 TP issue, the 3 TP issue still stands.
Spoiler: Current Version
Code:
<target action>
perform action
motion wait: user
if BattleManager._targets[0].tp == 0
eval:        BattleManager._logWindow.push('wait');
eval:        BattleManager._logWindow.push('wait');
    action common event
end
if BattleManager._targets[0].tp > 0
    EVAL:  BattleManager._logWindow.addText("\\c[\\v[6]]\\n[" + BattleManager._targets[0].actorId() + "]\\c[0]'s \\c[\\v[5]]SP\\c[0] detonates.");
    action animation
    wait for animation
    TP -1: target
    action effect
end
if BattleManager._targets[0].tp > 0
    action animation
    wait for animation
    TP -1: target
    action effect
end
if BattleManager._targets[0].tp > 0
                action animation
                wait for animation
                TP -1: target
                action effect
end

remove state 21: target
death break
</target action>

<finish action>
immortal: targets, false
wait for new line
clear battle log
perform finish
wait for movement
wait for effect
</finish action>
I did miss the last end originally, I probably deleted it when I switched the original else from AS to the Common event (I'll get into it), but it doesn't seem to have affect the execution after it was fixed.

You'd need Sergeo's extension to fix that if you dont already have it
I don't think I'm familiar with this one. Do you have a link to it or at the very least the exact name of the plugin?

Im not familiar with a double hit issue with yanfly's plugins when in the right order. got any additional details?
I far as I understand it, in the vanilla engine the "damage" effect accompanies the battle log damage message. Yanfly removes a lot of the battle log messages by default, so the "damage effect" is reinserted after the animation. You can toggle most of the removed battle log options back on, but the extra damage effect inserted separately is frequently not, resulting in each attack from a Scope: All or Scope: X Random skill to play the damage effect twice on each hit, except for the last one I think. With my own settings I've noticed this happens with Substitute as well if you toggle Show Substitute Text back on.

common events are usually not ran immediately when called. theyre reserved and run at the soonest available time for them to run. it can cause weird stuff when timing is important. Im not sure if the AS command for it is different in that regard
This one I'm familiar with. I kinda use it deliberately here to have the common effect only play at the end in the 0TP case.

But that aside, why use a common event? you did 90% of the effect in the one AS. you could have set up a condition at the start to check if the target has no TP, used the same code in the CE in the AS, and then had the rest of the skill play for not having TP.
I had originally done the 0 TP condition with AS as well, I think where my issue came in was removing the "Constrain (21)" condition using AS. At first I was using the Remove State trait, but that wouldn't execute at 0 TP and caused a stutter in between the first TP "Detonation" and any later ones.
I then tried remove state 21: target, show, since that's pretty important gameplay feedback I want the player to have, but the issue there is it seemed to print all of the effects to the battle log, not just the state change, meaning a phantom extra "x took y damage" also came up.

At that point I was fed up, removed the show and just switched it to a common event where I knew I could get more predicable behaviour. And also could put everything in a single Script command instead of stringing a bunch of single Eval: lines together.
I don't think I'm familiar with this one. Do you have a link to it or at the very least the exact name of the plugin?
each attack from a Scope: All or Scope: X Random skill to play the damage effect twice on each hit, except for the last one I think. With my own settings I've noticed this happens with Substitute as well if you toggle Show Substitute Text back on.
ah, yes. i see now. when the show hp parameter is on it does run performDamage from the function you altered and from the window later. Im used to not having it on, but yeah, i can hear performDamage going off twice regardless of scope with it. between the two points, i probably would have gone for that function first too.

I had originally done the 0 TP condition with AS as well, I think where my issue came in was removing the "Constrain (21)" condition using AS. At first I was using the Remove State trait, but that wouldn't execute at 0 TP and caused a stutter in between the first TP "Detonation" and any later ones.
i think that depends on how you had it set up? i cant really say anything with any certainty without seeing what you had prior.

I then tried remove state 21: target, show, since that's pretty important gameplay feedback I want the player to have, but the issue there is it seemed to print all of the effects to the battle log, not just the state change, meaning a phantom extra "x took y damage" also came up.
did you try using the AS#1 command to clear the log before running the command to remove the state?

EDIT:

This has solved the 1 TP issue, the 3 TP issue still stands.
it does appear to be a consequence of your plugin on my end. I can replicate your issue with your AS, but not with the plugin disabled. Without it, the animations play as they should both with the show hp parameter on and off (but you still get the double popup with it on)
did you try using the AS#1 command to clear the log before running the command to remove the state?
I gave it a shot:
Code:
CLEAR BATTLE LOG
remove state 21: target, show
The extra damage battlelog still happens, I suspect it might also have something to do with not expecting people to use the parameter "show action/hp text" whichever it is.
It also breaks up the effect across two pages which isn't ideal. It might help if I get to the bottom of this one, but in the mean time supplementing with javascript messages works.

Original thread: https://forums.rpgmakerweb.com/threads/number-of-hits-based-on-targets-tp.183978/