Percentage and bot responses based on the result

Asked Nov 16, 2020·7 replies·Last activity 5 years ago·Open in Discord ↗
Archived from the original community forum
Things may have changed since it was written. Still stuck? Ask the community on Discord.

Hello. I would like to create a double command one which indicates a percentage. XX is 80% a pirate. ($ (user) is a cracker at $ (eval Math.floor (Math.random () * 100) + 1)%) but I would like to add a sentence depending on the result. if result <30, between 30 and 50, between 50 and 70 between 70 and 90 and> 90, each possibility has a different answer.

7 replies

Hey @Eager Shrimp!

Here's a solution:

$(eval r=Math.floor(Math.random()*100)+1;o=`responseIfAboveOrEqualTo90`;if(r<90){o=`responseIfBetween70And89Included`} if(r<70){o=`responseIfBetween50And69Included`} if(r<50){o=`responseIfBetween30And49Included`} if(r<30){o=`responseIfBellow30`}`$(user) is a cracker at ${r}%. ${o}.`)

it's ok if i remove the "else" value. between the different possibilities. thank you very much !

is it possible to add a fixed value ... if (r = 92) {hdjdkdkdkdn}

Eager Shrimp said:
it’s ok if i remove the “else” value. between the different possibilities.

Yes, it is.

Eager Shrimp said:
is it possible to add a fixed value … if (r = 92) {hdjdkdkdkdn}

And yes too, just follow the pattern.

the problem is that only "92%" is drawn at random if I put as in my example

That's because you need to use at least two equal signs to make a comparison, one equal sign affects the value to the variable.

$(eval r=Math.floor(Math.random()*100)+1;o=`responseIfAboveOrEqualTo90`;if(r==92){o=`responseIfEqualTo92} if(r<90){o=`responseIfBetween70And89Included`} if(r<70){o=`responseIfBetween50And69Included`} if(r<50){o=`responseIfBetween30And49Included`} if(r<30){o=`responseIfBellow30`}`$(user) is a cracker at ${r}%. ${o}.`)

Didn't find your answer? The community is on Discord.

Ask on Discord