manish icon

CallBreak - Multiplayer Card Game by manish

manish | PRO | 10/01/17 02:50:26 PM UTC | 0 ⭐ | 406 👁️ | Never ⏰ | []
mIRC |

17.87 KB

|

None

|

0 👍

/

0 👎

############################################################
##       CallBreak - Multiplayer Cards Game      ##
##       Version: 1.0              ##
##       By: manish               ##
##       irc.lunarirc.net   #LunarIRC #LunarGames   User - manish  
  ## Commands ##
!cbrules - Show the rules to the player. 
!callbreak - Start the game of CallBreak
!bet - Call your bet ( only possible during 15 seconds before game actually starts )
!change <player> : Change an inactive player with an AI player.
!stopcb - Stops the game. 
!throw <card-position> : Throw a card at the specified position. 
############################################################
on *:TEXT:!callbreak*:#: {
  if ( %call != 1 ) && (%ongoing == $null) { 
    set %ongoing CallBreak
    set %chan $chan
    set %AInames Deegee.TallGah.RayAurous.Lunaleh 
    set %call 1
    msg $chan 9 A Game Of 5CallBreak 9has been started by $nick . To join the game, type !join . For rules of the game, type !cbrules .
    set %players $null
    timer 1 10 msg %chan 6 20 seconds remaining! 
    timer 1 20 msg %chan 9 10 seconds remaining. AI players will join if enough players aren't there. 
    timer 1 30 joinlimit
  }
}
on *:TEXT:!join*:#: {
  if ( %call == 1 ) && ($findtok(%players,$nick,1,46) == $null) {
    set %players $addtok(%players,$nick,32)
    msg $chan 13 $nick has joined the game. 
    if ( $numtok(%players,32) == 4 ) {
      timers off
      start
    }
  }
}
 
on *:TEXT:!cbrules*:#: { 
  notice $nick Call Break is a Four player card game and played with a single deck of 52 cards. Each player gets 13 cards and game begins with each player calling their possible winnable hands, or bets.
  notice $nick Your bet must be at least 1. In each round, the starter can throw any card, and the next player throws a higher card of the same suit to win. In case the player does not have a card of that suit, he can throw a trump card to win the hand, which is any card of Spades.
  notice $nick If even trump cards are not present, then the player may throw any card, but they won't win the hand. At the end of 13 rounds, score is evaluated. 
}
 
alias -l joinlimit { 
  timers off
  if ( %players == $null ) { 
    msg %chan 5 Well, looks like nobody joined! Stopping the game! 
    endcall 
  }
  else {
    timer 1 1 getai
    timer 1 3 msg %chan 5 AI Players have joined the game. Get ready....
    timer 1 5 start
  }
}
 
alias -l getai { 
  var %i = 1
  while ( %i <= 3 ) { 
    set %ai $gettok(%AInames,%i,46) 
    set %players %players %ai 
    inc %i 
  }
  set %players $gettok(%players,1-4,32)  
} 
 
alias -l endcall {
  timers off
  unset %call %begin %thr %curcard %chan %ongoing %players %AInames %ai %pl1 %pl2 %pl3 %pl4 %bets %nos %ccard %deck %suits %cards %bet %round %turn %tplayer %starter %wins %thrown %tc %checkcard %cursuit %colored %lolimit %hilimit %win %winner %cd %lu %toreturn %highest %checker %fs %ffs 
}
 
alias -l start {
  unset %pl1 %pl2 %pl3 %pl4
  timers off
  timer 1 1 msg %chan 11 The players are: %players
  timer 1 3 distcards
  set %bets 3.3.3.3
  timer 1 5 set %bet 1
  timer 1 5 msg %chan 6 The bets are set to 3 by default. You may change your bet by typing !bet <your bet>.
  timer 1 7 msg %chan 3 Game will start in 15 seconds. You cannot change your bet after that.
  timer 1 11 aibet
  timer 1 22 finalstart
}
 
