off $*:text:/^[!@`.-]hangman/Si:*: {
if (%game) {
/notice $nick A game is already being played. To find the progress made, please type !progress
halt
}
/set %game on
/set %hang.chan $chan
/set %num $numtok(%words,46)
/set %word $rand(0,%num)
/set %word $gettok(%words,%word,46)
/set %numlet $len(%word)
/set %num 1
/set %totguess $round($calc($len(%word) * 1.4),0)
/set %hangman.time $rand(60,300)
.timerman.time 1 %hangman.time /hmlose
:a
if (%num > %numlet) { goto next | halt }
else {
/set %figured %figured _
/inc %num
goto a
halt
}
:next
/set %numguess 0
/msg # The word is12 %figured
/msg $chan You have used12 %numguess 1out of12 %totguess 1guesses.
/msg # To guess, type !guess LETTER
/msg # You have12 %hangman.time 1seconds to complete this game.
/breakapart %word
}
on *:text:!guess *:%hang.chan: {
if (%game) {
if ($len($2) > 1) { /notice $nick Please guess only 1 character | halt }
if ($istok(%guessed,$2,46)) { /notice $nick $2 has already been guessed | halt }
if (%numguess >= %totguess) { /notice $nick Please solve the word! | halt }
/inc %numguess
/set %guessed $addtok(%guessed,$2,46)
if ($istok(%bword,$2,46) == $true) {
/set %a 1
while ($findtok(%bword,$2,0,46) >= %a) {
/set %loco $findtok(%bword,$2,%a,46)
/set %figured $puttok(%figured,$2,%loco,32)
/inc %a
}
/msg $chan12 %figured
}
else {
/msg $chan 12 $2 1is not in the word. There have been12 %numguess 1out of the12 %totguess 1you get.
/msg $chan This is what you have done so far:12 %figured | halt
}
}
if (%numguess >= %totguess) {
/msg $chan You have used all12 %totguess 1guesses. To win, please type !solve <word you think it is>
}
else {
/msg $chan You have used12 %numguess 1out of12 %totguess 1guesses. Eigther solve the word, or guess again
/msg $chan This is what you have done so far:12 %figured
else {
/notice $nick No game in progress. Please type !hangman
}
}
}
alias endgame {
/unset %game
/unset %loco
/unset %figured
/unset %word
/unset %bword
/unset %guessed
/unset %numguess
/unset %totguess
/.%hangman.time off
}
on *:text:!solve *:%hang.chan: {
if (%game) {
/inc %numguess 1
if ($2 == %word) {
/msg $chan Yes!12 %word 1was the correct answer! To start another game, type !hangman
/endgame
}
else {
if (%numguess > %totguess) {
/msg $chan You unsucessfully guessed the word in 10 tries. The word was12 %word $+ 1. To start another game, type !hangman
/endgame
}
else {
/msg $chan Nope,12 $2 1is not the word. Keep guessing letters, or try to solve again. You have only used12 %numguess 1guesses.
/msg $chan This is what you have done so far:12 %figured
}
}
}
else {
/notice $nick Sorry, no game in progress! Type !hangman
}
}
on *:text:!progress:%hang.chan: {
if (%game) {
/msg $chan So far, with12 %numguess 1out of12 %totguess 1guesses, you have gotten12 %figured
}
else {
/notice $nick Sorry, no game in progress. Please type !hangman
}
}
alias breakapart {
var %idx = 0, %new
while (%idx < $len($1)) {
inc %idx
if (%new) {
%new = %new $+ . $+ $mid($1,%idx,1)
}
else {
/set %new $mid($1,%idx,1)
}
}
/set %bword %new
/unset %new
}
off *:text:!commands:%hang.chan: {
/notice $nick Commands: !hangman (To Start) !progress !solve <word> !guess <letter>
/notice $nick Word will be non-case sensitive. Only letters will be in the word. There might be a space in the word, which is denoted by a / (you may type !guess /)
}
alias addhangword {
if ($istok(%words,$1,46)) {
/echo -a $1 is already in the words
halt
}
/set %words $addtok(%words,$1,46)
/echo -a $1 has been added
}
alias delhangword {
if ($istok(%words,$1,46)) {
/set %words $remtok(%words,$1,1,46)
/echo -a $1 has been deleted
halt
}
/echo -a $1 is not in your word list
}
alias addchan {
if ($chr(35) !isin $1) { /echo -a Please enter a valid channel | halt }
if ($istok(%chans,$1,44)) {
/echo -a $1 is already in the channels
halt
}
/set %chans $addtok(%chans,$1,44)
/echo -a $1 has been added to the channels list. List of channels: %chans
}
alias delchan {
if ($istok(%chans,$1,44)) {
/set %chans $remtok(%chans,$1,1,44)
/echo -a $1 has been deleted. List of working channels: %chans
halt
}
/echo -a $1 is not in your channel list.
}
menu channel {
.Hangman
.Add word:/addhangword $?="What word do you want to add?"
.Delete word: /delhangword $?="What word do you want to delete?"
.View words: /set %w $replace(%words,.,$chr(44) $chr(32)) | echo -a Your words are %w | /unset %w
.Add channel: /addchan $?="What channel do you want to add?"
.Delete channel: /delchan $?="What channel do you want to delete?"
.View channels: /echo -a List of channels: %chans
}
alias hmlose {
/endgame
}