I haven't tested it, but try this...
Code:
on 1:text:*guess*:#: {
  if ($1 == %c $+ guess) {
    if (%mnum == $null) { msg $chan I'm not thinking of a number yet. | halt }
    if ($2 !isnum 1000-9999) { msg $chan Enter a number between 1000 and 9999 | halt }
    if ($2 == %mnum) { 
      msg $chan That's right! %mnum $+ ! You win, $nick $+ ! And it only took %counter guesses. Type !mastermind to start a new guessing game.
      unset %mnum | halt
    }
    if ($2 != %mnum) { 
      inc %counter
      var %gfnum = $mid($2, 1, 1), %gsnum = $mid($2, 2, 1), %gtnum = $mid($2, 3, 1), %ghnum = $mid($2, 4, 1)
      var %correct = 0, %close = 0
      var %numbers = $+(%fnum,.,%snum,.,%tnum,.,%hnum)
      if (%gfnum == %fnum)      { inc %correct | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum == %snum)      { inc %correct | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum == %tnum)      { inc %correct | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum == %hnum)      { inc %correct | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      if (%gfnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gfnum,1,46) }
      if (%gsnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gsnum,1,46) }
      if (%gtnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%gtnum,1,46) }
      if (%ghnum isin %numbers) { inc %close | var %numbers = $remtok(%numbers,%ghnum,1,46) }
      msg $chan You have %correct correct.
      msg $chan You have %close out of place.
    }
  }
}


P.S. You may want to use $rand(1000,9999) to set %mnum, since now your number will never contain zeros, unless that is you intention. If that is indeed your intention, then you should probably change your statement where you check if the input isnum 1000-9999 to also check for "if (0 !isin $$2)" or people may be trying with zeros for ages.

Last edited by 5618; 27/01/09 07:04 PM.