MV Need help with executing code at the end of skill!

Hi, I'm using yanfly's battle engine core, action sequence 1, and battle system STB
Basically what I want to do is recreate Seele's passive ability from honkai star rail: when she defeats an enemy she immediately acts again, but this only happens once per turn.

What i've been doing is, using actseqpack1, use the eval: code thing in a skill's note section, but my coding experience is 0 so I'm pretty limited in what I can do alone.
The code in question would add a state to the user with only a "Action times + 100%" trait, and lasts until they act again.

-----

Examples of what I've tried:

<finish action>
eval: if (target.hp < 0)
ADD STATE 17: target, (show)
end
</finish action>


<finish action>
eval: if (target.isDead()) {
user.addState(17);
user.refresh();
}
</finish action>


<finish action>
eval: if (target.isDead()) { action.user().increaseActions(); }
}
</finish action>

-----

in either of these cases what ends up happening is: instead of giving state 17 to the user if the enemy dies after the attack, it removes the knockout state from the enemy (i think) and it stays alive

I'm lost, any help?
Well in your first example you add state 17 to the target, not the user, so that would obviously not work.

I'm also wondering what your complete action sequence looks like, because maybe you did some copy paste mumbo jumbo and your <setup action> may just have a immortal: targets, true which you don't seem to remove here, so the enemy doesn't die, therefore it's not dead, therefore not applying the state because the condition isdead ain't true.
Well in your first example you add state 17 to the target, not the user, so that would obviously not work.

I'm also wondering what your complete action sequence looks like, because maybe you did some copy paste mumbo jumbo and your <setup action> may just have a immortal: targets, true which you don't seem to remove here, so the enemy doesn't die, therefore it's not dead, therefore not applying the state because the condition isdead ain't true.
Hi, i asked chat gpt for some help but unsurprisingly it didnt work lmao, thats where the code comes from.

About the setup action, i dont have anything else on the skill's note section apart from what i showed here. After your suggestion I made this:

<finish action>
eval: if (target.isDead()) {
user.addState(17);
user.refresh();
}
immortal: targets, false
</finish action>

Now the target dies normally but the actor doesn't get the state 17 or gain another turn.

Maybe the problem is that I can't write the eval: code in more than one line? What should I write in that case? Tks
Ok I tried:

<finish action>
eval: if (target.isDead()) { user.addState(17); user.refresh(); }
immortal: targets, false
</finish action>

and

<finish action>
eval: if (target.isDead()) { action.user().increaseActions(); }
immortal: targets, false
</finish action>

Still same effect as last post

I'm testing everything with DTB and STB btw, but I want to use STB for the game.
(Default Turn Battle, Standard Turn Battle)
If anything, you'll need to put immortal: target, false before the if statement. There's no point in making the target mortal after you checked if it's dead. I'm also not sure if a sole finish action even works since the proper setup has:
<setup action>
</setup action>
<target action>
</target action>
and only then comes the finish action.

It could also be that this way of doing it would just not work due to the target being removed from the array upon death. Not too sure about that one.

You can try something like calling a common event that shows a dialogue box.

if target.isDead()
common event: x

put some dialogue in the common event to check if it even runs.
@El_Palito45 , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.
If anything, you'll need to put immortal: target, false before the if statement. There's no point in making the target mortal after you checked if it's dead. I'm also not sure if a sole finish action even works since the proper setup has:
<setup action>
</setup action>
<target action>
</target action>
and only then comes the finish action.

It could also be that this way of doing it would just not work due to the target being removed from the array upon death. Not too sure about that one.

You can try something like calling a common event that shows a dialogue box.

if target.isDead()
common event: x

put some dialogue in the common event to check if it even runs.
Ayy there's been some progress!

After your help and using chat gpt some more I managed to almost get the exact effect I wanted:
If an attack defeats an enemy then the user immediately gains another turn, but this can only work once per turn (meaning the user can only get 2 turn at a time).
This part is working perfectly.

Also, I ended up not using any states for this.
I've tested this with DTB and STB and it works only on STB, which is what I want!

There's just one last thing: I want to play common event 6 between the first and the additional turn, but no matter what I've tried it always plays the common event at the end of the additional turn.

-----

This is the code I have so far:

<setup action>
immortal: targets, true
perform start
</setup action>

<finish action>
immortal: targets, false
eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); $gameTemp.reserveCommonEvent(6); BattleManager.processTurn(); }
</finish action>

-----

The eval code is only on one line, it just looks like multiple ones here tho
"In between" is probably not possible. But if you put it at the end of the sequence... just like you did now now but instead of putting some code just use common event: x.

This should maybe call the CE before you get another turn. Not sure.
"In between" is probably not possible. But if you put it at the end of the sequence... just like you did now now but instead of putting some code just use common event: x.

This should maybe call the CE before you get another turn. Not sure.
Just tried this, what happens is: because that command is not linked to the eval: code it always happens, even if the "if" condition isn't triggered. Also if the condition is triggered, that command plays after the additional turn, so it's no good.

Not sure what to do now.
Yeah, if you put the common event call after your if condition, it's gonna trigger after your extra turn. Put it inside your if condition, whenever it's supposed to happen, but before your extra action code.

