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.

wordgame

Help for those learning Tcl or writing their own scripts.
Post Reply
d
drfox
Voice
Posts: 26
Joined: Sun Oct 09, 2005 1:51 am

wordgame

Post by drfox »

hi guys
is there away to stop this game using flags as i dont want to be adding everyone who wants to play it to the bots user file but i want each user to have there own scores saved but at the min i have to add them to the bots user list and give them a f flag
thanx in advance for ya help

Code: Select all

##################  Written by Murf 10/10/97 ##################
##                                                           ##
## Requires wordlist.txt and wscore file                     ##
## I have included a wordlist file, but if you want to write ##
## your own, the format is                                   ##
## <word to scramble>:<clue>                                 ##
##                                                           ##
##                                                           ##
##                                                           ##
##  The only  commands are:                                  ##
##                                                           ##
##  !word       -- starts the game                           ##
##  !wordscore  -- spews the top ten scorers                 ##
##  !wordswitch -- turns it on or off                        ##
##  !wordanswer -- turn the answer on or off                 ##
##           Check www.blueday.org/eggdrop.html              ##
##           Contact murf@mindless.com with questions        ##
###############################################################


###############################################################
##
## GeoWord: An enhanced version of Murf's word game.
## By: Pistos  irc.freenode.net:6667 #geoshell
## 2003 09 29
##
###############################################################

## NOTES

# Scores are kept globally
# Scores are only kept for those in the bot's user list.
# The special user used to track various things, is added
#   by the script.

## REVISION HISTORY

# Mar 26 2002   --  Fixed adding new channel
# Dec 18 2000   --  Fixed the score again. It was totally broken, not listing
#                   anything close to the top 10 scorers
#               --  fixed problem with possible duplicate entries in the score
#                   file is users change case of their nicks
# July 9 2000   --  Added switch to say/not say the answer if no one gets it.
#				--  Got rid of all the 'putchan's
# July 2 2000 	-- 	Fixed bug in the_score that didn't account for
# 					less than 10 people in the score list.
#				--	Fixed bug in the_score that failed to check for
#					non-existent score file.

## BINDS

#Change the f|f if you want.

bind pub - !wordscore the_score
bind pub - !word pub_word
bind time - "05 03 % % %" wo_refresh_time
bind msg m !wordswitch word_onoff
bind msg m !wordanswer answer_onoff

## VARIABLES, set these.

# This is the file that holds the wordlist, set it to whatever
set wlistfile /home/doc/eggdrop/scripts/wordlist.txt

# This file keeps scores again call it whatever
set wscorefile /home/doc/eggdrop/scripts/wordscore.dat

# This special user is added to the bots userlist and used to track
# where each chan is in the wordlist
set specuser specialwd

# Say the answer if no one gets it
# 0 is don't say it / 1 is say it
set ansonoff 1

## ----------------Leave the rest alone----------------------------------

# This variable tells whether the script is being run.  It will only allow
# the game to be played in one channel at a time, otherwise too many timers
# too much confusion.
# Occasionally, the script may become confused during desynchs and says its
# running when it isn't. You must reset this variable to 0. Don't worry
# it doesnt happen often.  Obviously leave it set to 0 here
set winuse 0

# This variable is the place in the wordlist.  Its initialized to 0 don't
# mess with it.  I tried randomizing this, but found this worked better,
# but its not hard to randomize if you like that better.
set word_list_count 0

# On off switch for the annoying people
# 0 is off/ 1 is on
set glonoff 1

# Global channel variable, initialized to null, leave alone
set chan ""

# Initializes global wordlist to null, leave it alone
set words ""

set num_revealed 0
set initial_point_value 100
set point_value 100
set last_winner ""
set consecutive_wins 1
set ignored_player ""
set max_wins 3

# ----------CODE--------------------------------------------------------

