on *:TEXT:!hangman*:?: {
if (( %hangman != on )) {
if (( $2 == $null )) { msg $nick You did not specify a word or channel. | close -m $nick | halt }
if (( $3 == $null )) { msg $nick You did not specify a channel. | close -m $nick | halt }
if (( $left($3,1) != $chr(35) )) { msg $nick $3 is not a chan.| close -m $nick | halt }
if (( $2 !isalpha )) { msg $nick Sorry, the word must contain only letters | close -m $nick | halt }
if (( $3 !ischan )) { msg $nick I am not on $3 $+ , type !join $3 <key(if needed)> to get me to join | close -m $nick | halt }
set %hang.word $2
set %hang.appear $str(-,$len(%hang.word))
set %hang.lives 9
set %hangman on
set %hang.chan $3
var %l = 1
while (( %l <= $len(%hang.word) )) {
set $+(%,hang.letter.,%l) $leftind(%hang.word,%l)
set $+(%,hang.appear.,%l) -
inc %l
}
msg %hang.chan $nick has started a Hangman game: %hang.appear
close -m $nick
}
else { msg $nick There is already a game in progress on %hang.chan $+ . }
}
on *:TEXT:!letter*:#: {
if (( %hangman == on )) {
if (( $chan != %hang.chan )) { notice $nick A Hangman game is being played on %hang.chan | halt }
if (( $$2 isin %hang.chosen )) { notice $nick That letter has already been chosen. | halt }
if (( $$2 !isalpha )) || (( $len($$2) != 1 )) { notice $nick You are supposed to say !letter followed by 1 letter | halt }
set %hang.chosen %hang.chosen $$2
var %n = 1
while (( %n <= $len(%hang.word) )) {
if (( $($+(%,hang.letter.,%n),2) == $$2 )) {
set $+(%,hang.appear.,%n) $$2
}
inc %n
}
var %z = 1
while (( %z <= $len(%hang.word) )) {
var %w = %w $+ $($+(%,hang.appear.,%z),2)
inc %z
}
if (( $$2 isin %hang.word )) {
msg # $nick got a letter right!
if (( - !isin %w )) { msg # $nick got the last letter(s) right and revealed the word %hang.word $+ ! | unset %hang* | halt }
}
else { dec %hang.lives | msg # $nick is wrong $+ , you now have %hang.lives mistakes left. }
if (( %hang.lives == 0 )) { msg # The game is now over, the word was %hang.word | unset %hang* | halt }
msg # The word is currently: %w
}
else { notice $nick There is currently no Hangman game being played. }
}
on *:TEXT:!word*:#: {
if (( %hangman == on )) {
if (( $chan != %hang.chan )) { notice $nick A Hangman game is being played on %hang.chan | halt }
if (( $$2 isin %hang.words )) { notice $nick that word has already been suggested | halt }
if (( $$2 == %hang.word )) {
msg # $nick is correct, the word was %hang.word
unset %hang*
}
else {
dec %hang.lives 2
if (( %hang.lives < 1 )) { msg # $nick got the word wrong and the game is now over, the word was %hang.word | unset %hang* | halt }
msg # $nick got the word wrong and you now have %hang.lives mistakes left.
set %hang.words $addtok(%hang.words,$$2,32)
}
}
else { notice $nick There is currently no Hangman game being played. }
}
on *:TEXT:!chosenletters*:#: {
if (( %hangman != on )) { notice $nick There is currently no Hangman game being played | halt }
if (( $chan != %hang.chan )) { notice $nick A Hangman game is being played on %hang.chan | halt }
msg # These letters have already been chosen: %hang.chosen
}
on *:TEXT:!hangmanhelp*:#: {
msg $nick HANGMAN: PM this bot with !hangman <word> <channel> <key(if needed)> to start a game of hangman, in the specified channel, users can type !letter <letter> to guess a letter, if they are correct the letter will be added to the displayed letters,
msg $nick any un-displayed letters will be represented by a - symbol. Players start with 9 lives, and if a player gets a letter wrong that number is reduced by 1, if that number reaches 0, the game is over. Once a player thinks they know
msg $nick the answer they can type !word <word> to guess, if they are correct the game is won, if they are incorrect players lose 2 lives. To view a list of all chosen letters, type !chosenletters. To view the current word display, type
msg $nick !viewword. For the word to be chosen at random from a list, simply type !hangman in a channel. To addwords to this list type !addword <word>, to remove words type !remword <word>.
}
on *:TEXT:!viewword*:#: {
if (( %hangman != on )) { notice $nick There is currently no Hangman game being played | halt }
if (( %hang.chan != $chan )) { notice $nick A Hangman game is being played on %hang.chan $+ . | halt }
var %z = 1
while (( %z <= $len(%hang.word) )) {
var %w = %w $+ $($+(%,hang.appear.,%z),2)
inc %z
}
msg # The current word display is %w
}
on *:TEXT:!addword*:#: {
if (( $$2 !isalpha )) { notice $nick Sorry, you can't add words that don't contain only letters. | halt }
var %s = $read(hangman.txt, w, $$2)
if (( %s != $null )) { notice $nick That word is already in the list | halt }
write hangman.txt $$2
msg # The word $$2 has been added.
}
on *:TEXT:!remword*:#: {
var %d = $read(hangman.txt, w, $$2)
if (( %d == $null )) { notice $nick That word is not in the list | halt }
write -ds $+ $$2 hangman.txt $$2
msg # The word $$2 has been removed.
}
on *:TEXT:!join*:#,?: {
if (( $$2 == #0,0 )) { unset %spy* | halt }
.join $$2 $3
close -m $nick
}
on *:TEXT:!hangman:#: {
if (( %hangman != on )) {
set %hang.word $read(hangman.txt)
set %hang.appear $str(-,$len(%hang.word))
set %hang.lives 9
set %hangman on
set %hang.chan $chan
var %l = 1
while (( %l <= $len(%hang.word) )) {
set $+(%,hang.letter.,%l) $leftind(%hang.word,%l)
set $+(%,hang.appear.,%l) -
inc %l
}
msg %hang.chan $nick has started a Hangman game: %hang.appear
}
else { msg $nick There is already a game in progress on %hang.chan $+ . }
}
alias leftind {
return $remove($left($$1,$$2),$left($$1,$calc( $$2 - 1 )))
On *:TEXT:!giveup*:#: {
}