Hangman v1.0

By Callison1 on May 31, 2007

It is a HangMan game meant for a bot but would work on an actual nick too. It allows users to open a query with the bot/person and type !hangman <key(if needed)> and a game of HangMan will start in that channel.

Type !hangman on it's own in a channel to start a game with a random word from a text file, it will select a word from a file called hangman.txt, remember to create that and put some words in there, !addword will add words to the list and !remword will remove. Use !hangmanhelp for more info.

Everything is explained under the command !hangmanhelp

Any ideas for improvement at all?

REMEMBER TO CREATE hangman.txt IN THE SAME DIRECTORY AS THE mIRC CLIENT YOU ARE USING THIS SCRIPT ON.

ALSO: When putting words into the file manually, you have to type each word on a new line.

Thanks

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* | inc $+(%,$nick,.hangwords) | halt }
    }
    else { dec %hang.lives | msg # $nick is wrong $+ , you now have %hang.lives mistakes left. | inc $+(%,$nick,.hangwasted) }
    if (( %hang.lives == 0 )) { msg # The game is now over, the word was %hang.word | unset %hang* | inc $+(%,$nick,.hanglost) | 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
      inc $+(%,$nick,.hangwords)
      unset %hang*
    }
    else {
      dec %hang.lives 2
      inc $+(%,$nick,.hangwasted) 2
      if (( %hang.lives == -1 )) { dec $+(%,$nick,.hangwasted) }
      if (( %hang.lives < 1 )) { msg # $nick got the word wrong and the game is now over, the word was %hang.word | inc $+(%,$nick,.hanglost) | 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>. Type !hangstats to view your stats or !hangstats <nick> to view that nick's stats.
}
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 $+ . }
}
on *:TEXT:!hangwords*:#: {
  msg # In the random words list for hangman, there is currently $lines(hangman.txt) words.
}
on *:TEXT:!hangstats*:#: {
  if (( $2 == $null )) { var %n = $nick }
  else { var %n = $2 }
  if (( $($+(%,%n,.hangwasted),2) == $null )) { set $+(%,%n,.hangwasted) 0 } | if (( $($+(%,%n,.hangwords),2) == $null )) { set $+(%,%n,.hangwords) 0 } | if (( $($+(%,%n,.hanglost),2) == $null )) { set $+(%,%n,.hanglost) 0 }
  notice $nick Stats for %n
  notice $nick Mistakes Made: $($+(%,%n,.hangwasted),2)
  notice $nick Games Won: $($+(%,%n,.hangwords),2)
  notice $nick Games Lost: $($+(%,%n,.hanglost),2)
}
alias leftind {
  return $remove($left($$1,$$2),$left($$1,$calc( $$2 - 1 )))
}

Comments

Sign in to comment.
Scakk   -  Sep 05, 2007

So it looks like the below

on *:TEXT:!remword*:#: {
  if ($2 !isalpha) { notice $nick Words on the list only contains letters. | halt }
  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.
}
 Respond  
Scakk   -  Sep 05, 2007

I added

  if ($2 !isalpha) { notice $nick Words on the list only contains letters. | halt }

to the below

on *:TEXT:!remword*:#: {
  var %d = $read(hangman.txt, w, $$2)
  if (%d !isalpha) { msg $chan Words on the list only contains letters. | halt }
  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.
}

Since it allowed \" !remword \" to actually remove \" \"

 Respond  
bvalis   -  Jul 02, 2007

nothing else about what i\'ve write to you? :)

 Respond  
Callison1   -  Jun 21, 2007

Okey =)

 Respond  
bvalis   -  Jun 21, 2007

ok. i will test it and send my reply!
ty again

 Respond  
Callison1   -  Jun 21, 2007

Ignore that link, I have updated this snippet (and fixed the bugs in the snippet i sent you Bvalis) so any more feedback would be appreciated.

 Respond  
bvalis   -  Jun 21, 2007

good job!

 Respond  
Callison1   -  Jun 20, 2007

Sorry I forgot about this snippet and didn\'t check it, thanks for the Private Message highlighting the same subject bvalis.

 Respond  
bvalis   -  Jun 18, 2007

it\'s great!!!but a 4.0 score isn\'t enough. this is what i need and maybe you get a bigger score. why don\'t you do a statistic for the player: how many word they get, how many word they don\'t how many lives they waste.. things like that. it will be huge! ty keep up the good work!

 Respond  
Callison1   -  Jun 05, 2007

Right, now there is 2 ways to play the game, you can type !hangman in a pm, or you can simply type !hangman in the channel and it will be randomly picked from the text file.

 Respond  
Callison1   -  Jun 05, 2007

Hmmm...2 separate snippets

 Respond  
|MELIORITE|   -  Jun 04, 2007

The active channel will the one where the bot/snippet is located and the game is requested. I was suggesting take out the invitations to join particular channels on the snippet, so it will be played either in chans where bot is active, and instead have a separate request bot snippet.... just an idea to avoid the complicatios of query msgs to commence games where the bot/snippet is not available in the chan requested.

 Respond  
Callison1   -  Jun 04, 2007

As it allows users to choose their own word to start the game with, it is activated by Query Message, so there is no active channel (unless I have misunderstood)

 Respond  
Callison1   -  Jun 03, 2007

Also the query window now always closes after processing the hangman request.

 Respond  
Callison1   -  Jun 03, 2007
                     ---UPDATE---

I changed it so that if you are not on the channel the person specifies it tells them how to get you to join.

 Respond  
Callison1   -  Jun 01, 2007

It is as if the $nick in the if statement in the line responsible as working as it would do with $me

 Respond  
|MELIORITE|   -  May 31, 2007

I like the work you have done on this snippet.

 Respond  
Callison1   -  May 31, 2007

Thankyou for the help on $read i have corrected that now.

I put the if\'s separately so that I could put separate messages etc for each (if there is a simpler way please tell me)

I put (( )) in all my scripts because it works the same and i find it easier to read.

 Respond  
Daveoh   -  May 31, 2007

In regards to the $read, just use a wildcard search - $read(hangman.txt,w,$2) (will match exactly that word as the line)
Quite a few /if\'s can be removed by using &\'s in the matchtext for on TEXTs such as the first one which could be !hangman & &
There is no need for (( )) for the conditionals of the /if\'s (can use 1 or 0 () in some cases)

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.