manish

Hi-Lo Multiplayer Game by manish

Apr 12th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 13.78 KB | None | 0 0
  1. ############################################################
  2. ##       Hi-Lo Multiplayer Version Script ( with Stats and AI Players)            ##
  3. ##       Version: 1.0              ##
  4. ##       By: manish               ##
  5. ##       irc.lunarirc.net   #LunarIRC   User - manish  
  6.   ## COMMANDS ##
  7. !hilo - To initiate a game of Hi-Lo.
  8. high - Go high.
  9. !low - Go low
  10. !stats <nickname> : Shows the statistics of the specified user.
  11. ############################################################
  12. on *:TEXT:!hilo*:#: {
  13.   if ( %hilo != on ) && (%ongoing == $null) {
  14.     set %hilo on
  15. set %chan $chan
  16.     set %o 0
  17.     msg $chan 3 Hi-Lo game has been started. 13 cards are taken, and a random card is drawn and removed every time. You need to guess whether the next card is higher or lower than the previous card.
  18.     msg $chan 9 Type !start Solo or !start multi to start a Solo Game or a Multiplayer Game respectively.    
  19.   }
  20.   else {
  21.     msg $chan 9 Type !start Solo or !start multi to start a Solo Game or a Multiplayer Game respectively.
  22.   }  
  23. }
  24.  
  25. on *:TEXT:!start*:#: {
  26.   if ( %hilo == on ) && ( %o == 0 ) && ( $2 == solo ) {
  27.     inc %o
  28.     set %gamemode solo
  29.     set %nick $nick
  30.     set %chan $chan
  31.     msg $chan 6 Game of High-Low has been started by $nick . Current champion: %champ .
  32.     startg
  33.     msg %chan 4,0♥ $+ %oldcard 4,010 has been chosen! 12 cards remaining in the deck.
  34.     msg %chan 6 $nick may choose to go !high or go !low
  35.     timer 1 30 timeout
  36.   }
  37.   elseif ( %hilo == on ) && ( %o == 0 ) && ( $2 == multi ) {
  38.     inc %o
  39.     set %chan $chan
  40.     set %gamemode multiplayer
  41.     unset %game
  42.     set %multi started
  43.     set %cards 2.3.4.5.6.7.8.9.10.J.Q.K.A
  44.     set %AInames ProMan LucyFir StupidTolga
  45.     if ( $3 isnum ) && ( $3 >= 2 ) && ( $3 <= 4 ) {
  46.       set %playing $3
  47.     }
  48.     else { set %playing 4 }
  49.     msg %chan 6 A game of Hi-Lo Multiplayer has been started. Type !join to join. You have 30 seconds..
  50.     set %joining on
  51.     timer 1 15 msg %chan 10 15 seconds left... If enough players do not join, AI Players will be joining.
  52.     timer 1 30 timeup
  53.  
  54.   }
  55.   elseif ( %o == 1 ) {
  56.     msg $chan 7 A game of High-Low %gamemode is already in progress in %chan .
  57.   }
  58.   else {
  59.   msg $chan 6 Please start a game of High-Low by typing !hilo . }
  60. }
  61. alias startg {
  62.   getinfo %nick
  63.   inc %sgp
  64.   makedata %nick
  65.   set %score 0
  66.   set %cards 2.3.4.5.6.7.8.9.10.J.Q.K.A
  67.   set %total $numtok(%cards,46)
  68.   set %x $rand(1,%total)
  69.   set %oldcard $gettok(%cards,%x,46)
  70.   %cards = $deltok(%cards,%x,46)
  71. }
  72. on *:TEXT:!stophilo*:#: {
  73.   if ( $nick isop %chan ) {
  74.     end
  75.     msg %chan 14  Game has been stopped by $nick .
  76.   }
  77. }
  78. on *:TEXT:!high*:#: {
  79.   timers off
  80.   if ( $nick == %tplayer ) {
  81.     go high
  82.   }
  83.   elseif ( $nick == %nick) {  
  84.     ignore %nick
  85.     timer 1 1 msg %chan 10 $nick goes for high.
  86.     set %total $numtok(%cards,46)
  87.     set %x $rand(1,%total)
  88.     set %newcard $gettok(%cards,%x,46)
  89.     %cards = $deltok(%cards,%x,46)
  90.     set %oldval $value(%oldcard)
  91.     set %newval $value(%newcard)
  92.     if ( %newval > %oldval ) {
  93.       inc %score
  94.       timer 1 5 msg %chan 14  The next card is 4,0♥ $+ %newcard 4,0 .
  95.       timer 1 5 msg %chan 6 $numtok(%cards,46) cards remaining in the deck.
  96.       timer 1 5 msg %chan 6 $nick makes a correct choice and is still in the game.
  97.       timer 1 7 msg %chan 10 Current score of $nick : %score
  98.       timer 1 7 ignore -r %nick
  99.       timer 1 37 timeout
  100.       if ( %score == 12 ) {
  101.         timer 1 8 msg %chan 9 $nick has won the game of High-Low with a top-class score of 12, and is the new champion!
  102.         getinfo %nick
  103.         if ( %score > %hs ) { set %hs %score }
  104.         makedata %nick
  105.         set %champ $nick
  106.         unset %o
  107.         set %hilo off
  108.         unset %nick
  109. timers off
  110.       }
  111.  
  112.     }
  113.     else {
  114.       timer 1 4 msg %chan 14  The next card is 4,0♥ $+ %newcard 4,0 .
  115.       timer 1 5 msg %chan 4 Game Over! $nick loses the game with a total score of %score . Well played!
  116.       ignore -r %nick
  117.       getinfo %nick
  118.       if ( %score > %hs ) { set %hs %score }
  119.       makedata %nick
  120.       unset %o
  121.       set %hilo off
  122.       unset %nick
  123.     }
  124.     set %oldcard %newcard
  125.   }
  126. }
  127. on *:TEXT:!low*:#: {
  128.   timers off
  129.   if ( $nick == %tplayer ) {
  130.     go low
  131.   }
  132.   elseif ( $nick == %nick) {  
  133.     ignore %nick
  134.     timer 1 1 msg $chan 10 $nick goes for low.
  135.     set %total $numtok(%cards,46)
  136.     set %x $rand(1,%total)
  137.     set %newcard $gettok(%cards,%x,46)
  138.     %cards = $deltok(%cards,%x,46)
  139.     set %oldval $value(%oldcard)
  140.     set %newval $value(%newcard)
  141.     if ( %newval < %oldval ) {
  142.       inc %score
  143.       timer 1 5 msg %chan 14  The next card is 4,0♥ $+ %newcard 4,0 .
  144.       timer 1 5 msg %chan 6 $numtok(%cards,46) cards remaining in the deck.
  145.       timer 1 5 msg %chan 6 $nick makes a correct choice and is still in the game.
  146.       timer 1 7 msg %chan 10 Current score of $nick : %score
  147.       timer 1 7 ignore -r %nick
  148.       timer 1 37 timeout
  149.       if ( %score == 12) {
  150.         timer 1 8 msg %chan 9 $nick has won the game of High-Low with a top-class score of 12, and is the new champion!
  151.         getinfo %nick
  152.         if ( %score > %hs ) { set %hs %score }
  153.         makedata %nick
  154.         set %champ $nick
  155.         unset %o
  156.         set %hilo off
  157.         unset %nick
  158.         timers off
  159.       }
  160.     }
  161.     else {
  162.       timer 1 4 msg %chan 14  The next card is 4,0♥ $+ %newcard 4,0 .
  163.       timer 1 5 msg %chan 4 Game Over! $nick loses the game with a total score of %score . Well played!
  164.       ignore -r %nick
  165.       getinfo %nick
  166.       if ( %score > %hs ) { set %hs %score }
  167.       makedata %nick
  168.       unset %o
  169.       set %hilo off
  170.       unset %nick
  171.  
  172.     }
  173.     set %oldcard %newcard
  174.   }
  175. }
  176.  
  177. alias -l value return $iif($1 isnum,$1,$+(1,$pos(JQKA,$1,1)))
  178.  
  179. alias  timeout {
  180.   msg %chan 4 Sorry %nick , you ran out of the time-limit (30 seconds) and eventually lose the game with the score %score .
  181.   getinfo %nick
  182.   if ( %score > %hs ) { set %hs %score }
  183.   makedata %nick
  184.   unset %o
  185.   set %hilo off
  186.   notice %nick Please Wait 30 seconds if you want to play again.
  187.   ignore -cu30 %nick
  188.   unset %nick
  189. }
  190. alias  go {
  191.   timers off
  192.   ignore %tplayer
  193.   timer 1 1 msg %chan 10 %tplayer decides to go $1 .
  194.   getnewcard
  195.   set %decision $1
  196.   set %oldval $value(%oldcard)
  197.   set %newval $value(%newcard)
  198.   timer 1 3 msg %chan The next card is 4,0♥ $+ %newcard 4,0 .
  199.   if ( %decision == high ) && ( %newval > %oldval ) {
  200.     timer 1 4 msg %chan 9 %tplayer makes a correct choice and is still in the game.
  201.     set %mcb $gettok(%corr,%turn,46)
  202.     inc %mcb
  203.     set %corr $deltok(%corr,%turn,46)
  204.     set %corr $instok(%corr,%mcb,%turn,46)
  205.   }
  206.   elseif ( %decision == low ) && ( %newval < %oldval ) {
  207.     timer 1 4 msg %chan 9 %tplayer makes a correct choice and is still in the game.
  208.     set %mcb $gettok(%corr,%turn,46)
  209.     inc %mcb
  210.     set %corr $deltok(%corr,%turn,46)
  211.     set %corr $instok(%corr,%mcb,%turn,46)
  212.  
  213.   }
  214.   else {
  215.     timer 1 4 msg %chan 4 %tplayer makes a wrong choice and loses a life.
  216.     %life = $gettok(%lifes,%turn,46)
  217.     set %life $calc(%life - 1)
  218.     set %lifes $deltok(%lifes,%turn,46)
  219.     set %lifes $instok(%lifes,%life,%turn,46)
  220.  
  221.   }
  222.   timer 1 6 showlifes
  223.   timer 1 8 getout
  224. }
  225.  
  226. alias -l showlifes {
  227.   var %pk = 1
  228.   while ( %pk <= %playing ) {
  229.     set %display %display 6   $gettok(%players,%pk,32) $+ : $gettok(%lifes,%pk,46)
  230.     inc %pk
  231.   }
  232.   msg %chan 3 Current Lives : %display
  233.   unset %display
  234. }
  235.  
  236. alias -l getout {
  237.   if ( $istok(%lifes,0,46) ) {
  238.     getinfo %tplayer
  239.     set %correct $gettok(%corr,%turn,46)
  240.     set %cg $calc(%cg + %correct)
  241.     set %wg $calc(%wg + 3)
  242.     set %corr $deltok(%corr,%turn,46)
  243.     makedata %tplayer
  244.     set %lifes $remtok(%lifes,0,0,46)
  245.     msg %chan 4 %tplayer has lost all their lives and is now out of the game, finishing with 10 coins. Adieu!  
  246. coins %tplayer 10
  247.     ignore -r %tplayer
  248.     set %players $remtok(%players,%tplayer,0,32)
  249.     set %playing $calc(%playing - 1)
  250.     set %turn $calc(%turn - 1)
  251.   }
  252.   if ( %playing == 1 ) {
  253.     timer 1 2 winner
  254.   }
  255.   else { continuegame }
  256. }
  257.  
  258. alias -l shuffle {
  259.   if ( $numtok(%cards,46) == 0 ) {
  260.     msg %chan 13 The other cards are being taken again and re-shuffled!
  261.     set %cards 2.3.4.5.6.7.8.9.10.J.Q.K.A
  262.     set %cards $remtok(%cards,%newcard,1,46)
  263. } }
  264. alias -l aiornot {
  265.   if ( $1 == $gettok(%AInames,1,32) ) {
  266.     var %highchance = 0
  267.     var %lowchance = 0
  268.     var %p = 1
  269.     while ( %p <= $numtok(%cards,46) ) {
  270.       set %curcard $gettok(%cards,%p,46)
  271.       set %curvalue $value(%curcard)
  272.       if ( %curvalue > $value(%newcard) ) { inc %highchance }
  273.       else { inc %lowchance }
  274.       inc %p
  275.     }
  276.     if ( %highchance > %lowchance ) {
  277.       go high
  278.     }
  279.     else {
  280.       go low
  281.     }
  282.   }
  283.   elseif ( $1 == $gettok(%AInames,2,32) ) {
  284.     set %newval $value(%newcard)
  285.     var %highchance = 14 - %newval
  286.     var %lowchance = %newval - 2
  287.     if ( %highchance > %lowchance ) {
  288.       go high
  289.     }
  290.     else {
  291.       go low
  292.     }
  293.   }
  294.   elseif ( $1 == $gettok(%AInames,3,32) ) {
  295.     set %y $rand(1,2)
  296.     if ( %y == 1 ) {
  297.       go high
  298.     }
  299.     else {
  300.       go low
  301.     }
  302.   }
  303. }
  304. alias -l winner {
  305.   set %winner $gettok(%players,1,32)
  306.   msg %chan 10 $gettok(%players,1,32) has won the game with %lifes lives remaining, earning 25 coins.
  307. coins %winner 25
  308.   ignore -r %winner
  309.   getinfo %players
  310.   set %correct %corr
  311.   set %cg $calc(%cg + %correct)
  312.   set %wg $calc(3 - %lifes)
  313.   inc %mgw
  314.   makedata %players
  315.   end
  316. }
  317. alias -l end {
  318.   timers off
  319.   ignore -r
  320.   unset %players %ongoing %turn %tplayer %multi %playing %ai %life %lifes %m %hilo %o %corr
  321.   set %game over
  322. }
  323.  
  324. alias -l continuegame {
  325.   if ( %game == $null ) {
  326.     inc %turn
  327.     if ( %turn > %playing ) {
  328.       set %turn 1
  329.       ignoreall
  330.     }
  331.     set %tplayer $gettok(%players,%turn,32)
  332.     msg %chan 10 Its %tplayer 's turn to continue. They may choose to go !high or go !low .
  333.     ignore -r %tplayer
  334.     timer 1 20 gone
  335.     aiornot %tplayer
  336.   }
  337. }
  338.  
  339. alias -l getnewcard {
  340.   if ( $numtok(%cards,32) == 0 ) {  shuffle }
  341.   set %oldcard %newcard
  342.   set %total $numtok(%cards,46)
  343.   set %x $rand(1,%total)
  344.   set %newcard $gettok(%cards,%x,46)
  345.   %cards = $deltok(%cards,%x,46)
  346. }
  347. alias -l getai {
  348.   var %i = 1
  349.   while ( %i <= 3 ) {
  350.     set %ai $gettok(%AInames,%i,32)
  351.     set %players %players %ai
  352.     inc %i
  353.   }
  354.   set %players $gettok(%players,1- $+ %playing $+ ,32)
  355.   msg %chan 9 AI Player(s) have joined the game.
  356. }
  357. on *:TEXT:!join*:#: {
  358.   if ( %playing != $null ) && ( %joining == on ) {
  359.     if ( $nick isin %players ) { notice $nick You are already playing. }
  360.     elseif ( $istok(%AInames,$nick,32) ) { notice $nick You cannot use that nickname. }
  361.     else {
  362.       getinfo $nick
  363.       inc %mgp
  364.       makedata $nick
  365.       msg %chan 3 $nick has joined the game.
  366.       set %players %players $nick
  367.       if ( $numtok(%players,32) == %playing ) {
  368.         msg %chan 13 The game may be started now.
  369.         set %joining off
  370.         timers off
  371.         start
  372. } } } }
  373.  
  374. alias -l timeup {
  375.   msg %chan 10 Time is up!
  376.   if ( $numtok(%players,32) == 0 ) {
  377.     msg %chan 10 Nobody has joined. Game is turning off.
  378.     unset %playing
  379.     unset %multi
  380.     end
  381.   }
  382.   else {
  383.     getai
  384.     set %joining off
  385.     start
  386.   }
  387. }
  388.  
  389. alias -l start {
  390.   set %turn 1
  391.   set %tplayer $gettok(%players,1,32)
  392.   set %lifes $left(3.3.3.3, $+ $calc(2 * %playing - 1))
  393.   set %corr $replace(%lifes,3,0)
  394.   set %total $numtok(%cards,46)
  395.   set %x $rand(1,%total)
  396.   set %oldcard $gettok(%cards,%x,46)
  397.   %cards = $deltok(%cards,%x,46)
  398.   set %newcard %oldcard
  399.   msg %chan 4,0♥ $+ %oldcard 4,010 has been chosen! 12 cards remaining.
  400.   msg %chan 6 Its %tplayer 's turn to start the game. They may choose to go !high or go !low .
  401.   timer 1 20 gone
  402. }
  403.  
  404. alias -l gone {
  405.   msg %chan 4 %tplayer ran out of time to make a choice and loses a life.
  406.   ignoreall
  407.   %life = $gettok(%lifes,%turn,46)
  408.   set %life $calc(%life - 1)
  409.   set %lifes $deltok(%lifes,%turn,46)
  410.   set %lifes $instok(%lifes,%life,%turn,46)
  411.   showlifes
  412.   getout
  413. }
  414. alias -l ignoreall {
  415.   var %pq = 1
  416.   while ( %pq <= %playing ) {
  417.     if ( $1 == $null ) { ignore $gettok(%players,%pq,32) }
  418.     else { ignore -r $gettok(%players,%pq,32) }
  419.     inc %pq
  420.   }
  421. }
  422.  
  423. alias getinfo {
  424.   if ( $istok(%AInames,$1,32) ) { return }
  425.   elseif (!$read(hilo.txt,w,* $+ $1 $+ * ) ) { write hilo.txt $1 0 0 0 0 0 0 | getinfo $1 }
  426.   set %info $read(hilo.txt,w,* $+ $1 $+ * )
  427. set %in $gettok(%info,1,32)
  428.   set %mgp $gettok(%info,2,32)
  429.   set %mgw $gettok(%info,3,32)
  430.   set %cg $gettok(%info,4,32)
  431.   set %wg $gettok(%info,5,32)
  432.   set %sgp $gettok(%info,6,32)
  433.   set %hs $gettok(%info,7,32)
  434. }
  435.  
  436. alias -l makedata {
  437.   if ( $istok(%AInames,$1,32) ) { return }
  438.   set %todel $read(hilo.txt,w,* $+ $1 $+ * )
  439.   set %no $readn $+
  440.   write -dl $+ %no hilo.txt
  441.   write hilo.txt $1 %mgp %mgw %cg %wg %sgp %hs
  442.  
  443. }
  444.  
  445. alias -l coins {
  446. if ( $istok(%AInames,$1,32) ) { return }
  447.   elseif ($read(coins.txt,w,* $+ $1 $+ *)) {
  448.     set %n $readn $+
  449.     set %data $read(coins.txt,w,* $+ $1 $+ *)
  450.     set %current $gettok(%data,2,32)
  451.     set %new $calc(%current + $2)
  452.     set %data $replace(%data,%current,%new)
  453.     write -dl $+ %n coins.txt
  454.     write coins.txt %data
  455.   }
  456.   else {
  457.     write coins.txt $1 $2
  458.   }
  459. }
  460.  
  461.  
  462. on *:TEXT:!stats*:#: {
  463.   if ( $2 == $null) { return }
  464.   getinfo $2
  465.   msg $chan 6 Hi-Lo Stats for %in :
  466.   msg $chan 10⚔Multiplayer:11 ❂Games Played:6 %mgp 11 ✬Games Won:6 %mgw 11 ☠Guesses (9☑/4☒): 6 %cg $+ / $+ %wg
  467.   msg $chan 10☃Solo:11 ♙Games Played:6 %sgp 11 ❆Highest Score:6 %hs
  468. }
Add Comment
Please, Sign In to add comment