# Procedure to turn on/off whether the answer is given if no one
# gets it.
proc answer_onoff {nick uhost handle args} {
  global ansonoff botnick
  set onoff [string tolower [ string trim [lindex [split $args] 0] "{}" ]]
  if {$onoff == "on"} {
 	set ansonoff 1
	putserv "NOTICE $nick :Wordgame will now tell you losers the answers ;-P"
	return
	}
  if {$onoff == "off"} {
	set ansonoff 0
	putserv "NOTICE $nick :Wordgame will no longer tell you losers the answers"
	return
	}
   putserv "NOTICE $nick :USAGE: /msg $botnick !wordanswer on\/off"
   return
}

# Had to add an on off switch cause some pple started annoying me
proc word_onoff {nick uhost handle args} {
  global botnick glonoff
  set onoff [string tolower [ string trim [lindex [split $args] 0] "{}" ]]
  if {$onoff == "on"} {
 	set glonoff 1
	putserv "NOTICE $nick :Wordgame is turned on"
	return
	}
  if {$onoff == "off"} {
	set glonoff 0
	putserv "NOTICE $nick :Wordgame is turned off"
	return
	}
   putserv "NOTICE $nick :USAGE: /msg $botnick !wordswitch on\/off"
   return
}

proc generate_words {nick uhost handle num_words max_length} {
   global botnick chan
   if {$num_words > 300} {
      set num_words 300
   }
   if {$max_length < 4} {
      set max_length 4
   }
   #exec java -cp /rznas GenerateWordList geowordlist.txt 233378 current_wordlist.txt $num_words $max_length
}

# This is the main proc, it spews the word and sets the timers to do the
# rest.

proc pub_word {nick uhost handle channel args} {
   global wscorefile wlistfile words word_list_count answer winuse \
chan letters specuser glonoff num_revealed part_of_speech num_syllables definition def_shown point_value initial_point_value etymology
   if {$glonoff == 0} {
	putserv "PRIVMSG $channel :Sorry, wordgame is turned off, try again later"
	return
   }

   set chn [string tolower $channel]

   if {$word_list_count == 0} {
       if {![validuser $specuser]} {
          set channels [channels]
          adduser $specuser specuser!special@word.special.org
          foreach chann $channels {
             setuser $specuser XTRA wcount.$chann 0
          }
       }
       set word_list_count [getuser $specuser XTRA wcount.$chn]
       if {$word_list_count == ""} {
          setuser $specuser XTRA wcount.$chn 0
          set $word_list_count 0
       }
       set words ""
       set fd [open $wlistfile r]
       while {![eof $fd]} {
          lappend words [gets $fd]
       }
       close $fd
   }

   if {($winuse == 1) && ([string compare $chn $chan] != 0)} {
      putserv "PRIVMSG $chn :Sorry, they're already playing in $chan, go join in. I'll tell em your coming, $nick."
      return 0
   } elseif {($winuse == 1) && ([string compare $chn $chan] == 0)} {
        putserv "PRIVMSG $chan :I can only display one word at a time."
        return 0
   } elseif {$winuse == 0} {
      kill_timers
      set num_revealed 0
      set chan $chn
      set winuse 1

      # Parse single line from word list.

      #set word_pair [lindex $words $word_list_count]
      #set answer [lindex [split $word_pair :] 1]
      #set word_split [split $word_pair :]
      #set letters [lreplace $word_pair 1 1]
      #set letters [lindex $words $word_list_count]

      set line [lindex $words $word_list_count]
      set line_elements [split $line _]
      set letters [lindex $line_elements 0]
      set num_syllables [lindex $line_elements 1]
      set part_of_speech [lindex $line_elements 2]
      set etymology [lindex $line_elements 3]
      set definition [lindex $line_elements 4]
      set def_shown 0
      set point_value $initial_point_value

      # Mix up the letters

      set let_split [split $letters {}]
      set i [llength $let_split]
      set smixed ""
      set tmixed ""
      for {set j 0} {$j < $i} {incr j} {
        set k [rand [llength $let_split]]
        set smixed $tmixed
        set smixed [lappend smixed [lindex $let_split $k]]
        set let_split [lreplace $let_split $k $k]
        regsub { } $smixed {} tmixed
      }
      set mixed $tmixed
      bind pub - $letters pub_gotit
      putserv "PRIVMSG $chan :Unscramble ...4 $mixed "
      incr word_list_count
      if {$word_list_count >= [expr [llength $words] -1]} {
         set word_list_count "0"
      }
      setuser $specuser XTRA wcount.$chn $word_list_count

      # Set the timers to reveal the clues.

      utimer 90 noone_gotit
      utimer 15 clue_1
      utimer 20 clue_2
      utimer 25 clue_3
      utimer 40 clue_4
      utimer 55 clue_5
   }

}

