How to deactivate random number if user selects number.

Asked Jan 29, 2021·2 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.

I have created a command for users to "gamble".

!gamble $(user) gambles $(querystring) bolts and $(eval a=["wins!", "loses"];a[Math.floor(Math.random() * a.length)]) a user is able to "gamble" a number of bolts and they win or lose.

I have also created one with a random number

!gamble $(user) gambles $(customapi http://2g.be/twitch/randomnumber.php?=defstart=1&defend=100000&start=$(1)&end=$(2)) bolts and $(eval a=["wins!", "loses"];a[Math.floor(Math.random() * a.length)])

Can I make it so that a random number is selected only if there is no user selected number, but still allow people to select a number? I have been experimenting, but I am clueless with coding and how to integrate different things. Any help is very appreciated :)

2 replies

Try this:

!addcom !gamble $(eval A=`$(1)`;if(A==`null`){B=Math.floor(Math.random()*RANDOM_NUMBER_AMOUNT+1)}else{B=A};C=[`wins!`,`loses.`];`$(user) gambles ${B} bolts and ${C[Math.floor(Math.random()*2)]}`)

Replace RANDOM_NUMBER_AMOUNT with the highest random number you want possible.

Thank you so much! That works perfectly!