mIRC Home    About    Download    Register    News    Help

Print Thread
#251376 16/02/15 07:15 PM
Joined: Nov 2014
Posts: 79
N
Newbie Offline OP
Babel fish
OP Offline
Babel fish
N
Joined: Nov 2014
Posts: 79
I've got a paper, rock, scissors script that trigger randomly as the stream is playing. Here's the script for reference:

Code:
alias -l PRS {
  set %PRS_user $read(PRS.txt, n)
  msg %PRS_newbie /me Dinobot challenges %PRS_user to Paper Rock Scissors, do you accept?
  set %PRS_control 1
}

alias -l PRScissors {
  msg %PRS_newbie I chose PRS_b
}

on !*:JOIN:#:{
  var %ran $rand(20,60)
  .timerPRS 1 %ran PRS
  write PRS.txt $nick
  set %PRS_newbie #
}

on *:TEXT:*:#: {
  if ($nick == %PRS_user) {
    if (%PRS_control == 1) {
      if ($1 == yes) {
        msg %PRS_newbie /me On the count of three. 
        set %PRS 2
        .timerOne 1 2 msg %PRS_newbie /me 1
        .timerTwo 1 4 msg %PRS_newbie /me 2
        .timerThree 1 6 msg %PRS_newbie /me 3
        .timerfour 1 8 msg %PRS_newbie /me Choose paper/rock/scissors
      }
      elseif ($1 == no) {
        msg %PRS_newbie /me You don't want to play with me BibleThump $+ ? 
      }
    }
    if (%PRS == 2) {
      set %PRS_u $1
      var %choices = paper,rock,scissors
      set %PRS_b $gettok(%choices, $rand(1,3), 44)
      PRScissors   
    }
  }
}


So the code will start the instant someone joins but can last until the end of the stream -- right now I only having it run for 60 seconds for testing purposes.

My question really comes down to deciding whether the player won or lost.

The variable PRS_u will be what the player input I.E. paper, rock, scissors. The variable PRS_b will be what my robot chose depending on $gettok(%choices, $rand(1,3), 44).

Is this the only way I can do it?

Code:
if ((%PRS_u == paper) && (%PRS_b == paper)) {
   msg # You both tied, no winners
} 
if ((%PRS_u == paper) && (PRS_b == rock)) {
   msg # You win! 
}

etc...


Or is there a shorter version to that?

Last edited by Newbie; 16/02/15 07:16 PM.
Joined: Jun 2014
Posts: 248
B
Fjord artisan
Offline
Fjord artisan
B
Joined: Jun 2014
Posts: 248
Umm...It possible I messed up some logic in here somewhere, but this *seems* right to me atm. Just based on the idea of the win pattern being circular.

Code:
alias win {
  var %win paper,scissors,rock
  if (%PRS_u == $gettok(%win, $iif($calc($findtok(%win, %PRS_b, 1, 44) - 1) == 0,3,$v1),44)) { .msg # win }
  if (%PRS_u == $gettok(%win, $iif($calc($findtok(%win, %PRS_b, 1, 44) + 1) == 4,1,$v1),44)) { .msg # lose }
  if (%PRS_u == %PRS_b)  { .msg # tie }
}


Link Copied to Clipboard