Trying to figure out the script to add a state with a chance

unholywolf

Villager
Member
Joined
Mar 28, 2020
Messages
9
Reaction score
4
First Language
English
Primarily Uses
RMMV
I've figured out to have a skill add a state if the user is under another state, but it makes it happening 100% of the time when I only want it happening at 20%.

This is what i got that is working.

Code:
if (user.isStateAffected(x)) {
 target.addState(y);
}
What am I missing?
 

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
661
Reaction score
207
First Language
Vietnamese
Primarily Uses
RMMV
Code:
if (user.isStateAffected(x) && Math.random() < 0.2) {
 target.addState(y);
}
Note that this chance will not be affected by LUK.
 

unholywolf

Villager
Member
Joined
Mar 28, 2020
Messages
9
Reaction score
4
First Language
English
Primarily Uses
RMMV
Ok, I've been messing around with this to increase the chance that the state lands depending on the state the actor has.

This is what I got:
Code:
<Pre-Damage Eval>
if (user.isStateAffected(x) && Math.random() < 0.05) {
  target.addState(n);
} else {
if (user.isStateAffected(y) && Math.random() < 0.1) {
  target.addState(n);
} else {
if (user.isStateAffected(z) && Math.random() < 0.2) {
  target.addState(n);
} else {
if (Math.random() < 0) {
  target.addState(n);
}}
</Pre-Damage Eval>
I don't know if it's correct or if I'm just unlucky enough that I keep getting bad rolls when testing.
And before anyone asks I've figured out how to remove state x if y is in place and both x & y if z is in place.

I also tried with a skill that does it with multiple states:
Code:
<Pre-Damage Eval>
if (user.isStateAffected(x) && Math.random() < 0.05) {
  target.addState(n);
} else {
if (user.isStateAffected(y) && Math.random() < 0.1) {
  target.addState(n);
} else {
if (user.isStateAffected(z) && Math.random() < 0.2) {
  target.addState(n);
} else {
if (Math.random() < 0) {
  target.addState(n);
}}

if (user.isStateAffected(a) && Math.random() < 0.03) {
  target.addState(o);
} else {
if (user.isStateAffected(b) && Math.random() < 0.05) {
  target.addState(o);
} else {
if (user.isStateAffected(c) && Math.random() < 0.09) {
  target.addState(o);
} else {
if (Math.random() < 0.01) {
  target.addState(o);
}}
</Pre-Damage Eval>
Is my math correct?
 
Last edited:

JamesRyan

Game Designer
Veteran
Joined
Sep 13, 2014
Messages
661
Reaction score
207
First Language
Vietnamese
Primarily Uses
RMMV
I think you may want to check for syntax errors. Make sure there is enough { or }.
 

unholywolf

Villager
Member
Joined
Mar 28, 2020
Messages
9
Reaction score
4
First Language
English
Primarily Uses
RMMV
Thanks again James.
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

Newest RPG Maker drops: hey fellas, get on the MZ train to somewhere

Me: Building my VX Ace lego tower, blissfully unaware of time moving forward
When you are trying to make progress in your game. But something is stopping your motivation. Like come on mind! Let me do what I want! :<
Tfw everyone is trying their hardest to brainstorm about unique ideas and game mechanics, here I am just going: "How am I gonna event conversations with busts" everyday. :kaoswt2:
Comedy is third person, tragedy is first person.
Man. A historic 130 year old church nearby had all of its windows broken out with bricks last night. Such a shame, it wasn't generic stained glass patterns either but had beautifully crafted murals depicting various parts of the gospels.

Forum statistics

Threads
99,320
Messages
964,129
Members
130,927
Latest member
Gigabitz
Top