MV Applying a state with a precise percentage of success

Hi all ♥
I am trying to create a State that works on stacks (I followed Yanfly's "Stockpile" Tips & Tricks) and a Skill that increases its strenght based on the stack level of the state. Everything works smoothly, but I would like to set an effect that, always based on the stack level, increases the chances for that skill to apply a state on the target.

For esample.
FIRST SKILL: "Warm up"
-- Every use add 1 stack of "Warmed up" on the user
SECOND SKILL: "Fire arrow"
-- Deals damage based on the number of stack of "Warmed up" on the user (easy to do) AND has a 10% chances to BURN the Target for every "Warmed up" stack on the user (1 stack: 10%, 2 stacks: 20%, 3 stack 30% and so on). If BURN occurs, clear out every "Warmed up" stack on the user.

So basically, I am asking what is the call code for applying a state on the enemy with just a precise percentace of success, and connecting this percentage to state stack value. I am not a Js expert at all ;; so any help would be extremely appreciated. And sorry if I'm asking for something too peculiar.
Moderator note: I have split your question into its own thread and moved to Plugin Support, however I don't really know if you're actually using a plugin or not - based on your reference to Yanfly and stack levels, I'm making the assumption that you are.
Reference link:

For this example I'm assuming that:
  • user._warmth is a reference to the "Warmed Up" stacks;
  • target is a reference to the target;
  • The Burn state is state ID 123; and
  • The stackable "Warmed Up" state is state ID 456.
In that case, I think this does what you're asking (untested):
JavaScript:
var chance = 0.1 * user._warmth;
if (Math.random() < chance) {
  target.addState(123);
  user._warmth = 0;
  user.setStateCounter(456, 0);
}
Note: by default addState bypasses state rates, luck effect, etc.
EDIT: Oh my God, I can't believe it was just THAT but I completely forgot to put your code between two
Code:
<Damage Formula>
code
</Damage Formula>

And of course it is now working amazingly. THANK YOU SO MUCH ♥♥♥♥♥♥♥


EDIT 2: I just noticed: If the actor is knocked down when it has some stacks of the State (3 for example), when I re-raise it in the same battle, it doesn't seems to have the state on. But as soon as I try to stack the state again, it instantly regain the state to the same number of stack it has before dying (3 in this case). How should I change this?

@Shaz You're absolutely right, sorry. Yes, I am using many Yanfly's Plugin, and the "Buffs & States Core" in particular for this precise case.

@caethyril Thank you SO MUCH for your answer! I think I am so bad at this that it seems I can't quite figure it out anyway ç_ç I used your example, compiling as such:

Code:
var chance = 0.1 * user._stockpile;
if (Math.random() < chance) {
  target.addState(18);
  user._stockpile = 0;
  user.setStateCounter(17, 0);
}

I was still using the "Stockpile" original code, for my various guesses, that's why I was using "user._stockpile". Under "target.addState" i put 18 since it's the ID of my "Burned" Status.
And as for the "user.setStateCounter" I put 17, since that's my "Warming Up" State.
The stacking of my Skill Meditation works perfectly (the script is exactly the one used in the "Stockpile Tips & Tricks", addedo to my "Warming Up" state)

SKILL "Meditation" add the "Warming Up" State to the User.
Warming Up State Notes:
Code:
<Custom Apply Effect>
// Default the stockpile stacks to 0.
user._stockpile = user._stockpile || 0;
// Increase the stockpile stack by 1
user._stockpile += 1;
// Cap the stockpile stack at 3
user._stockpile = Math.min(user._stockpile, 3);
// Update the state counter for the stockpile stack
user.setStateCounter(stateId, user._stockpile);
</Custom Apply Effect>

<Custom Remove Effect>
// Set the user's stockpile stack to 0
user._stockpile = 0;
// Update the state counter for the stockpile stack
user.setStateCounter(stateId, user._stockpile);
</Custom Remove Effect>

Skill "Fire Soul" should apply the BURN State on the Enemy with a 10% chance for any "Warmed Up" stack there is on the actor (max 3 stack: max 30%).

Fire Soul Skill notes:

Code:
var chance = 0.1 * user._stockpile;
if (Math.random() < chance) {
  target.addState(18);
  user._stockpile = 0;
  user.setStateCounter(17, 0);
}

...But when I use the "Fire Soul" Skill, it doesn't Burn anything. I changed the "var chance = 0.1 * user._stockpile;" into a "var chance = 0.3 * user._stockpile;" to try it out, after stocking it three times. Nothing. Am I doing something stupid? (Spoiler: I think yes? Sorry I'm so ignorant about Js)
EDIT: Oh my God, I can't believe it was just THAT but I completely forgot to put your code between two
Code:
<Damage Formula>
code
</Damage Formula>
And of course it is now working amazingly. THANK YOU SO MUCH ♥♥♥♥♥♥♥
Sorry for not being more specific! 😅

Note that the damage formula gets evaluated by auto-battle/enemy AI. If this skill is available for enemies, or if you have auto-battle party members, then I suggest using a different notetag, e.g. <After Eval> from YEP Skill Core.

EDIT 2: I just noticed: If the actor is knocked down when it has some stacks of the State (3 for example), when I re-raise it in the same battle, it doesn't seems to have the state on. But as soon as I try to stack the state again, it instantly regain the state to the same number of stack it has before dying (3 in this case). How should I change this?
I think this is a limitation of Buffs & States Core: the <Custom Remove Effect> notetag processes when the state is removed normally, but not when it is erased by death or State Resist effects. As a workaround, try adding this notetag to state 1 (death state):
Code:
<Custom Apply Effect>
delete target._warmth;
</Custom Apply Effect>
I.e. remove the battler's _warmth counter when they die~ 👋
@caethyril
I think this is a limitation of Buffs & States Core: the <Custom Remove Effect> notetag processes when the state is removed normally, but not when it is erased by death or State Resist effects. As a workaround, try adding this notetag to state 1 (death state):
Code:
<Custom Apply Effect>
delete target._warmth;
</Custom Apply Effect>
I.e. remove the battler's _warmth counter when they die~ 👋
I thought about the Knockout State too, and tried to remove the Stack with that in the same way!...
Of course I must have wrote some other sillyness instead of a working Js, that is more like ancient greek or something, and it wasn't working at all.
Yours worked wonderfully 😊thank you so-super-much! ♥

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/applying-a-state-with-a-precise-percentage-of-success.134878/