alias -l aibet { 
  if ( $istok(%AInames,$gettok(%players,1,32),46) == $true ) { 
    setbet 1
  }
  if ( $istok(%AInames,$gettok(%players,2,32),46) == $true ) { 
    setbet 2
  }
  if ( $istok(%AInames,$gettok(%players,3,32),46) == $true ) { 
    setbet 3
  }
  if ( $istok(%AInames,$gettok(%players,4,32),46) == $true ) { 
    setbet 4
  }
}
 
alias -l setbet { 
  if ( $1 == 1 ) { set %tc %pl1 } 
  elseif ( $1 == 2 ) { set %tc %pl2 } 
  elseif ( $1 == 3 ) { set %tc %pl3 } 
  elseif ( $1 == 4 ) { set %tc %pl4 } 
 
  var %k = 1 
  var %l = 0
  var %m = 0
  var %n = 0
  while ( %k <= 52 ) { 
    if ( $istok(%tc,%k,46) ) { 
      if ( %k // 13 ) { inc %l } 
      elseif ( %k >= 50 ) { inc %l }
      elseif ( %k > 44 ) { inc %n }
      elseif ( $calc(%k + 1) // 13 ) { inc %n }
    }
    inc %k
  }
  var %nb = $calc(%l + $floor( %n * 1.22 / 3 ))
  if ( %nb == 0 ) { var %nb = 1 }
  msg %chan 11 $gettok(%players,$1,32) sets their bet to %nb . 
  set %bets $deltok(%bets,$1,32)
  set %bets $instok(%bets,%nb,$1,46)
}
 
 
alias -l distcards { 
  set %nos 1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52
  var %i = 1 
  while ( %i <= 13 ) {
    var %c1 = $gettok(%nos,$rand(1,$numtok(%nos,46)),46)
    set %nos $remtok(%nos,%c1,1,46) 
    set %pl1 $addtok(%pl1,%c1,46)
    var %c2 = $gettok(%nos,$rand(1,$numtok(%nos,46)),46)
    set %nos $remtok(%nos,%c2,1,46) 
    set %pl2 $addtok(%pl2,%c2,46)
    var %c3 = $gettok(%nos,$rand(1,$numtok(%nos,46)),46)
    set %nos $remtok(%nos,%c3,1,46) 
    set %pl3 $addtok(%pl3,%c3,46)
    var %c4 = $gettok(%nos,$rand(1,$numtok(%nos,46)),46)
    set %nos $remtok(%nos,%c4,1,46) 
    set %pl4 $addtok(%pl4,%c4,46)
    inc %i
  }
  set %pl1 $sorttok(%pl1,46,n)
  set %pl2 $sorttok(%pl2,46,n)
  set %pl3 $sorttok(%pl3,46,n)
  set %pl4 $sorttok(%pl4,46,n)
  showcard $gettok(%players,1,32) 1
  showcard $gettok(%players,2,32) 2
  showcard $gettok(%players,3,32) 3
  showcard $gettok(%players,4,32) 4
}
 
alias -l showcard { 
  if ( $istok(%AInames,$1,46) == $false) {
    if ($2 == 1 ) { set %ccard %pl1 } 
    elseif ( $2 == 2 ) { set %ccard %pl2 }
    elseif ( $2 == 3 ) { set %ccard %pl3 }
    elseif ( $2 == 4 ) { set %ccard %pl4 }
    unset %deck 
    var %i = 1 
    while ( %i <= $numtok(%ccard,46) ) {
      set %curcard $gettok(%ccard,%i,46)
      set %deck %deck $card(%curcard)
      inc %i
    }
    notice $1 Your cards are: %deck (Total: $numtok(%ccard,46) )
  }
}
alias -l card { 
  set %suits 4,0♥.4,0♦.1,0♣.1,0♠
  set %cards 2.3.4.5.6.7.8.9.10.J.Q.K.A
  var %n = $1
  var %rv = $calc((%n -1) / 13)
  var %suit = $calc($floor(%rv) + 1)
  if ( $calc(%n % 13) == 0 ) { 
    var %card = 13
  }
  else {
    var %card = $calc(%n % 13) 
  }
  return $gettok(%suits,%suit,46) $+ $gettok(%cards,%card,46)
}
 
alias -l suit {
  var %n = $1
  var %rv = $calc((%n -1) / 13)
  var %suit = $calc($floor(%rv) + 1)
  return %suit
 
}
on *:TEXT:!bet*:#: {
  if ( %bet == 1 ) { 
    if ( $2 !isnum ) || ( $floor($2) != $2 ) || ( $2 < 1 ) || ( $2 > 13 ) || ($findtok(%players,$nick,1,32) == $null ) {
      notice $nick Invalid choice! Your bet should be a number, at least 1 and less than 14. 
    }
    else { 
      var %k = $findtok(%players,$nick,1,32) 
      set %bets $deltok(%bets,%k,46)
      set %bets $instok(%bets,$2,%k,46) 
      msg $chan 5 $nick changes their bet to $2 . 
    }
  }
}
 
alias -l finalstart { 
  timers off
  set %round 1
  set %bet 0
  set %turn 1 
  set %tplayer $gettok(%players,1,32)
  msg %chan 3 It's %tplayer  $+ 's turn to start the 1st round. 
  notice %tplayer You may throw any card by specifying !throw <card position>
  unset %thrown
  set %begin 1
  set %starter 1
  set %wins 0.0.0.0
  if ( $istok(%AInames,%tplayer,46)) { 
    timer 1 3 aistuff 
  }
 
}
 
alias -l validate { 
  if ( %turn == 1 ) { set %tc %pl1 }
  elseif ( %turn == 2 ) { set %tc %pl2 } 
  elseif ( %turn == 3 ) { set %tc %pl3 }
  elseif ( %turn == 4 ) { set %tc %pl4 } 
 
  set %checkcard $gettok(%tc,$1,46)
 
  if ( $suit(%checkcard) == %cursuit ) { return $true } 
 
  elseif ( $suit(%checkcard) == 4 ) { 
 
    var %startcheck = $calc(13 * %cursuit - 12)
    var %endcheck = $calc(%startcheck + 12)
    var %holder = 0
    while ( %startcheck <= %endcheck ) {
      if ( $istok(%tc,%startcheck,46) ) { 
        inc %holder
      }
      inc %startcheck 
    }
    if ( %holder > 0 ) { return $false } 
    else { return $true } 
  }
 
  else { 
 
    var %startcheck = $calc(13 * %cursuit - 12)
    var %endcheck = $calc(%startcheck + 12)
    var %holder = 0
    var %looper = 40
    while ( %startcheck <= %endcheck ) {
      if ( $istok(%tc,%startcheck,46) ) { 
        inc %holder
      }
      inc %startcheck 
    }
    while ( %looper <= 52 ) { 
      if ( $istok(%tc,%looper,46) ) {
        inc %holder
      }
      inc %looper 
    }
    if ( %holder > 0 ) { return $false } 
    else { return $true }
  }
}
 
alias -l finishround { 
  timers off
  inc %round 
  evaluatewinner 
}
 
alias -l score { 
 
  msg %chan 5Current Rounds Won:4  $gettok(%players,1,32)  :10 $gettok(%wins,1,46) 4 $gettok(%players,2,32)  : 10 $gettok(%wins,2,46) 4 $gettok(%players,3,32) :10 $gettok(%wins,3,46) 4 $gettok(%players,4,32)  :10 $gettok(%wins,4,46)
}
alias -l evaluatewinner { 
  timers off
  if ( %colored == 1 ) { 
    set %hilimit 52 
    while ( %hilimit >= 40 ) { 
      if ( $istok(%thrown,%hilimit,46) == $true ) {
        break
      }
      set %hilimit $calc( %hilimit - 1)
    }
    set %win $findtok(%thrown,%hilimit,1,46)
    set %thr $calc( ( %starter - 1 ) * 4 + %win )
    set %win $gettok(1.2.3.4.2.3.4.1.3.4.1.2.4.1.2.3,%thr,46) 
    set %winner $gettok(%players,%win,32)
    msg %chan 11 %winner has won this round, with his card $card(%hilimit) !
    set %starter %win
  }
  else { 
    set %lolimit $calc( %cursuit * 13 - 12 ) 
    set %hilimit $calc(%lolimit + 12 ) 
    while ( %hilimit >= %lolimit ) { 
      if ( $istok(%thrown,%hilimit,46) == $true ) { 
        break
      }
      set %hilimit $calc( %hilimit - 1)
    }
    set %win $findtok(%thrown,%hilimit,1,46) 
    set %thr $calc( ( %starter - 1 ) * 4 + %win )
    set %win $gettok(1.2.3.4.2.3.4.1.3.4.1.2.4.1.2.3,%thr,46)
    set %winner $gettok(%players,%win,32)
    msg %chan 11 %winner has won this round, with his card $card(%hilimit) !
    set %starter %win
  }
  if (%round == 14) { timer 1 5 endgame } 
 
  timer 1 4 score
  timer 1 6 msg %chan 6 It's 10 %winner 5's turn to start the next round!! 
  timer 1 5 showcard %winner %win
  timer 1 2 set %thrown $null
  timer 1 2 set %cd $null
  timer 1 2 set %cursuit $null
  timer 1 2 set %colored $null 
  timer 1 2 set %tplayer %winner
  timer 1 2 set %turn %win
  timer 1 3 changed
  if ( $istok(%AInames,%winner,46) ) { timer 1 8 aistuff }
 
}
 
alias -l changed {
  set %lu $gettok(%wins,%win,46)
  set %wins $deltok(%wins,%win,46)
  set %wins $instok(%wins,$calc(%lu + 1),%win,46)
}
 
on *:TEXT:!throw*:#: {
  if ( $nick == %tplayer) && ( %begin == 1) {
    if ( $2 isnum ) && ($floor($2) == $2) && ( $2 > 0 ) && ( $2 <= $calc(14 - %round)) {
 
      if ( %thrown == $null ) || ( $validate($2) == $true ) { 
        if ( %turn == 1 ) { 
          set %cd $gettok(%pl1,$2,46)
          set %pl1 $remtok(%pl1,%cd,1,46)
        }
        elseif ( %turn == 2 ) { 
          set %cd $gettok(%pl2,$2,46)
          set %pl2 $remtok(%pl2,%cd,1,46)
        }
        elseif ( %turn == 3 ) { 
          set %cd $gettok(%pl3,$2,46)
          set %pl3 $remtok(%pl3,%cd,1,46)
        }
        elseif ( %turn == 4 ) { 
          set %cd $gettok(%pl4,$2,46)
          set %pl4 $remtok(%pl4,%cd,1,46)
        }
        if ( $suit(%cd) == 4 ) { set %colored 1 } 
        if (%cursuit == $null) { set %cursuit $suit(%cd) }
        set %thrown $addtok(%thrown,%cd,46) 
        msg $chan 10 $nick throws the card $card(%cd) . 
        inc %turn
        if ( %turn > 4 ) { set %turn 1 } 
        set %tplayer $gettok(%players,%turn,32)
        if ( %turn == %starter ) { 
          timer 1 3 finishround 
        } 
        if ( %turn != %starter ) { 
          timer 1 2 msg %chan 9 It's 10 %tplayer 5's turn to continue the game!! 
          showcard %tplayer %turn
        }
        if ( $istok(%AInames,%tplayer,46)) { 
          timer 1 5 aistuff 
        }
      }
      else {
        notice %tplayer Invalid choice! Make sure that you throw a card of the same suit as the first card in this round. In case, you do not have a card of that suit, you must throw any card of Spades. 
      }
    }
    elseif ( $2 !isnum ) { notice $nick Please enter the position of the card in your deck, i.e, an integer number. }
    elseif ( $2 > $calc(14- %round)) { notice $nick You have selected card number $2 , but you have only $calc(14 - %round) cards. } 
    elseif ( $2 <= 0 ) { notice $nick The position of the card must be a natural number, i.e, greater than 0. } 
    elseif ( $floor($2) != $2 ) { notice $nick You must enter a natural number. }
  }
}
alias -l purify { 
  set %toreturn $1
  var %m = 40
  if ( %colored != 1 ) { 
    while ( %m <= 52 ) { 
      set %toreturn $remtok(%toreturn,%m,1,46)
      inc %m 
    }
  }
  set %toreturn $sorttok(%toreturn,46,nr)
  return $gettok(%toreturn,1,46) 
}
 
