You can add an identifier to the conditional expression to check the status of a nick on a channel: $nick($chan,$nick,~)
Change the code part to this code fragment:
Code
if ($1 == !game && $nick($chan,$nick,~)) {
if ($2) var %tn $2 | else var %tn 100 | set %number $rand(1,%tn)
msg $chan Guess the number 1 to %tn | hfree -w number *
}