egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

auto hangman

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
obelix
Voice


Joined: 10 Nov 2005
Posts: 3
Location: west java

PostPosted: Thu Nov 10, 2005 2:45 pm    Post subject: auto hangman Reply with quote

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 Wink

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 Wink

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
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Thu Nov 10, 2005 7:25 pm    Post subject: Re: auto hangman Reply with quote

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?
Quote:
bind pub - !hangman play_hangman

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
obelix
Voice


Joined: 10 Nov 2005
Posts: 3
Location: west java

PostPosted: Thu Nov 10, 2005 11:09 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Nov 10, 2005 11:10 pm    Post subject: Reply with quote

Fix up original post with code tags please.
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
obelix
Voice


Joined: 10 Nov 2005
Posts: 3
Location: west java

PostPosted: Thu Nov 17, 2005 10:33 pm    Post subject: tag code Reply with quote

sorry i dont know how to do that
can u tell me how to do ?
_________________
tak ada yang abadi
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Nov 17, 2005 10:53 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
mrdr
Halfop


Joined: 16 Jun 2005
Posts: 42
Location: Lithuania / Vilnius / Underground

PostPosted: Fri Nov 18, 2005 6:32 am    Post subject: Re: tag code Reply with quote

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 Smile
_________________
IRC: #egghelp @ Aitvaras.NET
IRC: #NASA @ Aitvaras.NET
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber