MV YEP_BuffsStatesCore Attack Skill (JS Support)

Good evening,

I previously created a skill with community assistance:


I am trying to replicate a similar skill, but there is an error in my code:

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.375)
           target.addState(17);
       if(Math.random() <= 0.15)
           target.addState(18);
   }
</Post-Damage Eval>

The desired end state will have the skill apply states 17 & 18 ONLY if the target receives damage. Currently, only state 17 is applied.

Thank you for the support.
I think you have some syntax errors (lack of "{" and "}" for IF).
Try this then:
Code:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.375){
           target.addState(17);}
       if(Math.random() <= 0.15){
           target.addState(18);}
   }
</Post-Damage Eval>
I think you have some syntax errors (lack of "{" and "}" for IF).
Try this then:
Code:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.375){
           target.addState(17);}
       if(Math.random() <= 0.15){
           target.addState(18);}
   }
</Post-Damage Eval>
I tried the new code, but only state 17 applies and not 18. Even when I changed state 18 chance to "0.99".
Maybe it needs to be more complex to work instead, because 0.15 is smaller than 0.375, so if the condition for 0.375 is met, it also overrides the 0.15 one. Just try this one:
Code:
<Post-Damage Eval>
   if(value > 0) {
       var random = Math.random();
       if(random <= 0.15){
           target.addState(18);}
       else {
       if(random <= 0.375){
           target.addState(17);}}
   }
</Post-Damage Eval>
I think you have some syntax errors (lack of "{" and "}" for IF).
This isn't correct. If statements automatically apply to the next single code statement, so if you only want to execute one command, there's no need to create a code block with brackets.
if the condition for 0.375 is met, it also overrides the 0.15 one.
This is exactly right. If you're checking a value multiple times, you logically must always go in the order of your operand (checking less than, go from smallest value).

But why do you have your else and if in two separate code blocks, instead of just using else if?
I tried Ryan's code, "code A," and "code B." Ryan's code and "code B" only apply to state 17, and not state 18. I even played with percentages to increase the chance of state 18 being applied, while keeping it lower than state 17's 0.375 and it did not work.

