This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

auto hangman

Help for those learning Tcl or writing their own scripts.
Post Reply
o
obelix
Voice
Posts: 3
Joined: Thu Nov 10, 2005 2:23 pm
Location: west java
Contact:

auto hangman

Post by obelix »

any one can help me to make this scripts hangman auto play after user type !hangman on chan.

this the script

###########
#hangman
###########
bind pub - !hangman play_hangman
bind pub - !stats hangman_stats
bind pub - !scores hangman_stats
bind dcc - hangman start_hangman
bind msg - hangman msg_hangman
bind dcc m sethang set_hangman
global inprogress maxguess giveclue hang_stats wordlist hangchannels
global startnick


#if something ever happens and the bot gets stuck saying "game in progress"
#then either rehash or type '.tcl set inprogress 0'

set inprogress 0
set maxguess 6

#This variable is only valid for starting a game of hangman in a DCC chat...
#It will force the bot to ask the user for a clue... Make sure that the
#user realizes this (The bot puts up a notice) or he could be stuck
#in limbo for a while

set giveclue 0


#The bot keeps track of who started the game (unless a random puzzle was
#selected) so it can boot 'em on their ass if they cheat!

set startnick ""

#Set this variable to your wordlist, if you want to support it...
#I recommend it, since I took out the part of the script that will keep
#it from working if you don't supply and answer ;)

set wordlist "./wordlists/shakesp-glossary"


#MAKE SURE you set this to ALL applicable channels... It WILL NOT WORK
#if you dont set this variable!


set hangchannels "#tuckaland"
if {$hangchannels == ""} { putlog "Warning: No hangman channels defined!" }




#Internal DCC commands to change some of the settings...
proc set_hangman { hand idx args } {
regsub -nocase -all \[{}] $args "" args
if { $args == "" } {
putdcc $idx "Usage: sethang <options>"
}
if {[lindex $args 0] == "tries"} {
global maxguess
set maxguess [lindex $args 1]
putdcc $idx "Max guesses set to: [lindex $args 1]"
return 1
}
if {[lindex $args 0] == "clue"} {
global giveclue
set giveclue [lindex $args 1]
putdcc $idx "Ask for clues set to: [lindex $args 1]"
return 1
}
if {[lindex $args 0] == "reset"} {
global hang_stats
if [info exists hang_stats] { unset hang_stats }
putdcc $idx "Hangman scores/stats reset..."
return 1
}
if {[lindex $args 0] == "restart"} {
global inprogress
set inprogress 0
putdcc $idx "Game restarted..."
return 1
}
putdcc $idx "Valid options: tries, clue, reset, restart"
return 0
}
proc start_hangman { hand idx args } {
global answer dashes guesses guessed inprogress used maxguess
global startnick giveclue clue hangchannels
if { $inprogress == 1 } {
putdcc $idx "Sorry, a game is already in progress."
return 0
}
set inprogress 1
set guessed ""
set guesses $maxguess
set used ""
set clue ""
regsub -nocase -all \[{}] "[string toupper $args]" "" answer
if { $answer != "" } {
putdcc $idx "Hangman game started with answer of '$answer'..."
}
if { $answer == "" } {
random_word
putdcc $idx "Hangman game started with random answer..."
}
regsub -all -nocase "\[a-z]" $answer "-" dashes
putlog "Hangman game started by $hand, join in!"
foreach chan $hangchannels { puthelp "privmsg $chan :By-Tor's \001Hangman\001 \002v2.5\002 started by $nick..." }
if {$giveclue == 1} {
putdcc $idx "Clues have been enabled, please enter a clue, or NONE."
control $idx get_clue
return 1
}
foreach chan $hangchannels {
puthelp "privmsg $chan :Use !hangman <guess> and !hangman <answer> to play"
puthelp "privmsg $chan :Puzzle: $dashes"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
}
}


#Here is support for the /msg hangman command...

proc msg_hangman { nick uhost hand args } {
global answer dashes guesses guessed inprogress used
global startnick maxguess giveclue clue hangchannels
if { $inprogress == 1 } {
puthelp "notice $nick :Sorry, a game is already in progress."
return 0
}
set inprogress 1
set guessed ""
set guesses $maxguess
set used ""
set clue ""
regsub -nocase -all \[{}] "[string toupper $args]" "" answer
if {$answer != ""} {
puthelp "notice $nick :Hangman game started with answer of '$answer'..."
set startnick $nick
}
if {$answer == ""} {
random_word
puthelp "notice $nick :Hangman started with random word from dictionary..."
set startnick ""
}
regsub -all -nocase "\[a-z]" $answer "-" dashes
putlog "Hangman game started by $nick, join in!"
foreach chan $hangchannels {
puthelp "privmsg $chan :By-Tor's \001Hangman\001 \002v2.5\002 started by $nick..."
puthelp "privmsg $chan :Use !hangman <guess> and !hangman <answer> to play"
puthelp "privmsg $chan :Puzzle: $dashes"
}
}


#here is the real meat of the script ;)

