NightDev Community Forums

Percentage and bot responses based on the result

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.

Hey @dirqf!

Here’s a solution:

$(eval r=Math.floor(Math.random()*100)+1;o=`responseIfAboveOrEqualTo90`;if(r<90){o=`responseIfBetween70And89Included`}else if(r<70){o=`responseIfBetween50And69Included`}else if(r<50){o=`responseIfBetween30And49Included`}else 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}

Yes, it is.

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}else if(r<90){o=`responseIfBetween70And89Included`}else if(r<70){o=`responseIfBetween50And69Included`}else if(r<50){o=`responseIfBetween30And49Included`}else if(r<30){o=`responseIfBellow30`}`$(user) is a cracker at ${r}%. ${o}.`)

Thanks for your work , all is OK :wink:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.