alias -l aistuff { 
  timers off
  if ( %turn == 2 ) { set %tc %pl2 } 
  elseif ( %turn == 1 ) { set %tc %pl1 }
  elseif ( %turn == 3 ) { set %tc %pl3 }
  elseif ( %turn == 4 ) { set %tc %pl4 }
 
  if (%cursuit == $null) { 
    var %x = $numtok(%tc,46)
    set %cd $rand(1,%x)
    set %cd $gettok(%tc,%cd,46)
    set %tc $remtok(%tc,%cd,1,46)
  }
 
  else {
    set %highest $purify(%thrown)
    set %lolimit $calc( %cursuit * 13 - 12 ) 
    set %hilimit $calc(%lolimit + 12 ) 
 
    if ( %hilimit == %highest ) { throw 1 } 
    elseif ( $istok(%tc,%hilimit,46) || $istok(%tc,$calc(%hilimit-1),46) ) { throw 2 } 
    elseif ( $calc(%hilimit - %highest) <= 3 ) && ( $istok(%tc,%highest,46) ) { throw 2 } 
    elseif ( $calc(%hilimit - %highest) <= 3 ) { throw 1 } 
    elseif ( $calc(%highest - lolimit) <= 8 ) { throw 2 } 
    else { throw 2 }  
 
  }
 
  if ( $suit(%cd) == 4 ) { set %colored 1 }
  if (%cursuit == $null) { set %cursuit $suit(%cd) }
  set %thrown $addtok(%thrown,%cd,46) 
  msg %chan 10 %tplayer decides to throw the card $card(%cd) . 
 
  if ( %turn == 2 ) { set %pl2 %tc } 
  elseif ( %turn == 1 ) { set %pl1 %tc }
  elseif ( %turn == 3 ) { set %pl3 %tc }
  elseif ( %turn == 4 ) { set %pl4 %tc }
 
  inc %turn 
  if ( %turn > 4 ) { set %turn 1 } 
  set %tplayer $gettok(%players,%turn,32)
  if ( %turn == %starter ) { timer 1 4 finishround } 
  if ( %turn != %starter ) { 
    timer 1 3 msg %chan 9 It's 10 %tplayer 5's turn to continue the game!! 
    showcard %tplayer %turn
  }
 
  if ( $istok(%AInames,%tplayer,46)) { 
    timer 1 5 scon 1 aistuff
  }
}
 
