Reset CD + Extra turn if skill kills enemy

Im using Yanfly STB, so action + doesnt work.
Basically I have a skill with a long CD and intended as finisher, a skill that if it kills an enemy you get another turn and potential refreshes CD or lowers it by 6 turns.

I figure if I can have conditions to make it an instant cast assuming it kills then it would enable an extra turn.

I tried a few things like instant cast
<Instant Eval>
if (target.hp <= 0) {
instant = true;
}
</Instant Eval>
<Cooldown Eval> and <Post-Damage Eval>, none give me the desired effect of instant cast or extra turn and I cant even get the CD reduction on kill either.
I can only guess at the moment but it might be that the target is already removed as a battler before your instant eval happens. and if the target no longer exists that condition on target HP will always be false.

It's the same with regular troop events in troop battles where you need to trick the engine with an immortal state to have the troop event run on HP=0 for the last battler, because otherwise the battle would end before the troop event.

How about you try this:
make a calculation if the expected damage is higher than the remaining h of the target before processing the damage, and then apply the effects you want. If there is a timing problem with that, turn on a switch if the damage is higher and have the post-damage eval react to that switch.
The problem is that instant casting is checked before the skill is done. So if it only dies during the skill is was already not instant.
The only option I can think of right now is Andar's suggestion of a prediction, then if the prediction fails and the target survives you do something for the battler to lose the turn they would have won.
How would I check to see potential damage before its done? Would it factor in buffs and increases in damage?
Try with value instead of 0 as in it.
If you have damage Core, value refers to damage. It could be an alternative.
<Instant Eval>
if (target.hp <= value) {
instant = true;
}
</Instant Eval>
Try with value instead of 0 as in it.
If you have damage Core, value refers to damage. It could be an alternative.
<Instant Eval>
if (target.hp <= value) {
instant = true;
}
</Instant Eval>

ReferenceError: target is not defined
Also does not work

Edit: If I try this it says value not defined. I dont know the code to check your damage lol
Code:
<Before Eval>
if (target.hp <= value) {
cooldown = 1;
instant = true;
}
</Before Eval>
<Instant Eval>
if (value>=target.hp)
instant = true
</Instant Eval>

This should work for the free turn, I use it for my thief in my game.

EDIT : Add also this for lowering by 6 the CD in case of a fatal strike (not sure if you need the brackets or no in this formulation)

<Cooldown Eval>
if (value>=target.hp){
cooldown += -6;
}
</Cooldown Eval>
<Instant Eval>
if (value>=target.hp)
instant = true
</Instant Eval>

This should work for the free turn, I use it for my thief in my game.

EDIT : Add also this for lowering by 6 the CD in case of a fatal strike (not sure if you need the brackets or no in this formulation)

<Cooldown Eval>
if (value>=target.hp){
cooldown += -6;
}
</Cooldown Eval>

The instant doesnt work and returns this error, tried it with {} and instant = true;
ReferenceError: value is not defined
Same for Cooldown, says same error
Instant is calculated before the skill is even selected, as far as I remember. So it doesn't have a target yet to check for.
And before eval would be run before the skill is started, much less damage is calculated, so it also doesn't have a value yet.

So yeah, thought of my idea better.
Make the skill always be instant,
create a state that lasts only until the end of the turn and doesn't let you act, I'll use the number 32 as an example,
and put this post-damage eval:

<Post-Damage Eval>
if (target.hp > 0) {
user.addState(32);
}
</Post-Damage Eval>

this should add the state to the user if the enemy survives, negating their next action and thus making it not seem to be instant.
Instant is calculated before the skill is even selected, as far as I remember. So it doesn't have a target yet to check for.
And before eval would be run before the skill is started, much less damage is calculated, so it also doesn't have a value yet.

So yeah, thought of my idea better.
Make the skill always be instant,
create a state that lasts only until the end of the turn and doesn't let you act, I'll use the number 32 as an example,
and put this post-damage eval:

<Post-Damage Eval>
if (target.hp > 0) {
user.addState(32);
}
</Post-Damage Eval>