# All the timers expired and no one got it. Spew to chan.

proc noone_gotit {} {
   global winuse chan letters ansonoff
   if {$ansonoff} {
     putserv "PRIVMSG $chan :Nobody solved it in time.  The word was $letters"
   } else {
     putserv "PRIVMSG $chan :No one solved it in time."
   }
   unbind pub - $letters pub_gotit
   set winuse 0
   set chan ""
}

# List of things to say when a validuser wins

set winsay {
"you must be really smart."
"do you read the dictionary in your spare time?"
"you rock!"
"you rule!"
"you're amazing."
"you're awesome!"
"you're great!"
"you're stupendous!"
"you must be on fire!!"
"a true genius at work."
"impressive."
"how'd you manage that feat?"
"let's have a round of applause!"
"good job."
"good work."
"good show."
"smashing, baby, yeah."
"shouldn't you be working?"
}

# Somebody won, spew to chan and update score file. Scores are kept for both
# daily and cumulative.  Once anyone hits 500 all scores are reset.

proc pub_gotit {nick uhost handle channel args} {
   global wscorefile words letters answer winuse chan winsay num_revealed point_value \
        initial_point_value definition def_shown ignored_player consecutive_wins last_winner max_wins

   if {$nick == $ignored_player} {
       putserv "PRIVMSG $nick :You've already won $consecutive_wins times in a row!  Give some other people a chance."
       return 0
   }

   kill_timers

   putserv "PRIVMSG $chan :8$nick 0got it ...4 $letters 0... for8 $point_value 0points."

   if {$nick == $last_winner} {
       incr consecutive_wins
       putserv "PRIVMSG $chan :$consecutive_wins wins in a row!"
       if {$consecutive_wins > $max_wins} {
           set ignored_player $nick
           putserv "PRIVMSG $chan :$nick's guesses will be ignored in the next game."
       }

   } else {
       set consecutive_wins 1
       set ignored_player ""
   }

   set last_winner $nick

   if {!$def_shown} {
        putserv "PRIVMSG $chan :Definition ...4 $definition"
   }

   unbind pub - $letters pub_gotit
   if {![validuser $handle]} {
     putserv "PRIVMSG $chan :Invalid user -- $handle -- assuming $nick"
     if {![validuser $nick]} {
        set winuse 0
        set chan ""
        return 0
     }
     set handle $nick
   }
   if {![file exists $wscorefile]} {
	set fd [open $wscorefile w]
	close $fd
   }
   set fd [open $wscorefile r]
   set j 0
   while {![eof $fd]} {
     lappend score [gets $fd]
     set j [incr j]
   }
   set i [expr $j - 1]
   set score [lreplace $score $i $i]
   close $fd
   for {set k 0} {$k < $i} {incr k 3} {
     set scnick [lindex $score $k]
     if {[string tolower $handle] == [string tolower $scnick]} {

        # Get today's score
        set newd [expr [lindex $score [expr $k + 1]] + $point_value]

        # Get all-time score
        set newf [expr [lindex $score [expr $k + 2]] + $point_value]

        # Replace scores in memory buffer
        set score [lreplace $score [expr $k + 1] [expr $k + 2] $newd $newf]

        # Give win count for today.
        set dscore [lindex $score [expr $k + 1]]
        set rand_say [lindex $winsay [rand [llength $winsay]]]
        putserv "PRIVMSG  $chan :4$nick 0you have $dscore points for today - $rand_say"

        if {$newf > 10000} {
          putserv "PRIVMSG $chan :$scnick has scored 10000 points since time began!"
          set score [lreplace $score 1 2 0 0]
          for {set k 1} {$k < $i} {incr k 2} {
            set score [lreplace $score $k $k 0]
	    incr k
            set score [lreplace $score $k $k 0]
          }
          putserv "PRIVMSG $chan :\001ACTION resets the scores.\001"
        }

        set winuse 0
        set chan ""

        # Rewrite score file.

        set fd [open $wscorefile w]
        foreach line $score {
          puts $fd $line
        }
        close $fd

        return 0
     }
   }
   putserv "PRIVMSG $chan :$nick this is your first ever win!  Congratulations."
   set score [lappend score $handle]
   # daily
   set score [lappend score $point_value]
   # all-time
   set score [lappend score $point_value]
   set fd [open $wscorefile w]
     foreach line $score {
       puts $fd $line
     }
   close $fd
   set winuse 0
   set chan ""
}