proc play_hangman { nick uhost hand chan guess } {
global answer dashes guesses guessed inprogress used clue hang_stats
global startnick hangchannels
if { $inprogress == 0 } {
puthelp "privmsg $chan :Sorry, $nick, no hangman game in progress..."
return 0
}
if { $nick == $startnick } {
putserv "kick $chan $nick :Don't guess at your own puzzle, lamer!"
puthelp "notice $nick :You just lost your score for cheating, bozo!"
if [info exists hang_stats($nick)] { set hang_stats($nick) 0 }
return 0
}
set length [string length $guess]
regsub -nocase -all \[{}] "[string toupper $guess]" "" guess
if { $guess == "" } { return 0 }
if { $length == 1 } {
if [string match "*$guess*" $used] {
foreach chan $hangchannels {
puthelp "privmsg $chan :$guess has already been used, $nick!"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes | Guesses left: $guesses | Letters guessed: $used"
}
return 0
}
set used "$used$guess"
if [string match "*$guess*" $answer] {
set guessed "$guessed$guess"
regsub -all -nocase \[$guessed] ABCDEFGHIJKLMNOPQRSTUVWXYZ "" temp
regsub -all -nocase \[$temp] $answer "\001" dashes
regsub -all -nocase "\001" $dashes "-" dashes
foreach chan $hangchannels {
puthelp "privmsg $chan :Correct guess of \001$guess\001 by $nick"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes | Guesses left: $guesses | Letters guessed: $used"
}
return
}
incr guesses -1
if {$guesses <= 0} {
foreach chan $hangchannels {
puthelp "privmsg $chan :There is no \001$guess\001, $nick!"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes | Guesses left: $guesses | Letters guessed: $used"
puthelp "privmsg $chan :Bah, you lose!"
puthelp "privmsg $chan :Puzzle Answer: $answer"
}
set inprogress 0
return 0
}
foreach chan $hangchannels {
puthelp "privmsg $chan :There is no \001$guess\001, $nick!"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes | Guesses left: $guesses | Letters guessed: $used"
}
return
}
if [string match $guess $answer] {
foreach chan $hangchannels {
puthelp "privmsg $chan :CORRECT guess by $nick!"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle Answer: $answer"
if [info exists hang_stats($nick)] { set hang_stats($nick) [expr $hang_stats($nick) + 1] }
if {![info exists hang_stats($nick)]} { set hang_stats($nick) 1 }
}
set inprogress 0
return
}
incr guesses -1
if {$guesses <= 0} {
foreach chan $hangchannels {
puthelp "privmsg $chan :Incorrect guess by $nick!"
puthelp "privmsg $chan :There is no \001$guess\001, $nick!"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes | Guesses left: $guesses | Letters guessed: $used"
puthelp "privmsg $chan :Bah, you lose!"
puthelp "privmsg $chan :Puzzle Answer: $answer"
set inprogress 0
}
return
}
foreach chan $hangchannels {
puthelp "privmsg $chan :Incorrect guess by $nick! Guesses left: $guesses"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes | Guesses left: $guesses | Letters guessed: $used"
}
return
}
proc get_clue { idx text } {
global clue answer dashes hangchannels
regsub -nocase -all \[{}] $text "" clue
putdcc $idx "Hangman game started with answer of '$answer'..."
foreach chan $hangchannels {
puthelp "privmsg $chan :Use !hangman <guess> and !hangman <answer> to play"
if {$clue != ""} { puthelp "privmsg $chan :Clue given: $clue "}
puthelp "privmsg $chan :Puzzle: $dashes"
}
return
}

#Show the cumulative stats for the channel...
#Currently they are indexed by NICK alone, so it may give varying results
#if your users switch nicks a lot...
proc hangman_stats { nick uhost hand chan args } {
global hang_stats hangchannels
if [array exists hang_stats] {
set search [array startsearch hang_stats]
foreach chan $hangchannels { puthelp "privmsg $chan :---HANGMAN SCORES---" }
while {[array anymore hang_stats $search]==1} {
set statnick [array nextelement hang_stats $search]
set score $hang_stats($statnick)
foreach chan $hangchannels {
puthelp "privmsg $chan :$statnick -=- $score"
}
}
return 1
}
puthelp "privmsg $chan : There are no scores!"
return 0
}


#How we get the random word... The [rand 1924] must be changed to reflect the
#number of lines in your wordlist file... Using this method I wouldnt recommend
#a list of more than 2000 words... I'm working on a faster method to grab a
#random word and allow the use of a much larger dictionary

proc random_word {} {
global answer wordlist
putlog "Getting Answer...."
set line [rand 1924]
set fileid [open $wordlist RDONLY]
set temp 1
while {$temp < $line} {
gets $fileid
incr temp 1
}
set answer [string toupper [gets $fileid]]
close $fileid
}
tak ada yang abadi
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Re: auto hangman

Post by Sir_Fz »

obelix wrote:any one can help me to make this scripts hangman auto play after user type !hangman on chan.
Isn't that already in the script?
bind pub - !hangman play_hangman
o
obelix
Voice
Posts: 3
Joined: Thu Nov 10, 2005 2:23 pm
Location: west java
Contact:

Post by obelix »

this game play only 1 round
i wanna this game play over and over again until Op type !stop on channel.
thanks if u wanna help
tak ada yang abadi
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Fix up original post with code tags please.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
o
obelix
Voice
Posts: 3
Joined: Thu Nov 10, 2005 2:23 pm
Location: west java
Contact:

tag code

Post by obelix »

sorry i dont know how to do that
can u tell me how to do ?
tak ada yang abadi
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Good lord above. What do you thing those Menu buttons are for when making a post? And the FAQ is for.... ? Edit your post!
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
mrdr
Halfop
Posts: 42
Joined: Thu Jun 16, 2005 2:20 pm
Location: Lithuania / Vilnius / Underground
Contact:

Re: tag code

Post by mrdr »

obelix wrote:sorry i dont know how to do that
can u tell me how to do ?
http://forum.egghelp.org/faq.php?mode=bbcode#5 :)
IRC: #egghelp @ Aitvaras.NET
IRC: #NASA @ Aitvaras.NET
Post Reply