Unleashing a skill that kills enemy with hp <= 2000

Hi everyone,
I was trying to make a passive state that allowed the user to unleash a skill that had a 20% probability of instantly killing the target if said target had less than 2000 hp.

I tried to use the Weapon Unleash plugin by Yanfly.

JavaScript:
<Custom Weapon Unleash: x>
    if (target.hp < 2000) {
        rate = 0.2;
    } else {
        rate = 0;
    }
</Custom Weapon Unleash: x>

However, using this code, nothing happens.
I guess it's because of the target variable, but I don't know how to make it equal to the chosen target.
How do I store the target Id so I can use it in this code?

Thanks in advance!
is the skill intended to either kill the target at 2000 or less, or do nothing to the target otherwise?
If the target has more than 2000 HP (or the weapon unleash doesn't occur, since it has a 20% chance of happening),
the user will perform a normal attack.
<Pre-Damage Eval>
var rr = Math.floor(Math.random() * 5);
if(target.hp<=2000){
if(rr<=2){
target.addState(1);
}
}
</Pre-Damage Eval>

so this should work with YEP... crap, i forget what the actual name of the plugin, but i'm sure it has to do with battlecore stuff. i kinda copy pasted part of this from elsewhere to be an "add up to 3 states thing", but changing the math to a 5 and the less than to 20% should make that a 20% chance to kill something if it's hp is 2000 or less.

i may need to re-test that math.random() part, now that i look at it, it doesn't seem quite right :|

OR....

you might try using </custom weapon unleash> as the end of what you have. try something like that too.


also, oh, i think i misread the part about it being a state that lets you do this, i could be WAY off on everything.

ok, now i think i understand everything about what you're asking lol. it's a state like 'near death' that has a 20% chance of the user using a skill that kills the target of the attack. yes?

wait, no, it's literally just a 20% chance to kill a target with 2000 or less HP. god i'm confusing myself more and more lol
This is one of the few yanfly plugins I didn't use myself just yet, but I know this is not good:
Code:
<Custom Weapon Unleash: x>

The X stands for something. You need to replace that with... Well, I don't know with what. I'd have to look it up, but it should be in the help section of the plugin.

Hopefully pointing out where the error is, is already helpful. If you still can't find it, then let me know. I'll dig into the plugin to see what should be on the X for this.
This is one of the few yanfly plugins I didn't use myself just yet, but I know this is not good:
Code:
<Custom Weapon Unleash: x>

The X stands for something. You need to replace that with... Well, I don't know with what. I'd have to look it up, but it should be in the help section of the plugin.

Hopefully pointing out where the error is, is already helpful. If you still can't find it, then let me know. I'll dig into the plugin to see what should be on the X for this.
x should be either skill number or skill name. in what he's got, i'm more worried about not ending it appropriately with the </...> part. i'm also still looking through my states to see if i have one that approximates this.

additionally, you may need the states core and use this...

<Custom Action Start Effect>
code
code
</Custom Action Start Effect>
This effect will run at the start of each of the battler's actions. The
code will process before the skill/item cost takes place.

possibly

<Custom Initiate Effect>
code
code
</Custom Initiate Effect>
This effect will run when the battler selects a target. This will occur
before hit/miss/evade confirmation and damage execution. This effect will
run before everything else has taken course.

should have mentioned this requires buffs and states core.
This is one of the few yanfly plugins I didn't use myself just yet, but I know this is not good:
Code:
<Custom Weapon Unleash: x>

The X stands for something. You need to replace that with... Well, I don't know with what. I'd have to look it up, but it should be in the help section of the plugin.

Hopefully pointing out where the error is, is already helpful. If you still can't find it, then let me know. I'll dig into the plugin to see what should be on the X for this.
x should be either skill number or skill name. in what he's got, i'm more worried about not ending it appropriately with the </...> part. i'm also still looking through my states to see if i have one that approximates this.
Oh, I modified those parts when I posted the code here.
But in the original code I replaced the x with the number of the skill I wanted to unleash and I ended the code with the </...> part as well.
Oh, I modified those parts when I posted the code here.
But in the original code I replaced the x with the number of the skill I wanted to unleash and I ended the code with the </...> part as well.
Okay... So if I understand it right, this might cast another skill when the target HP is under 2k?

Then if the tag is all fine... (including the </ and with the right skill ID...) Did you check the skill it needs to unleas? If this skill also has 20% chance to kill, it will be 20% of 20% which is only 4%.
not sure if my edit showed lol so i will repost if missed.

additionally, you may need the states core and use this...

<Custom Action Start Effect>
code
code
</Custom Action Start Effect>
This effect will run at the start of each of the battler's actions. The
code will process before the skill/item cost takes place.

possibly

<Custom Initiate Effect>
code
code
</Custom Initiate Effect>
This effect will run when the battler selects a target. This will occur
before hit/miss/evade confirmation and damage execution. This effect will
run before everything else has taken course.
Okay...if I correctly understand the things you've said...this is way simpler than you and some others have been chasing around 🤣

In your passive state, put:
Code:
<Replace attack: X>
where X is the ID of your unleashing killing skill.

In the damage formula of that skill, put:
Code:
b.hp<2000 && Math.random()<0.2 ? 2000 : formula
where "formula" is replaced by your regular attack's damage formula.

This will cause having the passive state to replace your attack command with your unleashing skill, and when that skill hits, if the enemy's hit points are less than 2,000 it has a 20% chance to do 2,000 damage (thus killing it).

If it has higher HP, or it fails that random check, it'll do your regular damage formula. Your original approach (and the state notetags suggested by deus) won't work because there's no such thing as a target until after you've selected your skill and initiated the action, at which point you can't change which skill is being executed.
i was trying to avoid the 2k damage popup, sorry 🙁
Okay...if I correctly understand the things you've said...this is way simpler than you and some others have been chasing around 🤣

In your passive state, put:
Code:
<Replace attack: X>
where X is the ID of your unleashing killing skill.

In the damage formula of that skill, put:
Code:
b.hp<2000 && Math.random()<0.2 ? 2000 : formula
where "formula" is replaced by your regular attack's damage formula.

This will cause having the passive state to replace your attack command with your unleashing skill, and when that skill hits, if the enemy's hit points are less than 2,000 it has a 20% chance to do 2,000 damage (thus killing it).

If it has higher HP, or it fails that random check, it'll do your regular damage formula. Your original approach (and the state notetags suggested by deus) won't work because there's no such thing as a target until after you've selected your skill and initiated the action, at which point you can't change which skill is being executed.
At the end I made something similar to what you proposed, by using the Yanfly's Action Sequences.
I'm gonna post my code so other people can see the solution if they need it.

This is the base code (without all the movement and zoom effects):
Code:
<target action>
if target.hp<2000 && Math.random()<0.2
animation (insert the number of death animation): target
wait for animation
eval: $gameTemp._myFormula = target.die()
else
action animation
wait for animation
eval: $gameTemp._myFormula = user.atk * 6 - target.def
action effect
wait for effect
end
</target action>

IMPORTANT: You need to put $gameTemp._myFormula in the skill's Formula.

i was trying to avoid the 2k damage popup, sorry 🙁
By using the code "target.die()" the 2k damage popup won't show.

Thank you everyone for helping me solving this problem!
Have a great day!

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

Original thread: https://forums.rpgmakerweb.com/threads/unleashing-a-skill-that-kills-enemy-with-hp-2000.146366/