proc the_score {nick uhost handle channel args} {
  global botnick wscorefile words winuse chan
  if {($winuse == 1) && ($chan == $channel)} {
    putserv "PRIVMSG $chan :(Game in progress.)"
  return 0
  }
  if {![file exists $wscorefile]} {
    putserv "PRIVMSG $chan : No one has scored yet!"
    return
  }

   set fd [open $wscorefile r]
   set j 0
   while {![eof $fd]} {
     lappend score [gets $fd]
	 incr j
   }
   set i [expr $j - 1]
   set score [lreplace $score $i $i]
   close $fd
   set looptest [llength $score]
   for {set k 0} {$k < $looptest} {incr k 3} {
      set wosnick [lindex $score $k]
      set dscore [lindex $score [expr $k + 1]]
      set fscore [format "%d" [lindex $score [expr $k + 2]]]
      lappend tempsortscore [format "%.20d %d %s" $fscore $dscore $wosnick]
   }
   set tempsortscore [lsort -decreasing $tempsortscore]
   set sortscore ""
   for {set i 0} {$i < 10} {incr i} {
      set tiscore [lindex $tempsortscore $i]
      set newtempsortscore [string trimleft [lindex $tiscore 0] 0]
      #putserv "PRIVMSG Pistos :tiscore - $tiscore -- newtss - $newtempsortscore"
      if {$newtempsortscore != ""} {
        append sortscore [format "%s\. %s\(%d\/%d\)  " [expr {$i + 1}] [lindex $tiscore 2] $newtempsortscore [lindex $tiscore 1]]
      }
   }

   set slength [llength $sortscore]
   putserv "PRIVMSG $channel :The top 10 Scramble scorers are (Total/Today):"
   putserv "PRIVMSG $channel :$sortscore"
}

# Give part of speech

proc clue_1 {} {
   global chan part_of_speech point_value initial_point_value
   set clue $part_of_speech
   set point_value [expr int($initial_point_value * 0.95)]
   putserv "PRIVMSG $chan :Part of speech ...4 $clue"
}

# Give etymology

proc clue_2 {} {
   global chan etymology point_value initial_point_value
   set clue $etymology
   set point_value [expr int($initial_point_value * 0.90)]
   putserv "PRIVMSG $chan :Etymology ...4 $clue"
}

# Give number of syllables

proc clue_3 {} {
   global chan num_syllables point_value initial_point_value
   set clue $num_syllables
   set point_value [expr int($initial_point_value * 0.85)]
   putserv "PRIVMSG $chan :Number of syllables ...4 $clue"
}

