How can I increase the chance of inflicting a STATE based on the target's HP being at certain thresholds?

Ex. At <=50% health, chance to inflict state becomes 90%. At =100% health, chance to inflict state becomes 10%.

This same condition will be applied to most moves.

If no simpler method is currently widespread then I guess I can create seperate states for each of these thresholds and apply them to the actor.
Okay so I'm using states instead now and running into a JS issue using Yanfly's BuffsStates Core. When hit by an attack it deals 100 damage. Can someone enlighten me as to why this is happening? Pretty sure it's a simple code error that I am overlooking.

State note at full HP is:

<Custom React Effect>
if (value < 75) {
value = 100*target.hp/target.mhp
target.addState(198)
target.removeState(197)
}
</Custom React Effect>

State note at 75% HP is:

<Category: Bypass Recover All Removal>
<Custom React Effect>
if (value < 50) {
value = 100*target.hp/target.mhp
target.addState(199)
target.removeState(198)


and so on


State note at 25% HP (checks if HP is 0) is


<Custom React Effect>
if (value >= target.hp) {
value = target.hp - 1
target.addState(11)
target.removeState(200)
}

which was the note I've always been using until I decided to add these thresholds.


I found another solution to this using troop events but I would still like to grow my understanding by figuring this issue out.
When hit by an attack it deals 100 damage. Can someone enlighten me as to why this is happening?
You do it right here.
value = 100*target.hp/target.mhp
If the target is at full health, then hp/mhp = 1, and 100 * 1 = 100.

What did you intend for this equation to do?
You do it right here.

If the target is at full health, then hp/mhp = 1, and 100 * 1 = 100.

What did you intend for this equation to do?

My goodness, I was extremely tired.
I was just trying to grab a percentage of total health haha. 😮‍💨 Thank you
My goodness, I was extremely tired.
I was just trying to grab a percentage of total health haha. 😮‍💨 Thank you
Sure thing. It does look like these notetags have very little to do with what you described in your first post.

You start off by asking about having percent chance to apply states, then all of these notetags are changing the damage that the battler takes.

Does your troop event solution work properly, or do you need more help with this?
Sure thing. It does look like these notetags have very little to do with what you described in your first post.

You start off by asking about having percent chance to apply states, then all of these notetags are changing the damage that the battler takes.

Does your troop event solution work properly, or do you need more help with this?
My troop solution was to have an event for the battle that checks the health of each actor every turn. If that actor is below 50% it will give it the state of being below 50% and so on. However it only goes down and can't get the state that corresponds to a higher HP percentage.

I've been wasting too much time on trying to make gimmicks work so for now I've resorted back to my past battle system until I find a solution
Okay, well, if you can describe more precisely what you want to happen, we can help you do it.

I'm not certain what you're going for right now, because your title and first post read like you're trying to inflict a state on the target of an attack, and how likely it is to apply is determined by their health.

But then your last reply talked about just applying the state to all actors under a certain health threshold.

So the code is pretty simple, the effort on your part just needs to be a clear description 😉

But if it's not important to you right now, that's okay too.
So the code is pretty simple, the effort on your part just needs to be a clear description 😉

But if it's not important to you right now, that's okay too.

Aha apologies for the mess.

Alright so basically I'm trying to find a way to make the title:

How can I increase the chance of inflicting a STATE based on the target's HP being at certain thresholds?​



Ex: All attacks have a chance to instantly knock a fighter out.
At 100% health the chance to knock someone out is 0%.
At 1% health the chance to knock someone out is 99%

My initial idea was to use different states to incorporate which doesn't even make sense as a sentence and doesn't really make sense to me now.

Right now I'm thinking of somehow using the state inflict % on an attack and change the % into the percentage of the target's health but I couldn't find a plugin for that.

So whenever this attack is used, the percentage of inflicting death is (actor's health percentage).
When you say all attacks, do you mean literally any skill or damaging item might cause instant KO, or are you referring specifically to the Attack command?
Ex: All attacks have a chance to instantly knock a fighter out.
At 100% health the chance to knock someone out is 0%.
At 1% health the chance to knock someone out is 99%
None of that complicated stuff or states of anything are necessary.

You'll use Yanfly's Skill Core. In the skill, put this notetag:
Code:
<Post-Damage Eval>
if (Math.random()>=target.hpRate())
    target.addState(1);
</Post-Damage Eval>

Try that out - if the target gets the state but they don't immediately appear to die, let us know and we can add a line to account for it. But see if it works like that.
None of that complicated stuff or states of anything are necessary.

You'll use Yanfly's Skill Core. In the skill, put this notetag:
Code:
<Post-Damage Eval>
if (Math.random()>=target.hpRate())
    target.addState(1);
</Post-Damage Eval>

Try that out - if the target gets the state but they don't immediately appear to die, let us know and we can add a line to account for it. But see if it works like that.

Works perfectly thank you!

Do you mind explaining some logic behind this code such as the value range of Math.random() and value of hpRate so I can better manipulate it for certain skills (and build up my own MV JS knowledge)?

Also, I've been hesitant asking straight up advice like this as I feel like it's a bit rude to just get people to write everything for me, is this the norm? If so I have another problem related to this I need help with :LZSexcite:
Do you mind explaining some logic behind this code such as the value range of Math.random() and value of hpRate so I can better manipulate it for certain skills (and build up my own MV JS knowledge)?
The Math.random() is a default JavaScript function, so you'd find the documentation on it with a Google - but it generates a value from 0 to .9 barred.

And if you're getting into JavaScript, you could do a search for the text "hpRate" in your js folder and find it in the source code, but it's pretty much what it sounds like - it returns the rate (ratio) of the HP, so it's simply hp/mhp. Thus, a value from 0 to 1.

So, mathematically, the two things correspond to exactly what you wanted - if the target has full HP, Math.random() can't get up to 1, so there's a 0% chance of it being equal.

Also, I've been hesitant asking straight up advice like this as I feel like it's a bit rude to just get people to write everything for me, is this the norm? If so I have another problem related to this I need help with :LZSexcite:
If you start going overboard you won't find people willing to "write everything" for you 😛

But yes, it's very typical for something like a short notetag to post in Plugin Support (since you can't do it with just MV alone) and ask for help with the code.

Original thread: https://forums.rpgmakerweb.com/threads/how-can-i-increase-the-chance-of-inflicting-a-state-based-on-the-targets-hp-being-at-certain-thresholds.154999/