AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
171
First Language
English
Primarily Uses
N/A
Code:
<Post-Damage Eval>
var bonusStateRate = 0.20 + (user.luk / 300);
if (Math.random() < bonusStateRate && target.elementRate(1) > 1) user.addState(7);
</Post-Damage Eval>

In my project, I'm using this post damage evaluation to award a bonus state if you hit an enemy's weakness and if a random chance passes. But I would like to use the luck stat of said actor in the evaluation so that the luck stat has a bit more use in the game. The actor's luck gets taken and divided by a large number so it's added as a minor modifier to the bonus state rate. This code works, but I'm wondering if there's any issues with floating numbers?

As an example, if var bonusStateRate was 0.20 + (user.luk / 300), where the users luck was 44, google says the answer to 44 / 300 is 0.14666666666.
Is that still a smaller number than 0.80? Will a floating number give a pass when it shouldn't have been a pass?

Additionally:
I'm also curious how to have it add the bonus state if the hit was critical? Would that be it's own "if" line?
 
Last edited:

Naveed

Veteran
Veteran
Joined
Nov 2, 2013
Messages
314
Reaction score
148
First Language
English
Primarily Uses
RMMV
There's no issues with floating numbers. The code you wrote should work as intended.

If you want it so that a critical hit will always add the state to the user, you can use an 'or' (which is || in js) in the if line:

Code:
if ((Math.random() < bonusStateRate && target.elementRate(1) > 1) || target.result().critical) user.addState(7);

If you want it so that the state is always added on a critical hit given that the weakness condition still has to be met, just combine the 'or' statement with the random chance check instead using parentheses:

Code:
if ((Math.random() < bonusStateRate || target.result().critical) && target.elementRate(1) > 1) user.addState(7);
 

AdamSakuru

[Null_Value]
Veteran
Joined
Mar 14, 2014
Messages
314
Reaction score
171
First Language
English
Primarily Uses
N/A
Thanks for your help once again, Naveed!
Quick question: can you use 'or' multiple times?

I.E like so:
Code:
<Post-Damage Eval>
if ((condition 1) || (condition 2) || (condition 3) || (etc.)) RESULT;
</Post-Damage Eval>
 

Naveed

Veteran
Veteran
Joined
Nov 2, 2013
Messages
314
Reaction score
148
First Language
English
Primarily Uses
RMMV
Yes you can. The if statement will pass if any of the conditions is true.
 

Latest Threads

Latest Posts

Latest Profile Posts

When you have your friend over and you try to have a good time and let him try your game but he legit finds 10+ bugs that you now have to add to your already big workload for the day lol.
Zaj
Okay anothe stupid question from me. Why is when everyone's explaining the scripts in the scriptlets, it chnge into green. how do i know when do i code without knowing whether its turning green or not
So I realized that I really just don't have enough time to make videos. However I don't mind clicking stream and just letting people watch me work on my game. I don't really have a good microphone... okay it's a $20 headset so it's terrible, and I have no web cam. So the stream would largely be royalty free music and me working, with minor interaction. I guess the question is, would that actually interest anybody?
Child base test two, flappin' their arms like it's VX Ace.
ChildTest-02.gif

Forum statistics

Threads
111,325
Messages
1,060,205
Members
144,641
Latest member
Shooleam
Top