# Give the first letter.

proc clue_4 {} {
   global chan letters num_revealed point_value initial_point_value
   set clue [string range $letters 0 $num_revealed]
   incr num_revealed
   set point_value [expr int($initial_point_value * 0.70)]
   putserv "PRIVMSG $chan :Begins with ...4 $clue"
}

# Give definition

proc clue_5 {} {
   global chan definition def_shown point_value initial_point_value
   set clue $definition
   set def_shown 1
   set point_value [expr int($initial_point_value * 0.40)]
   putserv "PRIVMSG $chan :Definition ...8 $clue"
}

# Kill all remaining timers when someone wins.

proc kill_timers {} {
   global chan
   foreach j [utimers] {
     if {[lindex $j 1] == "noone_gotit"} {
        killutimer [lindex $j 2]
     }
     if {[lindex $j 1] == "clue_1"} {
        killutimer [lindex $j 2]
     }
     if {[lindex $j 1] == "clue_2"} {
        killutimer [lindex $j 2]
     }
     if {[lindex $j 1] == "clue_3"} {
        killutimer [lindex $j 2]
     }
     if {[lindex $j 1] == "clue_4"} {
        killutimer [lindex $j 2]
     }
     if {[lindex $j 1] == "clue_5"} {
        killutimer [lindex $j 2]
     }
   }
   return 0
}

# Its 3:00 am, clear the daily scores.

proc wo_refresh_time {m h d mo y} {
  global wscorefile
  set fd [open $wscorefile r]
  set j 0
  while {![eof $fd]} {
     lappend score [gets $fd]
     set j [incr j]
    }
  set i [expr $j - 1]
  set score [lreplace $score $i $i]
  close $fd
  set score [lreplace $score 1 1 0]
  for {set k 1} {$k < $i} {incr k 3} {
     set score [lreplace $score $k $k 0]
  }
  set fd [open $wscorefile w]
  foreach line $score {
      puts $fd $line
  }
  close $fd
  return 1
}

putlog "GeoWord by Pistos (original wordgame by murf) loaded"
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

There is no requirement for anyone that wishes to play this game to be added to the bot as a user with any flag!

The only requirement for a user to have access to the bot is as a bot master:

Code: Select all

bind msg m !wordswitch word_onoff
bind msg m !wordanswer answer_onoff
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
Linux
Halfop
Posts: 71
Joined: Sun Apr 04, 2004 4:20 pm
Location: Under The Sky

Post by Linux »

for more about flags and their functions type .help whois in your bot's partyline and read it.
second thing, this is published script better post such topic in Script Support & Releases
I'm an idiot, At least this one [bug] took about 5 minutes to find...
d
drfox
Voice
Posts: 26
Joined: Sun Oct 09, 2005 1:51 am

Post by drfox »

ok guys so can you tell me y if there not added to bots user file with a flag they get this on a correct answer [9:57pm] <13@Scramble> Invalid user -- * -- assuming Snow_Fox
nod no score is saved but if i add them to the bots user list that dosent come upand a score is saved.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Linux wrote:for more about flags and their functions type .help whois in your bot's partyline and read it.
second thing, this is published script better post such topic in Script Support & Releases
1) The query was more do with (here goes that swear word again!) READING!

2) I moved the topic here as this script is no longer supported (apparently) by the author; at least no one ever gets a response from him.

3) It's a very minor thing and falls within the definition of "Scripting Help".
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
Linux
Halfop
Posts: 71
Joined: Sun Apr 04, 2004 4:20 pm
Location: Under The Sky

Post by Linux »

Alchera wrote: 1) The query was more do with (here goes that swear word again!) READING!

2) I moved the topic here as this script is no longer supported (apparently) by the author; at least no one ever gets a response from him.

3) It's a very minor thing and falls within the definition of "Scripting Help".
Ok Boss :)
I'm an idiot, At least this one [bug] took about 5 minutes to find...
Post Reply