on *:TEXT:*:#: {
  if ($1 == !guess.stats) {
    msg # Game is currently: $+(,%game,)
    msg # Total words: $+(,$lines(wordguess.txt),)
    msg # Last person to win: $+(,%winner,) - Score: $+(,%score. [ $+ [ %winner ] ],)
    halt
  }
  if ($1- == !guess.start) && (%game == started) {
    msg # The game has already been started by %starter $+ .
    halt
  }
  else if ($1- == !guess.start) {
    set %game started
    set %word $read(wordguess.txt)
    set %starter $nick
    msg # Guessing game has been started by $+(,$nick,) $+ .
    msg # Type !guess <word> to guess the word! Type !hint to recieve a hint from me!
    timer 1 1 msg # The word is set. It has $len(%word) characters and begins with the letter $+(,$upper($left(%word,1)),) $+ . Start guessing!
    set %hint 2
  }
  else if ($1- == !guess.stop) && (%game != started) {
    msg # There is no game in progress. Type !guess.start to begin a game.
    halt
  }
  else if ($1- == !guess.stop) && ($nick == %starter) {
    msg # Guessing game ended by $nick $+ . Type !guess.start to start anew.
    unset %starter
    unset %hint
    unset %word
    set %game stopped
  }
  else if ($1- == !guess.stop) && ($nick != %starter) {
    msg $chan Only %starter can end this game $nick $+ .
    halt
  }
  else if ($1- == !guess.giveup) && ($nick == %starter) && (%word != $null) {
    msg # $nick gave up. The answer was $+(,%word,) $+ . This round was ended because $nick was the starter. Type !guess.start to start anew.
    unset %starter
    unset %hint
    unset %word
    set %game stopped
  }
  else if ($1- == !guess.giveup) && ($nick != %starter) && (%word != $null) {
    notice $nick You gave up. The answer was $+(,%word,) $+ . But the game is not over for the other players, so don't tell!
    set %giveup. [ $+ [ $nick ] ] $nick
    halt
  }
  if ($1- == !guess.hint) && (%hint >= $len(%word)) { msg # No more hints. | halt }
  else if ($1 == !guess.hint) && (%hint == 2) { inc %hint 1 | msg # Hint #1: First 2 Characters: $left(%word,2) }
  else if ($1 == !guess.hint) && (%hint == 3) { inc %hint 1 | msg # Hint #2: First 3 Characters: $left(%word,3) }
  else if ($1 == !guess.hint) && (%hint == 4) { inc %hint 1 | msg # Hint #3: First 4 Characters: $left(%word,4) }
  else if ($1 == !guess.hint) && (%hint == 5) { inc %hint 1 | msg # Hint #4: First 5 Characters: $left(%word,5) }
  else if ($1 == !guess.hint) && (%hint == 6) { inc %hint 1 | msg # Hint #5: First 6 Characters: $left(%word,6) }
  else if ($1 == !guess.hint) && (%hint == 7) { inc %hint 1 | msg # Hint #6: First 7 Characters: $left(%word,7) }
  else if ($1 == !guess.hint) && (%hint == 8) { inc %hint 1 | msg # Hint #7: First 8 Characters: $left(%word,8) }
  else if ($1 == !guess.hint) && (%hint == 9) { inc %hint 1 | msg # Hint #8: First 9 Characters: $left(%word,9) }
  else if ($1 == !guess.hint) && (%hint == 10) { inc %hint 1 | msg # Hint #9: First 10 Characters: $left(%word,10) }
  else if ($1- == !guess.hint) && (%hint > 10) { msg # No more hints. | halt }
  else if ($1 == !guess.score) && (%score. [ $+ [ $nick ] ] != $null) && ($2 == $null) {
    msg # Your current score is %score. [ $+ [ $nick ] ] $nick $+ .
    halt
  }
  else if ($1 == !guess.score) && (%score. [ $+ [ $2 ] ] != $null) && ($2 != $null) {
    msg # $2's current score is %score. [ $+ [ $2 ] ] $+ .
    halt
  }
  else if ($1 == !guess.score) && ($2 != $null) && (%score. [ $+ [ $2 ] ] == $null) { msg # $2 doesn't have a score for this game yet $nick $+ . | halt }
  else if ($1 == !guess.score) { msg # You don't have a score for this game yet $nick $+ . }
  else if ($1 == !guess) && ($2 != %word) {
    msg # That's not the word $nick $+ . Try again!
    halt
  }
  else if ($1 == !guess) && ($2 == $2) && ($nick == %giveup. [ $+ [ $nick ] ]) {
    msg $chan You cannot guess anymore $nick $+ . You already gave up.
    halt
  }
  else if ($1 == !guess) && ($2 == %word) {
    msg $chan $nick got the word correct and is awarded 1 point! Type !guess.start to start anew.
    unset %starter
    unset %word
    unset %hint
    set %game stopped
    set %winner $nick
    inc %score. [ $+ [ $nick ] ] 1
  }
}