alias -l throw { 
  unset %checker
  if ( $1 == 1 ) { 
 
    while ( %hilimit >= %lolimit ) { 
      if ( $istok(%tc,%hilimit,46)) { set %checker %hilimit } 
      set %hilimit $calc(%hilimit - 1)
    }
    if ( %checker == $null ) { 
      var %mc = 40 
      while ( %mc <= 52 ) { 
        if ( $istok(%tc,%mc,46)) { 
          set %checker %mc 
          break
        }
        inc %mc
      }
    }
    if ( %checker == $null ) { 
      var %pc = $rand(1, $numtok(%tc,46) )
      set %checker $gettok(%tc,%pc,46)
    }
  }
  elseif ( $1 == 2 ) { 
    while ( %lolimit <= %hilimit ) { 
      if ( $istok(%tc,%lolimit,46)) { set %checker %lolimit }
      inc %lolimit
    } 
    if ( %checker == $null ) { 
      var %mc = 40 
      while(%mc <= 52 ) { 
        if ( $istok(%tc,%mc,46)) { 
          set %checker %mc 
          break
        }
        inc %mc
      }
    }
    if ( %checker == $null ) { 
      var %pc = $rand(1, $numtok(%tc,46) )
      set %checker $gettok(%tc,%pc,46)
    }
  }
 
  set %cd %checker
  set %tc $remtok(%tc,%cd,1,46)
 
}
 