this should add the state to the user if the enemy survives, negating their next action and thus making it not seem to be instant.

Yep thanks! It works!
Any idea how to include the CD into it?
ah right, forgot about that. lowers cooldown of all skills by 6, right?

Code:
<Post-Damage Eval>
if (target.hp > 0) {
  user.addState(32);
} else {
  for (var i = 0; i < user.skills().length; ++i) {
    var skill = user.skills()[i];
    if (user.cooldown(skill.id) > 0) {
      user.setCooldown(skill.id, Math.max(user.cooldown(skill.id)-6,0));
    }
  }
}
</Post-Damage Eval>

Sorry, had to edit. wasn't n a code block so suddenly there was a part missing and a bunch of italic
ah right, forgot about that. lowers cooldown of all skills by 6, right?

Code:
<Post-Damage Eval>
if (target.hp > 0) {
  user.addState(32);
} else {
  for (var i = 0; i < user.skills().length; ++i) {
    var skill = user.skills()[i];
    if (user.cooldown(skill.id) > 0) {
      user.setCooldown(skill.id, Math.max(user.cooldown(skill.id)-6,0));
    }
  }
}
</Post-Damage Eval>

Sorry, had to edit. wasn't n a code block so suddenly there was a part missing and a bunch of italic

Actually it's just for that skill not all skills, it refreshes the finisher...for learning purposes
What does for (var i = 0; i < user.skills().length; ++i) { mean?
it makes the code inside the {} block look for as long as the second condition is met. the first is done before the first run and the last is done after every run. so in this before it starts va i = 0; at every loop ++i meaning it has 1 added to i, and it goes until i is not smaller than the skills the user has anymore.

So, I'll use 120 there as the skill's id. There may be a way to get the skill's ide through code so you don't need toput it by hand, but not able to look right now.
Your code would end up as

<Post-Damage Eval>
if (target.hp > 0) {
user.addState(32);
} else {
user.setCooldown(120, Math.max(user.cooldown(120)-6,0));
}
</Post-Damage Eval>
it makes the code inside the {} block look for as long as the second condition is met. the first is done before the first run and the last is done after every run. so in this before it starts va i = 0; at every loop ++i meaning it has 1 added to i, and it goes until i is not smaller than the skills the user has anymore.

So, I'll use 120 there as the skill's id. There may be a way to get the skill's ide through code so you don't need toput it by hand, but not able to look right now.
Your code would end up as

<Post-Damage Eval>
if (target.hp > 0) {
user.addState(32);
} else {
user.setCooldown(120, Math.max(user.cooldown(120)-6,0));
}
</Post-Damage Eval>

OMG It works you make it look so simple! Thank you!!!
I wont pretend I understood all that but I think I got enough of the code with ++i, im picking stuff up slowly.
Keep in mind that if the enemy survive and if your actor is affected by a state that trigger at Action End, then the state will be trigger twice.
Per example, if the actor is affected by a poison state that deal 100 damage at the end of the action. If actor use this skill and if the enemy survive, then the actor will get -200 damage by poison instead of 100 as expected. Also, state turn will be decrease by 2 instead of 1.
Hope for you that most of your states trigger at Turn End.


Best,

Lay.
Keep in mind that if the enemy survive and if your actor is affected by a state that trigger at Action End, then the state will be trigger twice.
Per example, if the actor is affected by a poison state that deal 100 damage at the end of the action. If actor use this skill and if the enemy survive, then the actor will get -200 damage by poison instead of 100 as expected. Also, state turn will be decrease by 2 instead of 1.
Hope for you that most of your states trigger at Turn End.


Best,

Lay.

Right so if your saying if I have enemies which have an ability that once per battle lethal damage instead reduces to 1HP, this would consider it as being dead and I would get the bonus. All my states are turn end that deal with restriction of action or it will never expire lol.
Right so if your saying if I have enemies which have an ability that once per battle lethal damage instead reduces to 1HP, this would consider it as being dead and I would get the bonus. All my states are turn end that deal with restriction of action or it will never expire lol.

Didn't understand what you said...
I will give a concrete example below :
  • Player use your "finishing skill " on an enemy that has 1000 hp
  • Skill deal 500 hp as damage, enemy has now 500 hp
  • During post damage eval, because target.hp > 0, condition is met. Thus, the user get the inability effect with (user.addState(32)).
  • It is now the end of the actor Action. All state that trigger something during Action End do their job (poison, regeneration, etc...).
  • Because the "finishing skill" is set to <Instant Cast>, the actor instantly start a new Action.
  • Inability effect disable the selection of any action and things appear to be nothing from the player point of view, making the action a kind of "ghost" action.
  • However, even if it's ghost, it is still now the end of the actor "ghost" Action. All state that trigger something during Action End do their job.
Thus, states trigger twice, regardless of the hp the target has lost.
@Lay last I checked, not if you use yanfly's Battle Engine Core.
Which in this case is being used since STB needs it.

I remember complaining to yanfly once on his <forbiden site's name>, when it was still developing plugins, that if I was using it and put a state as Action End, and it was set to not let you act, the state would never lose a turn count and you'd stay frozen forever (thus why I said to use a turn end state to remove the extra action instead of action end).
Yanfly said it was intentional, since it would make no sense to do anything on action end, including lower turn count, if you were not able to do an action, and so I would have to do a turn end instead.
I disagree with the idea, or think the developer should at least be able to set a state to do such things even if the action was lost, but it is useful here.
@YoraeRasante Ho okay I didn't know that.
I probably have a plugin conflict somewhere. It requires a deeper investigation !!

Thanks,

Lay.
@Lay last I checked, not if you use yanfly's Battle Engine Core.
Which in this case is being used since STB needs it.

I remember complaining to yanfly once on his <forbiden site's name>, when it was still developing plugins, that if I was using it and put a state as Action End, and it was set to not let you act, the state would never lose a turn count and you'd stay frozen forever (thus why I said to use a turn end state to remove the extra action instead of action end).
Yanfly said it was intentional, since it would make no sense to do anything on action end, including lower turn count, if you were not able to do an action, and so I would have to do a turn end instead.
I disagree with the idea, or think the developer should at least be able to set a state to do such things even if the action was lost, but it is useful here.

Hey Yorae, I was wondering how to modify the notes to have a range of skills go off cooldown. I want to make a state that when you crit, lowers the cooldown of all Ice spells by 1. Also to prevent abuse, it goes on a timer for 3 rounds.
I based it off of Yanfly BubbleWrap tips and tricks

So learn this skill, applies passive state:
Code:
<Custom Battle Effect>
// Get the state ID for the bubble wrap effect state
var icecdresetID = 70;
// Add that state to the user
user.addState(icecdresetID);
// Set the cooldown to 0
user._reseticeCooldown = 0;
</Custom Battle Effect>

<Custom Regenerate Effect>
// Default the  cooldown to 0
user.reseticeCooldown = user.reseticeCooldown || 0;
// Check if the cooldown is above 0
if (user.reseticeCooldown > 0) {
  // Decrease the cooldown by 1
  user.reseticeCooldown -= 1;
  // Check if the cooldown has reached 0 or less
  if (user.reseticeCooldown <= 0) {
    // Get the state ID for the bubble wrap effect state
    var icecdresetID = 70;
    // Play an animation on the user
    user.startAnimation(82);
    // Add the state to the user
    user.addState(icecdresetID);
  }
}
</Custom Regenerate Effect>

Then the State where crits lower CD

Code:
<Custom Establish Effect>
var iceskills = [76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99]
if (target && target.result().hpDamage > 0 && target.result().critical) {
user.setCooldown(iceskills.id, Math.max(user.cooldown(iceskills.id)-1,0));
  // Remove the icecdreset state from the target
  target.removeState(70);
}
</Custom Establish Effect>

<Custom Remove Effect>
// Set the reseticeCooldown to 3 turns
user.reseticeCooldown = 3;
</Custom Remove Effect>

It does not work, is there a way to check all the ids in the box?

Original thread: https://forums.rpgmakerweb.com/threads/reset-cd-extra-turn-if-skill-kills-enemy.120625/