!battle with 2 random numbers, and 3 different messages depending on win/lose/tie

So far I have this, which is basically a coin flip:

$(eval var sayings = [‘$(user) defeated $(1)!’, “$(1) defeated $(user)!”]; sayings[Math.floor(Math.random() * sayings.length)]:wink:

But I’d like to somehow include a random number generator like this: $(eval Math.floor((Math.random() * 100) + 1))

So that the command can create two random numbers, compare them against each other, and then spit out one of 3 different results depending on whether:

the first number is higher than the second number
the first number is lower than the second number
both numbers are the same

example results corresponding to the above would look like:

$(user)'s [first number] crushed $(1)'s [second number]!
$(user)'s [first number] was crushed by $(user)'s [second number]!
$(user)'s [first number] and $(1)'s [second number] are evenly matched!

Hey @evalhelpquestion!

What you want is fairly easy to set up:

$(eval r = () => Math.floor(Math.random() * 100) + 1; u = r(); t = r(); s = [`$(user)'s ${u} crushed $(1)'s ${t}`, `$(user)'s ${u} was crushed by $(1)'s ${t}`, `$(user)'s ${u} and $(1)'s ${t} are evenly matched`]; v = u - t; v > 0 ? w = 0 : v < 0 ? w = 1 : w = 2; s[w] + '!';)
1 Like

PERFECT! Thank you Emily!

While I was testing it I had two more ideas. Not sure if they’re possible of if they’d make the code so long I’ve have to use a pastebin, but

  1. Right now if I type !battle by itself it will fight “null”. I don’t know if there’s a way to make it say “Choose An Opponent” instead.

  2. I thought it would be fun if the describing-words in the middle changed depending on the difference between the two numbers

The range-breakdown would be:

defeated / was defeated by (1 to 19)
destroyed / was destroyed by (20 to 39)
crushed / was crushed by (40 to 59)
demolished / was demolished by (60 to 79)
obliterated / was obliterated by (80 to 99)

The list on the left of the “/” above would be used if the first number was higher than the second number
The list on the right of the “/” above would be used if the first number was lower than the second number

So if for example the random number generator in the command chose the numbers 20 and 80 it would return

$(user)'s [first number] was demolished by $(1)'s [second number]!

choosing the phrase “was demolished by” because the difference between the numbers is 60 (80-20), AND because the first number was lower than the second number (if the first number was HIGHER than the second number, the chosen phrase would have been “demolished”)

I hope this makes sense and I’m curious to hear if this is within the realm of possibility!

That’s the easiest thing to fix:

if ('$(1)' === 'null') { 'Choose an opponent' } else { THE_REST_OF_THE_CODE }

This isn’t difficult to do either, just gotta use absolute value of the comparison.

$(eval r = () => Math.floor(Math.random() * 100) + 1; u = r(); t = r(); v = u - t; a = Math.abs(v); d = ['defeated', 'destroyed', 'crushed', 'demolished', 'obliterated']; '$(1)' === 'null' ? 'Choose an opponent' : v === 0 ? `$(user)'s ${u} and $(1)'s ${t} are evenly matched!` : `$(user)'s ${u} ${v < 0 ? 'was' : ''} ${a < 20 ? d[0] : a < 40 ? d[1] : a < 60 ? d[2] : a < 80 ? d[3] : d[4] } ${v < 0 ? 'by' : ''} $(1)'s ${t}!`;)

Incredible, worked like a charm. Thank you!!


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