alias -l modify { 
  if ( $1 < 0 ) { return 0 } 
  else { return $1 } 
}
 
alias -l endgame { 
  timers off
  unset %fs
  var %l = 1
  while ( %l <= 4 ) { 
    if ( $gettok(%wins,%l,46) < $gettok(%bets,%l,46) ) { 
      set %fs $instok(%fs,$calc(-1 * $gettok(%bets,%l,46) * 10),%l,46 )
      if ($istok(%AInames,$gettok(%players,%l,32),46) == $false ) { coins $gettok(%players,%l,32) $modify($gettok(%fs,%l,46)) }
    }
    else { 
      set %fs $instok(%fs,$calc( $gettok(%bets,%l,46) * 10 + ( $gettok(%wins,%l,46) - $gettok(%bets,%l,46) ) ),%l,46 )
      if ($istok(%AInames,$gettok(%players,%l,32),46) == $false ) { coins $gettok(%players,%l,32) $modify($gettok(%fs,%l,46)) }
    }
    inc %l
  }
  timer 1 1 msg %chan 6 Points earned: 4  $gettok(%players,1,32)  :10 $gettok(%fs,1,46) 4 $gettok(%players,2,32)  : 10 $gettok(%fs,2,46) 4 $gettok(%players,3,32) :10 $gettok(%fs,3,46) 4 $gettok(%players,4,32)  :10 $gettok(%fs,4,46)
  set %ffs $sorttok(%fs,46,nr)
  var %hig = $gettok(%ffs,1,46)
  set %win $findtok(%fs,%hig,1,46)
  set %winner $gettok(%players,%win,32)
  timer 1 3 msg %chan 5 %winner has won the game, with a score of %hig , thus getting %hig coins. Other players have been given their respective coins! 
  timer 1 4 endcall
}  
 
