add a condition to rock paper scissor game

Hello,

I already have a line of code for a minigame of rock, paper, scissor where you can put an username and fight him.
But im wondering how to make a specific response if someone put a specific username.
Like “$(user) tried to fight (otheruser) but no one can try him.” or something like that…
the code is:
!commands edit !fight $(user) fought $(eval a=[won,drew,lost];b=[a rock,paper,scissors];r=x=>x[Math.floor(Math.random()*x.length)];${decodeURIComponent($(querystring)).replace(/@/g,``)||$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))} and ${r(a)} with ${r(b)})`

1 Like

Hey @dreyz!

This should do what you’re looking for, replace SPECIFIC_USER in the command.

!editcom !fight $(eval a=[`won`,`drew`,`lost`];b=[`a rock`,`paper`,`scissors`];r=x=>x[Math.floor(Math.random()*x.length)];`$(query)`?t=decodeURIComponent(`$(querystring)`).replace(/@/g,``):t=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;t.toLowerCase()==`SPECIFIC_USER`.toLowerCase()?`$(user) tried to fight ${t} but no one can try them.`:`$(user) fought ${t} and ${r(a)} with ${r(b)}`;)
2 Likes

Thanks a lot this works perfectly.
If i want to add another user can i do
t.toLowerCase()==SPECIFIC_USER||ANOTHER_SPECIFIC or do i have to create another const ?

1 Like

Yes, that’s one of the ways to do it, however, if you remove toLowerCase() remember to write the SPECIFIC_USERS in lower case.

The other option being the following:

!addcom !fight $(eval a=[`won`,`drew`,`lost`];b=[`a rock`,`paper`,`scissors`];r=x=>x[Math.floor(Math.random()*x.length)];`$(query)`?t=decodeURIComponent(`$(querystring)`).replace(/@/g,``):t=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;s=[`SPECIFIC_USER1`,`SPECIFIC_USER2`];s.includes(t.toLowerCase())?`$(user) tried to fight ${t} but no one can try them.`:`$(user) fought ${t} and ${r(a)} with ${r(b)}`;)

In this case SPECIFIC_USERS should be written in lower case.

2 Likes

Im trying to rebuild this command for my channel (sorry dreyz). What can I do something to make “b” different between to players and the command identify the answer? Repeat the “b” in a “c” value maybe?

$(user) fought ${t} and picked ${r(b)}, ${t} picked ${r(c)}. ${r(a)}!;)`

Hey @loldest159!

Alright, so this is a different command in that case, I hope you don’t mind if I get rid of the SPECIFIC_USER part as I already gave a solution for this, and the @ remover part as well, I needed to save as much space as I could. Also, you’ll have to add the command via the dashboard as it’s too long for adding it from the chat.

$(eval z=[`a rock`,`paper`,`scissors`];r=()=>Math.floor(Math.random()*3);u=`$(user)`;`$(query)`?t=`$(touser)`:t=`$(urlfetch https://2g.be/twitch/randomviewer.php?channel=$(channel))`;a=r();b=r();if(a==b){c=`it's a tie`;}else{if(a==0&&b==1){w=`${t}`;}if(a==0&&b==2){w=`${u}`;}if(a==1&&b==0){w=`${u}`;}if(a==1&&b==2){w=`${t}`;}if(a==2&&b==0){w=`${t}`;}if(a==2&&b==1){w=`${u}`;}c=`${w} won`;}`${u} started a fight against ${t}. ${u} picks ${z[a]} and ${t} picks ${z[b]}... Looks like ${c}!`)
1 Like

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