Rock Paper Scissors Game

By Vegito on Nov 08, 2013

Type /msg rps to request a player to RPS.
When RPS request is sended you have to wait till opponent accept or deny the request.
If your opponent has !accept the request bot will pm you and the opponent to choose between r, p/color] and s

alias -l rpsMakeGame {
  hmake $1
  hmake $2

  hadd $1 RPSOpponent $2
  hadd $2 RPSOpponent $1
}

alias -l rpsReqTimeout {
  msg $1 4 $+ $2 $+ , 12didn't reply within 04 $+ 30 seconds $+ , 12Rock Paper Scissors request timed out. 
  /rpsFreePlayers $1 $2
}

alias -l rpsGestureTimeout {
  var %p1Gesture = $hget($1, RPSGesture)
  var %p2Gesture = $hget($2, RPSGesture)

  if (!%p1Gesture && !%p2Gesture) {
    msg $1 12Both you and 4 $+ $2 12didn't make a gesture.
    msg $2 12Both you and 4 $+ $1 12didn't make a gesture.
  }
  elseif (!%p1Gesture) {
    msg $1 12You didn't make a gesture.
    msg $2 4 $+ $1 12didn't make a gesture.
  }
  elseif (!%p2Gesture) {
    msg $1 4 $+ $2 12didn't make a gesture.
    msg $2 12You didn't make a gesture.
  }

  msg $1 12Rock Paper Scissors game timed out.
  msg $2 12Rock Paper Scissors game timed out.

  /rpsFreePlayers $1 $2
}

alias -l rpsGestureFullname {
  if ($1 == r) return Rock
  if ($1 == p) return Paper
  if ($1 == s) return Scissors
} 

alias -l rpsFreePlayers {
  hfree $1 
  hfree $2
}

alias -l rpsResult {
  var %gesture1 = $hget($1, RPSGesture) 
  var %gesture2 = $hget($2, RPSGesture)

  msg $1 12You choose 4 $+ $rpsGestureFullname(%gesture1) 12and $2 choose 4 $+ $rpsGestureFullname(%gesture2)
  msg $2 12You choose 4 $+ $rpsGestureFullname(%gesture2) 12and $1 choose 4 $+ $rpsGestureFullname(%gesture1)

  if ($istok(r s:p r:s p, %gesture1 %gesture2, 58)) {
    msg $1 12Congratulations! You won the game of Rock Paper Scissors! 
    msg $2 12You lost! 4 $+ $1 12 $+ won! 
  } 
  elseif ($istok(r p:p s:s r, %gesture1 %gesture2, 58)) {
    msg $1 12You lost! 4 $+ $2 12 $+ won! 
    msg $2 12Congratulations! You won the game of Rock Paper Scissors! 
  }
  else {
    msg $1 12It's a tie!
    msg $2 12It's a tie!
  }
}

on *:TEXT:rps*:?: {
  if ($2 == $me) {
    msg $nick 12Sry, I will not play a game of Rock Paper Scissors with you!
    halt
  } 
  if ($2 == $nick) {
    msg $nick 12You can not play a game of Rock Paper Scissors with yourself!
    halt
  }
  if ($hget($2, RPSOpponent)) {
    msg $nick 4 $+ $v1 12challenged or is already playing a game of Rock Paper Scissors with 4 $+ $2 
    msg $nick 12Please try again later.
    halt
  }
  if ($hget($nick, RPSOpponent)) {
    msg $nick 4 $+ $nick 12you already challenged or are playing a game of Rock Paper Scissors with 4 $+ $v1 
    msg $nick 12Please finish your current game first.
    halt
  }
  if ($2) {
    var %opponent = $2
    /rpsMakeGame $nick %opponent

    msg %opponent 4 $+ $nick 12has challenged you to a game of Rock Paper Scissors!
    msg %opponent 12Type 4accept 12to accept the challenge 4deny 12to decline the challenge.
    .timerRPSReq. $+ %opponent 1 30  /rpsReqTimeout $nick %opponent
  }
  else { 
    msg $nick 12You haven't specified an opponent.
    msg $nick 12SYNTAX: 4/msg $me rps <opponent>
  }
}

on $*:TEXT:/^(r|p|s)$/:?: {
  if ($timer(RPSGesture. $+ $nick)) {
    .timerRPSGesture. $+ $nick off

    hadd $nick RPSGesture $1
    var %opponent = $hget($nick, RPSOpponent)

    if ($hget(%opponent, RPSGesture)) {
      /rpsResult $nick %opponent
      /rpsFreePlayers $nick %opponent
    }
    else {
      msg $nick 12You choose 4 $+ $rpsGestureFullname($1)
      msg $nick 4 $+ %opponent 12hasn't made a gesture yet.
    } 
  }
}

on *:TEXT:accept*:?: {
  if ($timer(RPSReq. $+ $nick)) {
    .timerRPSReq. $+ $nick off

    var %p2 = $nick
    var %p1 = $hget(%p2, RPSOpponent)

    msg %p1 12Make a gesture: 04r, 04p 12or 04s $+ 12.
    msg %p2 12Make a gesture: 04r, 04p 12or 04s $+ 12.

    msg %p1 12You've 04 $+ 30 seconds 12to make a gesture.
    msg %p2 12You've 04 $+ 30 seconds 12to make a gesture.

    .timerRPSGesture. $+ %p1 1 30 .timerRPSGesture. $+ %p2 off $(|) /rpsGestureTimeout %p1 %p2
    .timerRPSGesture. $+ %p2 1 30 /rpsGestureTimeout %p1 %p2
  }
}

on *:TEXT:deny*:?: {
  if ($timer(RPSReq. $+ $nick)) {
    .timerRPSReq. $+ $nick off    

    var %p1 = $hget($nick, RPSOpponent)  

    msg %p1 04 $+ $nick $+ , 12has declined your Rock Paper Scissors request. 
    msg $nick 12You've declined 04 $+ %p1 $+ 's 12Rock Paper Scissors request.
    /rpsFreePlayers %p1 $nick
  }
}

Comments

Sign in to comment.
Yawhatnever   -  Nov 09, 2013

$result is already a built-in identifier for mIRC. You'll want to be careful when creating aliases that use an existing name.

Vegito  -  Nov 09, 2013

Oh, ic thanks :D

Ashoollakhani  -  Feb 09, 2016

not working

Sign in to comment

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.