<finish action>
immortal: targets, false
eval: if (target.isDead()) { BattleManager.forceAction(user);
common event: x BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
</finish action>
i asked chat gpt for some help
For the record, please don't do this. It's not a forum rule, but it's pretty much been agreed upon by most folks here that if you ask ChatGPT to program for you, then you are on your own.

This is not some anti-Ai movement we have, it's just that troubleshooting the garbage it spits out is not worth the hassle when folks are helping you for free. Why give free laborers even more work?

There are, however, some folks who have a negative sentiment around AI based tools, so my advice for the future is if you are struggling with programming something, just say, "Hey, I tried to do something, I can't get it to work, can I get some help?" And maybe avoid using the "CPT" name so it doesn't trigger some of the folks into not wanting to help you.

That all said, I do want to say that I appreciate you being honest about the source of your code.
Thankfully @SGHarlekin is a pretty good guy and doesn't care if you started with garbled code spat out by our dumb but omniscience AI overlords. And keep that in mind to, as a user of ChatGPT, it may spit out things that sound smart, but it's ultimately pretty dumb. A useful tool, but not an intelligence replacement.
Yeah, if you put the common event call after your if condition, it's gonna trigger after your extra turn. Put it inside your if condition, whenever it's supposed to happen, but before your extra action code.

<finish action>
immortal: targets, false
eval: if (target.isDead()) { BattleManager.forceAction(user);
common event: x BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
</finish action>
"common event: x" or "common event: 6" isn't a command that can be used in a line of code, it's a command for the yanfly plugins, so putting it in the middle of the code breaks it.
That's why I was using "$gameTemp.reserveCommonEvent(6)", I assume that is the command that calls the common event 6, but it always executes it after the additional turn no matter in what part of the code I put it in.

Also @TheAM-Dol I appreciate the tip, I just wanted to make sure to try everything I could before asking for help.
"common event: x" or "common event: 6" isn't a command that can be used in a line of code, it's a command for the yanfly plugins, so putting it in the middle of the code breaks it.
That's why I was using "$gameTemp.reserveCommonEvent(6)", I assume that is the command that calls the common event 6, but it always executes it after the additional turn no matter in what part of the code I put it in.

Also @TheAM-Dol I appreciate the tip, I just wanted to make sure to try everything I could before asking for help.
Yeah but I mean you could put it in between 2 evals. Well either way if that's also not working, the only thing we can assume is that your code ain't working, or that reserving the common event only calls it at another time and not immediatly. Maybe someone with more js knowledge will be able to help here, because I don't know much about it either.
Maybe this could work instead?

eval: if (target.isDead()) {
eval: $gameTemp.reserveCommonEvent(6);
eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
Maybe this could work instead?

eval: if (target.isDead()) {
eval: $gameTemp.reserveCommonEvent(6);
eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
sorry for the delayed response, there's been some progress!

I hadn't thought of putting the comands in different evals, now its closer to what I wanted!

-----

I only made a small ajustment to your code but here it is


eval: if (target.isDead()) { $gameTemp.reserveCommonEvent(6); }

eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }

Now theres just one small problem, the common event plays every time the condition is triggered, unlike the rest that is triggered only once per turn, which is what I want for the common event as well.

I tried putting "BattleManager._subject.removeCurrentAction();" after "BattleManager.forceAction(user);" but what happens is the common event plays but not the rest, so it just skips to the next character's turn. I also tried putting "BattleManager.processTurn();" after that as well, but that just breaks the code.

What should I do?

Also no problem @SGHarlekin, tysm for your help!
sorry for the delayed response, there's been some progress!

I hadn't thought of putting the comands in different evals, now its closer to what I wanted!

-----

I only made a small ajustment to your code but here it is


eval: if (target.isDead()) { $gameTemp.reserveCommonEvent(6); }

eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }

Now theres just one small problem, the common event plays every time the condition is triggered, unlike the rest that is triggered only once per turn, which is what I want for the common event as well.

I tried putting "BattleManager._subject.removeCurrentAction();" after "BattleManager.forceAction(user);" but what happens is the common event plays but not the rest, so it just skips to the next character's turn. I also tried putting "BattleManager.processTurn();" after that as well, but that just breaks the code.

What should I do?

Also no problem @SGHarlekin, tysm for your help!
You could use a 1 turn state to determine if the Common Event is play or skipped.

Like this


if !user.isStateAffected(ID) && target.isDead()


eval: $gameTemp.reserveCommonEvent(6);

add state ID: user

eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }

else

eval: BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
You could use a 1 turn state to determine if the Common Event is play or skipped.

Like this


if !user.isStateAffected(ID) && target.isDead()


eval: $gameTemp.reserveCommonEvent(6);

add state ID: user

eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }

else

eval: BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
IT'S DONE!

Tysm, after changing your code a bit it now works perfectly!

-----

This is the final result:

<setup action>
immortal: targets, true
perform start
</setup action>

<finish action>
immortal: targets, false
eval: if (!user.isStateAffected(17) && target.isDead()) { $gameTemp.reserveCommonEvent(6); }

add state 17: user

eval: if (target.isDead()) { BattleManager.forceAction(user); BattleManager.inputtingAction().setTarget(target); BattleManager._subject.removeCurrentAction(); BattleManager.processTurn(); }
</finish action>

-----

State 17 is used to check if the game should play common event 6, if the skill's user doesn't have it then it won't play and skip to the next part of the code.

Should I post a video showing the result in-game?

Original thread: https://forums.rpgmakerweb.com/threads/need-help-with-executing-code-at-the-end-of-skill.158720/