on *:TEXT:!stopcb*:#: {
  if ( $nick isop %chan ) || ($nick == manish) { 
    endcall
    msg $chan 4 Game has been stopped by $nick .
  } 
}
 
on *:TEXT:!change*:#: {
  if ( $nick isop %chan ) { 
    if ( $istok(%AInames,$2,46) ) { notice $nick AIs cannot be replaced. } 
    elseif ( $istok(%players,$2,32) ) { 
      var %i = 1 
      while ( %i <= 4 ) { 
        if ( $istok(%players,$gettok(%AInames,%i,46),32) == $false ) { 
          break
        }
        inc %i 
      }
      msg %chan 10 $gettok(%AInames,%i,46) will be playing in place of $2 now! 
      var %z = $findtok(%players,$2,1,32)
      set %players $remtok(%players,$2,1,32)
      set %players $instok(%players,$gettok(%AInames,%i,46),%z,32)
      if ( %turn == %z ) { 
        set %tplayer $gettok(%AInames,%i,46)
        aistuff
      }
    }
  }
}
 
alias -l coins {
  if ($read(coins.txt,w,* $+ $1 $+ *)) {
    set %n $readn $+
    set %data $read(coins.txt,w,* $+ $1 $+ *)
    set %current $gettok(%data,2,32) 
    set %new $calc(%current + $2)
    set %data $replace(%data,%current,%new)
    write -dl $+ %n coins.txt
    write coins.txt %data 
  }
  else { 
    write coins.txt $1 $2
  }
}

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