0

I have a bunch of code for a blackjack game script on mIRC. Everything is running fine, but when a user starts a game of blackjack, no one else can play until that game finishes.

I was wondering if someone could help me out with coding it so that I can give user a 45 second timer between each action; if they time out, the script will reset, opening up the script for another user to play. This will void the game that's in use.

The code for the game is below.

;BLACKJACK
on *:TEXT:!blackjack*:#vegas:{
  if (%bj == on) {
/msg $chan 10Blackjack is already in progress. Please wait your turn.
halt
  }
if ( %hs [ $+ [ $nick ] ] != $null ) /notice $nick 10 $+ $nick $+ , you have a game in progress!!!
if ( %hs [ $+ [ $nick ] ] == $null ) {
if ( $2 == $null ) /notice $nick 10Please enter amount you want to bet. ex. !blackjack 20
if ($readini( casino.ini, $nick, Money ) == $null ) /notice $nick 10 $+ $nick is not yet registered.  Type !atm
if ( $readini( casino.ini, $nick, Money ) < $2 ) /notice $nick 10You don't have that much money...try something lower!
if ( $readini( casino.ini, $nick, Money ) >= $2 ) {
  if ( $2 < 1 ) {
    /notice $nick 10Please bet more than 1 dollar.
    halt
  }
  if ( $2 > 0 ) {

    /set %bj on

    /set %bet [ $+ [ $nick ] ] $2

    /bjdeal

    /msg $chan 10 $+ $nick bet $2 dollars on a hand of blackjack

    /var %cch = $rand(1,4)

    if ( %cch == 1) /msg $chan 10 $+ $nick $+ 's hand: 4,0 %hcard1 [ $+ [ $nick ] ]  4,0 %hcard2 [ $+ [ $nick ] ] 

    if ( %cch == 2) /msg $chan 10 $+ $nick $+ 's hand: 4,0 %hcard1 [ $+ [ $nick ] ]  1,0 %hcard2 [ $+ [ $nick ] ] 

    if ( %cch == 3) /msg $chan 10 $+ $nick $+ 's hand: 1,0 %hcard1 [ $+ [ $nick ] ]  4,0 %hcard2 [ $+ [ $nick ] ] 

        if ( %cch == 4) /msg $chan 10 $+ $nick $+ 's hand: 1,0 %hcard1 [ $+ [ $nick ] ]  1,0 %hcard2 [ $+ [ $nick ] ] 

    if (( %hcard1 [ $+ [ $nick ] ] == A ) && ( %hcard2 [ $+ [ $nick ] ] == A )) {
      /set %addh [ $+ [ $nick ] ] 12
      /set %aceh [ $+ [ $nick ] ] 0
    }
    if (( %hcard1 [ $+ [ $nick ] ] == A ) || ( %hcard2 [ $+ [ $nick ] ] == A )) { /set %aceh [ $+ [ $nick ] ] 0 }
    /set %ccc [ $+ [ $nick ] ] $rand(1,2)
    if ( %ccc [ $+ [ $nick ] ] == 1) /msg $chan 10Dealer's hand: 4,0 %ccard1 [ $+ [ $nick ] ]  12,0 ? 
    if ( %ccc [ $+ [ $nick ] ] == 2) /msg $chan 10Dealer's hand: 1,0 %ccard1 [ $+ [ $nick ] ]  12,0 ? 
    if ( %addh [ $+ [ $nick ] ] == 21 ) {
      /set %bj [ $+ [ $nick ] ] $calc( $2 / 2 )
      /set %bj [ $+ [ $nick ] ] $calc( %bj [ $+ [ $nick ] ] + $2 )
      /msg $chan 4Blackjack!! $nick has won %bj [ $+ [ $nick ] ] dollars!!
      /set %bj.temp $calc( $readini( casino.ini, $nick, Money ) + %bj [ $+ [ $nick ] ] )
      /writeini casino.ini $nick Money %bj.temp
      /unset %bj.temp
      /unset %hs [ $+ [ $nick ] ]
      /unset %bet [ $+ [ $nick ] ]
      /unset %addh [ $+ [ $nick ] ]
      /unset %addc [ $+ [ $nick ] ]
      /unset %hcard1 [ $+ [ $nick ] ]
      /unset %hcard2 [ $+ [ $nick ] ]
      /unset %ccard1 [ $+ [ $nick ] ]
      /unset %ccard2 [ $+ [ $nick ] ]
      /unset %hcard3 [ $+ [ $nick ] ]
      /unset %ccard3 [ $+ [ $nick ] ]
      /unset %bj [ $+ [ $nick ] ]
      /unset %aceh [ $+ [ $nick ] ] 
      /unset %double [ $+ [ $nick ] ]
      /unset %bj
      /halt
    }
    if ( %addh [ $+ [ $nick ] ] != 21 ) {
      set %double [ $+ [ $nick ] ] $calc( %bet [ $+ [ $nick ] ] * 2)
      if ( $readini( casino.ini, $nick, Money ) >= %double [ $+ [ $nick ] ] ) {
        /msg $chan 10 Hit Stand or Double?
        /set %d [ $+ [ $nick ] ] 0
        /set %hs [ $+ [ $nick ] ] 0
        /halt
      }
      if ( $readini( casino.ini, $nick, Money ) < %double [ $+ [ $nick       ]     ] ) 
{
            /msg $chan 10 Hit or Stand?
        /set %hs [ $+ [ $nick ] ] 0
        /halt
      }
    }
  }
    }
  }
}
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453

1 Answers1

0

One way to do this is to start a timer which will unset your variables when X amount of time has passed. For example:

on *:TEXT:!blackjack*:#vegas:{
 if ($timer(blackjack)) {
    ; the timer exists so a game is already in progress
  }
  else {
    ; start the timer
    startblackjacktimer        
    ; put your code here
    
  }
}
 alias startblackjacktimer {
  ; change 45 to amount of seconds
  ; this alias will start a timer to call 'resetblackjack'
  .timerblackjack 1 45 resetblackjack
 }
alias resetblackjack {
 ; do your variable reset here
}

For each command they can do you have to restart the timer by triggering the startblackjack alias again.

If you have any more questions, feel free to ask them.

Community
  • 1
  • 1
Denny
  • 1,766
  • 3
  • 17
  • 37