Code A:
JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       var random = Math.random();
       if(random <= 0.365)
           target.addState(18);
       else
       if(random <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>

Code B:
JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.15)
           target.addState(18);
       if(Math.random() <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>
I tried Ryan's code, "code A," and "code B." Ryan's code and "code B" only apply to state 17, and not state 18.
These pieces of code are doing two fundamentally different things. What do you want to be happening here?

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       var random = Math.random();
       if(random <= 0.365)
           target.addState(18);
       else
       if(random <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>
I'm not sure if having the "else" and "if" on different lines breaks this. Generally speaking, JavaScript ignores line breaks, but I know there are some specific cases where it doesn't. It's also just correct form to have the "else if" next to each other: else if (random<=0.375)

If that is correct, I would expect you to hardly ever see state 17 - you only have a one percent chance.

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.15)
           target.addState(18);
       if(Math.random() <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>

This code is syntactically correct. However, it does not do the same thing as the code above. In this case, you're making two separate checks with no else - that means you have a 15% chance to give state 18 and a 37.5% chance to give 17.

If you want to be able to inflict both states, this code is correct. If you only want one or the other, you need to use "else if".

I'm not sure what you mean by "code only apply to" one state, but if you mean that you're never seeing state 18, then I think you should make sure the settings on the state are correct and that your target isn't resistant to it.
These pieces of code are doing two fundamentally different things. What do you want to be happening here?

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       var random = Math.random();
       if(random <= 0.365)
           target.addState(18);
       else
       if(random <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>
I'm not sure if having the "else" and "if" on different lines breaks this. Generally speaking, JavaScript ignores line breaks, but I know there are some specific cases where it doesn't. It's also just correct form to have the "else if" next to each other: else if (random<=0.375)

If that is correct, I would expect you to hardly ever see state 17 - you only have a one percent chance.

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.15)
           target.addState(18);
       if(Math.random() <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>

This code is syntactically correct. However, it does not do the same thing as the code above. In this case, you're making two separate checks with no else - that means you have a 15% chance to give state 18 and a 37.5% chance to give 17.

If you want to be able to inflict both states, this code is correct. If you only want one or the other, you need to use "else if".

I'm not sure what you mean by "code only apply to" one state, but if you mean that you're never seeing state 18, then I think you should make sure the settings on the state are correct and that your target isn't resistant to it.
These pieces of code are doing two fundamentally different things. What do you want to be happening here?

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       var random = Math.random();
       if(random <= 0.365)
           target.addState(18);
       else
       if(random <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>
I'm not sure if having the "else" and "if" on different lines breaks this. Generally speaking, JavaScript ignores line breaks, but I know there are some specific cases where it doesn't. It's also just correct form to have the "else if" next to each other: else if (random<=0.375)

If that is correct, I would expect you to hardly ever see state 17 - you only have a one percent chance.

JavaScript:
<Post-Damage Eval>
   if(value > 0) {
       if(Math.random() <= 0.15)
           target.addState(18);
       if(Math.random() <= 0.375)
           target.addState(17);
   }
</Post-Damage Eval>

This code is syntactically correct. However, it does not do the same thing as the code above. In this case, you're making two separate checks with no else - that means you have a 15% chance to give state 18 and a 37.5% chance to give 17.

If you want to be able to inflict both states, this code is correct. If you only want one or the other, you need to use "else if".

I'm not sure what you mean by "code only apply to" one state, but if you mean that you're never seeing state 18, then I think you should make sure the settings on the state are correct and that your target isn't resistant to it.
I want to be able to inflict both states per the percentages mentioned above. State 18 still does not apply to the target when using the last code you posted.

State 18 is my "ZOMBIE" state. I wonder if it has something to do with Yanfly's "Undead" BuffsandStates code embedded within the state? Screenshots attached.

So far, I can only get it to work by using the engine's default state Traits. Unfortunately, a zombie doing zero damage to a player can still afflict them. I want the states only to be applied if the target takes damage.
I want to be able to inflict both states per the percentages mentioned above. State 18 still does not apply to the target when using the last code you posted.
Note, that as you wrote it there's only a 15% chance for it to work...but that's non-zero, and it's easy enough to change it to a guaranteed chance to test - make it if (Math.random()<=1)

If that doesn't work, you know something's wrong someplace else.
State 18 is my "ZOMBIE" state. I wonder if it has something to do with Yanfly's "Undead" BuffsandStates code embedded within the state? Screenshots attached.
I don't see how it would be. But, again, that's super simplistic to test...just cut all of the text out of the notes into another window and test it with a blank notes area.
Unfortunately, a zombie doing zero damage to a player can still afflict them.
Is that an intended part of your combat system? That you can hit for 0 damage?

After you make your changes, you're saving the project and starting a new game, correct? Not loading a save?
Note, that as you wrote it there's only a 15% chance for it to work...but that's non-zero, and it's easy enough to change it to a guaranteed chance to test - make it if (Math.random()<=1)

If that doesn't work, you know something's wrong someplace else.

I don't see how it would be. But, again, that's super simplistic to test...just cut all of the text out of the notes into another window and test it with a blank notes area.

Is that an intended part of your combat system? That you can hit for 0 damage?

After you make your changes, you're saving the project and starting a new game, correct? Not loading a save?
Not sure what happened, but when I reloaded the project everything started working with the state.

I am still working on stat balancing, but if a character's DEF is high enough it is possible to receive 0 damage. Especially when wandering in a low-level area at a higher level. IMO, in that scenario, it would not make sense for a zombie dealing 0 damage to a player to turn them into a zombie.
Turan,

As always, your support is much appreciated. SOLVED.

Ryan,

I appreciate your help too.

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/yep_buffsstatescore-attack-skill-js-support.146610/