Rock Paper Scissors (2Player)

By Deimius on Jun 06, 2008

This is my own Rock Paper Scissors game that I use on my Bot. It's my first real snippet that I actually made from scratch, however unoriginal it is. It is a little long, so any input on shortening it is greatly appreciated. So are any comments and please post if you find any errors.

To install, post it in you scripts editor(remotes section) by pressing Alt+R on your keyboard. Copy and paste the script below. Make sure you change the first, onTEXT part of the sciprt to the channel(s) you want the game to work in. You must then unload and then reload your Remotes file.

Commands:
!RPS -This will challenge the nick you specify.
!Accept -If nick was challenged, s/he types this to accept a challenge.
!Decline -If nick was challenged, s/he types this to decline a challenge.
!RPS scores [NickHere] -This will find [NickHere]'s RPS scores. If no nick is specifyed, it will retrieve the nick who typed the command's scores.
!RPS Highscores -This will find the nick with the most wins, games, losses and draws and message their names, along with their score to the channel.

Thanks to Z for shortening the FaceOff Alias.
Thanks vaseline28 who's scipt gave me the idea to write this one.
Also thanks to Xlbrag for teaching me about IRC when I was just starting out.
And thanks Scakk for inspiring me a little.

on *:load: {
  if ($isfile(RPS.hsh)) { hmake RPS 50 | hload RPS RPS.hsh }
  else { 
  hmake RPS 50 
  hadd RPS WinHolder None 
  hadd RPS LoseHolder None 
  hadd RPS GamesHolder None 
  hadd RPS DrawHolder None 
}

on *:Exit: {
  hsave RPS RPS.hsh
}

#RPS on
on *:TEXT:*:#Channel(s)Here: {
  if ($1 == !RPS) || ($1 == !PSR) || ($1 == !PSS) || ($1 == !SRP) {
    if ($2 == highscores) { msg $chan Rock Paper Scissors HighScores: 4Most Games: $hget(RPS,$hget(RPS,gamesholder) $+ games) $+ ( $hget(RPS,gamesholder) ) 4Most Wins: $hget(RPS,$hget(RPS,winholder) $+ win) $+ ( $hget(RPS,winholder) ) 4Most Losses: $hget(RPS,$hget(RPS,loseholder) $+ lose) $+ ( $hget(RPS,loseholder) ) 4Most Draws: $hget(RPS,$hget(RPS,drawholder) $+ draw) $+ ( $hget(RPS,drawholder) ) | halt }
    if ($2 == scores) {
      if ($3 == $null) { 
        if (!$hget(RPS,$nick $+ games)) { msg $chan You have never played a game of Rock Paper Scissors with me. | halt }
        else { 
          msg #deimiusland Stats for $nick $+ : 4Games Played: $hget(RPS,$nick $+ games) $+ , 4Wins: $hget(RPS,$nick $+ win) $+ , 4Losses: $hget(RPS,$nick $+ lose) $+ , 4Draws: $hget(RPS,$nick $+ draw) $+ .  
          halt 
        }
      }
      if ($hget(RPS,$3 $+ games)) {
        msg #deimiusland Stats for $3 $+ : 4Games Played: $hget(RPS,$3 $+ games) $+ , 4Wins: $hget(RPS,$3 $+ win) $+ , 4Losses: $hget(RPS,$3 $+ lose) $+ , 4Draws: $hget(RPS,$3 $+ draw) $+ . 
        halt 
      }
      if (!$hget(RPS,$3 $+ games)) { msg $chan $3 has never played a game of Rock Paper Scissors with me. | halt }
    }
    if (%RPS1 == $null) {
      if ($2 == $nick) { msg $chan You cannot play Paper Scissors Rock, by yourself, $nick $+ . | halt }
      if ($2 == $me) { msg $chan I setup the games, I do not play them. | halt }
      if ($2 == $null) { msg $chan Who do you wish to challenge, $nick $+ ? | halt }
      if ($2 ison $chan) { 
        set %RPS1 $nick
        set %RPSW $2
        msg $chan $nick has challeneged $2 to a game of Rock Paper Scissors!
        notice $2 You have been challenged by $nick to a game of Paper scissors Rock. Type: '!accept' or '!decline'.
        .timerRPSChal1 1 60 msg $chan $2 doesn't appear to be there right now. Try challenging $2 again later.
        .timerRPSchal2 1 60 unset %RPS* 
        halt     
      }
      else { msg $chan $2 is not on the channel, $nick $+ . | halt }
    }
    else { msg $chan Please be Patient, $nick $+ . There is already a game of Paper scissors rock in progress. | halt } 
  }
  if ($1 == !accept) { 
    if (%RPS1) {
      if ($nick == %RPSW) {
        .timerRPSchal* off
        set %RPS.chan $chan
        unset %RPSW
        set %RPS2 $nick
        if (!$hget(RPS,%RPS1 $+ games)) {
          hadd -m RPS %rps1 $+ draw 0
          hadd -m RPS %rps1 $+ games 1
          hadd -m RPS %rps1 $+ win 0
          hadd -m RPS %rps1 $+ lose 0
        }
        if (!$hget(RPS,%RPS2 $+ games)) {
          hadd -m RPS %rps2 $+ games 1
          hadd -m RPS %rps2 $+ win 0
          hadd -m RPS %rps2 $+ lose 0
          hadd -m RPS %rps2 $+ draw 0
        }
        msg $chan The Challenge from %RPS1 has been accepted by %RPS2 $+ .
        notice %RPS1 You have 60 seconds to choose either !rock, !paper or !scissors. Syntax: /notice $me [!choicehere] 
        notice %RPS2 You have 60 seconds to choose either !rock, !paper or !scissors. Syntax: /notice $me [!choicehere]    
        .timerRPS1limit1 1 40 msg $chan 20 seconds left, %RPS1 $+ .
        .timerRPS1limit2 msg $chan You took far too long, %RPS1 $+ . 
        .timerRPS1limit3 2win
        .timerRPS2limit1 1 40 msg $chan 20 seconds left, %RPS2 $+ .
        .timerRPS2limit2 1 60 msg $chan You took far too long, %RPS2 $+ . 
        .timerRPS2limit3 1 60 1win
        halt 
      }
      else { 
        msg $chan %rps1 did not challenge you, $nick $+ .
        halt
      }
    }
    else { msg $chan There is no game of rock paper scissors to accept. To challenge someone, type: !RPS [nicktochallenge] | halt }
  }
  if ($1 == !decline) { 
    if ($nick == %RPSW) { 
      .timerchal* off
      msg $chan %RPSw $+  has declined %RPS1 $+ 's challenge.
      unset %RPS*
      halt
    }
    else { 
      msg $chan %rps1 did not challenge you, $nick $+ .
      halt
    }
  }
  if ($1 == !paper) || ($1 == !scissors) || ($1 == !rock) {
    if ($nick == %Rps1) { msg %RPS.chan Correct Syntax is: '/notice $me [!choicehere]' It wouldn't be a bad idea to change your choice now. | halt }
    if ($nick == %Rps2) { msg %RPS.chan Correct Syntax is: '/notice $me [!choicehere]' It wouldn't be a bad idea to change your choice now. | halt }
    else { return }
  }
  else { halt }
}
on *:notice:*:?: {
  if ($1 == !rock) || ($1 == !Paper) || ($1 == !scissors) {
    if ($nick == %RPS1) {
      .timerRPS1* off
      set %RPS1.C $1 
      notice %RPS1 You have chosen %RPS1.c $+ .
      if (%RPS2.c != $null) {
        msg %RPS.chan %RPS1 chose %RPS1.c - %RPS2 chose %RPS2.c $+ . 
        faceoff
        halt
      }
      if (%RPS2.c == $null) {
        notice %RPS1 Please wait for %RPS2 to decide what to pick.
        halt 
      }
    }
    if ($nick == %RPS2) {
      .timerRPS2* off
      set %RPS2.C $1
      notice %RPS2 You have chosen %RPS2.c $+ . 
      if (%RPS1.c != $null) {
        msg %RPS.chan %RPS1 chose %RPS1.c - %RPS2 chose %RPS2.c $+ .
        faceoff 
        halt
      }
      if (%RPS1.c == $null) { notice %RPS2 Please wait for %RPS1 to decide what to pick. | halt } 
    }
  }
  elseif ($nick == %RPS1) { notice %RPS1 Please decide on either !rock, !paper or !scissors | halt }
  elseif ($nick == %RPS2) { notice %RPS2 Please decide on either !rock, !paper or !scissors | halt }
  else { return }
}
alias faceoff {
  if (%rps1.c == %rps2.c) { draw | halt }
  if (%rps1.c == !paper) {
    if (%rps2.c == !rock) { 1win | halt }
    if (%rps2.c == !scissors) { 2win | halt }
  }
  if (%rps1.c == !rock) {
    if (%rps2.c == !scissors) { 1win | halt }
    if (%rps2.c == !paper) { 2win | halt }
  }
  if (%rps1.c == !scissors) {
    if (%rps2.c == !paper) { 1win | halt }
    if (%rps2.c == !rock) { 2win | halt }
  }
}
alias draw {
  msg %rps.chan This Game ends in a draw! We all know, here in %rps.chan $+ , there are no losers.
  var %addgames1 $hget(RPS,%rps1 $+ games)
  inc %addgames1 1
  hadd RPS %rps1 $+ games %addgames1
  if ($hget(RPS,%rps1 $+ games) > $hget(rps,$hget(rps,gamesholder) $+ games)) {
    hadd RPS gamesholder %rps1
    msg %rps.chan %RPS1 $+ , you know hold the title for the most Rock Paper Scissors Games! 
  } 
  var %adddraw1 $hget(RPS,%rps1 $+ draw)
  inc %adddraw1 1
  hadd -m RPS %rps1 $+ draw %adddraw1
  if ($hget(RPS,%rps1 $+ draw) > $hget(rps,$hget(rps,drawholder) $+ draw)) {
    hadd RPS drawholder %rps1
    msg %rps.chan %RPS1 $+ , you know hold the record for the most draws in Rock Paper Scissors! 
  } 
  var %addgames2 $hget(RPS,%rps2 $+ games)
  inc %addgames2 1
  hadd RPS %rps2 $+ games %addgames2
  if ($hget(RPS,%rps2 $+ games) > $hget(rps,$hget(rps,gamesholder) $+ games)) {
    hadd RPS gamesholder %rps2
    msg %rps.chan %RPS1 $+ , you know hold the title for the most Rock Paper Scissors Games! 
  } 
  var %adddraw2 $hget(RPS,%rps2 $+ draw)
  inc %adddraw2 1
  hadd -m RPS %rps2 $+ draw %adddraw2
  if ($hget(RPS,%rps2 $+ draw) > $hget(rps,$hget(rps,drawholder) $+ draw)) {
    hadd RPS drawholder %rps2
    msg %rps.chan %RPS2 $+ , you know hold the record for the most draws in Rock Paper Scissors! 
  } 
  unset %rps*
  halt
}
alias 1win {
  msg %rps.chan Congratulations, %rps1 $+ !! %RPs1.c never fails!
  var %addgames1 $hget(RPS,%rps1 $+ games)
  inc %addgames1 1
  hadd RPS %rps1 $+ games %addgames1
  if ($hget(RPS,%rps1 $+ games) > $hget(rps,$hget(rps,gamesholder) $+ games)) {
    hadd RPS gamesholder %rps1
    msg %rps.chan %RPS1 $+ , you know hold the title for the most Rock Paper Scissors Games! 
  } 
  var %addwin $hget(RPS,%rps1 $+ win)
  inc %addwin 1
  hadd RPS %rps1 $+ win %addwin
  if ($hget(RPS,%rps1 $+ win) > $hget(rps,$hget(rps,winholder) $+ win)) {
    hadd RPS winholder %rps1
    msg %rps.chan %RPS1 $+ , you know hold the title for the most Rock Paper Scissors Wins! 
  }
  var %addgames2 $hget(RPS,%rps2 $+ games)
  inc %addgames2 1
  hadd RPS %rps2 $+ games %addgames2
  if ($hget(RPS,%rps2 $+ games) > $hget(rps,$hget(rps,gamesholder) $+ games)) {
    hadd RPS winholder %rps2
    msg %rps.chan %RPS2 $+ , you now hold the title for the most Rock Paper Scissors Games! 
  }
  var %addlose $hget(RPS,%rps2 $+ lose)
  inc %addlose 1
  hadd RPS %rps2 $+ lose %addlose
  if ($hget(RPS,%rps2 $+ lose) > $hget(rps,$hget(rps,loseholder) $+ games)) {
    hadd RPS loseholder %rps2
    msg %rps.chan %RPS2 $+ , you now hold the title for the most Rock Paper Scissors Games! 
  }
  unset %rps*
  halt
}
alias 2win {
  msg %rps.chan Congratulations, %rps2 $+ !! Next time, you should think again before challenging %Rps2 $+ , %RPs1 $+ . 
  if ($hget(RPS,%rps2 $+ games) > $hget(rps,$hget(rps,gamesholder) $+ games)) {
    hadd RPS gamesholder %rps2
    msg %rps.chan RPS2 $+ , you now hold the title for the most Rock Paper Scissors Games! 
  }
  var %addwin $hget(RPS,%rps2 $+ win)
  inc %addwin 1
  hadd -m RPS %rps2 $+ win %addwin
  if ($hget(RPS,%rps2 $+ win) > $hget(rps,$hget(rps,winholder) $+ win)) {
    hadd RPS winholder %rps2
    msg %rps.chan %RPS2 $+ , you now hold the title for the most Rock Paper Scissors Wins! 
  }
  var %addgames1 $hget(RPS,%rps1 $+ games)
  inc %addgames1 1
  hadd -m RPS %rps1 $+ games %addgames1
  if ($hget(RPS,%rps1 $+ games) > $hget(rps,$hget(rps,gamesholder) $+ games)) {
    hadd RPS gamesholder %rps1
    msg %rps.chan %RPS1 $+ , you now hold the title for the most Rock Paper Scissors Games! 
  }
  var %addlose $hget(RPS,%rps1 $+ lose)
  inc %addlose 1
  hadd -m RPS %rps1 $+ lose %addlose
  if ($hget(RPS,%rps1 $+ lose) > $hget(rps,$hget(rps,loseholder) $+ lose)) {
    hadd RPS loseholder %rps1
    msg %rps.chan %RPS1 $+ , you now hold the title for the most Rock Paper Scissors loses! I'm not so sure if that's a good thing though.
  }
  unset %rps*
  halt
}
#RPS end

Comments

Sign in to comment.
PuNkTuReD   -  Jun 08, 2008

youve got a few
msg #deimiusland
in there still
maybe allow people to set a variable containint their room name
then have it
msg %variable

 Respond  
^Neptune   -  Jun 07, 2008

Hash tables were the first thing you learned? D:
Jesus, that\'s going a bit for starting msl

 Respond  
vaseline28   -  Jun 07, 2008

\"Thanks vaseline28 who\'s scipt gave me the idea to write this one.\"
No problem, but if you look at mine, I use numerical values for Rock/Paper/Scissors within the script and therefore cutting down on the if-then-else statements and shortening the script.

 Respond  
Deimius   -  Jun 06, 2008

Sorry about that, I\'m still really new to scripting and my knowledge of different commands is really limited. Hash tables were one of the first things I learned and it was at the time (and still is :P) the only way I knew of keeping track of scores.

If you have a suggestion on any other methods, I\'m all ears :). Thanks for the comments, both of you.

 Respond  
^Neptune   -  Jun 06, 2008

Hash tables for just using rock paper scissors? lol
I think you made a it a bit over complicated for such a simple thing

 Respond  
LucSatise   -  Jun 06, 2008

wow nice job.. i might actually use this on my new bot =] i\'l give u 9/10 cos of the length

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.