Duel command with percentage for nightbot winning

Asked Aug 22, 2021·21 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 am brand new to nightbot and I want to set up a !duel command where the user challenges nightbot to a duel but rather than a random 50/50 I would like to make it in nightbot's favor so that winning the duel is even more significant. I want it to be a 1 in 50 chance of beating nightbot. If anyone could help I would greatly appreciate it.

21 replies

Hey @Trusty Jellyfish!

It's pretty simple really:

$(eval Math.floor(Math.random()*50)==0?`USER_WINS_MESSAGE`:`USER_LOSES_MESSAGE`)

Actually for a 50/50 you’ll wanna make that a 2 and not 50 :p

$(eval Math.floor(Math.random()*2)==0?`USER_WINS_MESSAGE`:`USER_LOSES_MESSAGE`)

I actually wanted the 1 in 50 chance, but this is useful to know how to change the math. Thanks!

One more thing I thought of. Is there a way to make it count the number of wins and losses separately? Or does counting only work for the command use?

Yes you could do that you’d need three or more commands one with an alias and the use of an API to keep track of it but it is technically possible. There is a slightly less complicated version of this which would require manual entry /t/win-loss-death-kill-counters-in-one-command/1534599429502537921#m153459943… and a more complex version that would update it automatically you’ll need a separate command to see the wins and losses to. If you need me to I’ll edit the above code to make it automatically update if you want but either way let me know.

I would like it to update automatically.
if you don't mind editing it that would be great!

For these you’ll need to generate private and public tokens how it explains in the post I linked.

!Main_command_name

$(eval Math.floor(Math.random()*50)==0?`w`:`l`)

Alias it to _count

_count

$(eval a=`$(urlfetch https://twitch.center/customapi/addquote?token=PRIVATE_TOKEN&data=$(1))`;`$(1)`==`w`?`WIN_MESSAGE`:`LOSS_MESSAGE`)

!NAME_OF_COUNT_COMMAND

$(eval q=`$(urlfetch json https://twitch.center/customapi/quote/list?token=PUBLIC_TOKEN&no_id=1)`;w=q.replace(/l/g,``);l=q.replace(/w/g,``);w==null?w=0:w=w.length;l==null?l=0:l=l.length;`Wins: ${w} | Losses: ${l}`)

Please note I wrote this all at 3 am so there may very well be mistakes but hopefully it works first go :)

It seems like its almost there. i ran the main command a few times but the count just says 25 for wins and losses. and I really do appreciate the help at this hour but no rush if you want to get back to me later about it

I just need your 8 digit public token so I can check something

where would i find that? im completely new to all this

Ok when you added the commands did you replace “PUBLIC” and “PRIVATE” “_TOKEN”?

i pretty much just copy pasted everything but changed the 'WIN_MESSAGE'" and "LOSS_MESSAGE" was i supposed to replace the 'w' and 'l' in the main command with the same win and loss message?

okay i will check that out. and just to be clear is there anything else that I am supposed to change other than the win and loss messages?

Yes specifically PUBLIC_TOKEN and PRIVATE_TOKEN There is absolutely no way they will work unless you use those.

oh okay. that must be what im missing. sorry, I dont know much about this. ill check out the link and see if i can get it going. Thank you so much for this 😊

It's working! Once again I really appreciate it and thank you for dealing with my Naivety 😁

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

Ask on Discord