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.

I made a high/low game script.

Support & discussion of released scripts, and announcements of new releases.
Post Reply
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

I made a high/low game script.

Post by Justdabomb2 »

I couldn't find one by anyone else, so I made my own.
Should I submit it to the archive?

I am working on adding a "scoreboard" to the script, so should I hold off on submitting untill I make one, or just submit it and update it later?
Yeah!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

If it's not really huge, maybe post it here for review/testing before submitting to the archive?
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

Post by Justdabomb2 »

And yes Rosc I made this completely on my own, from scratch. My friend Rolcol gave me some cool suggestions on some things I should add to it though, like the random messages for winning and guessing wrong, and an easier to go about getting a random number. And before I submit to the archive, I just got a good idea to let people change the high number though a public command when they start it. So here is the code, test it for me, and tell me what you think. Thanks.

Code: Select all

##########################################
##                                      ##
##  Author: Justdabomb2                 ##
##  Script: High Low                    ##
##  Version: v1.0                       ##
##  Date: 10/12/2006                    ##
##                                      ##
##         Thanks for the great         ##
#           suggestions Rolcol!         ##
##                                      ##
##########################################

############################################################
## Set this to the highest number your bot can pick from. ##
############################################################

set highestnumber "999"

######################################################################
## Random messages the bot will use when you get the correct guess. ##
######################################################################

set correctmsgs {
  "Good job!"
  "Congratulations!"
  "Wowzers!"
  "Great Guess!"
  "Good work!"
  "Outstanding!"
  "Now win again!"
}

#########################################################################
## Random messages your bot will use when you make an incorrect guess. ##
#########################################################################

set incorrectmsgs {
  "Sorry"
  "Too bad,"
  "Try again,"
  "Incorrect guess,"
  "Keep trying"
}

######################################################
## You don't need to edit anything below this line. ##
######################################################

set hlinuse 0
set correctnumber ""
set hlcreator "Justdabomb2"
set hlturnedoff "High Low has been turned off by"
set hlnoton "9High Low1 is not currently on."
set hlalreadyoff "9High Low1 is already off."
set hlinvalidguess "Your guesses must be bewteen3,1 1 0,1and7,1"
set hlalreadyon "9High Low1 is already on."
set hlnumberstoguess "1The numbers vary from3 1 1to7"
set hlturnedon "9High Low14 has been turned on by"
set hlcommand "Type !guess <number>"

bind pub - !hlon hl:on
bind pub - !guess hl:guess
bind pub - !hloff hl:off

proc hl:on {nick uhost hand chan args} {
  global hlinuse correctnumber hlcreator hlalreadyon highestnumber hlturnedon hlcommand hlnumberstoguess
  if { $hlinuse == 0 } {
    set hlinuse 1
    set correctnumber [rand $highestnumber]
    putquick "PRIVMSG $chan :9,1High Low8,14 By: $hlcreator" 
    putquick "PRIVMSG $chan :$hlturnedon 10$nick14. $hlcommand to guess a number." 
    putquick "PRIVMSG $chan :$hlnumberstoguess $highestnumber1." 
    } else {
    putquick "PRIVMSG $chan :$hlalreadyon"
  }
}

proc hl:guess {nick uhost hand chan args} {
  global hlinuse correctnumber highestnumber hlnoton hlinvalidguess correctmsgs incorrectmsgs hlcommand
  set correctmsg [lindex $correctmsgs [rand [llength $correctmsgs]]]
  set incorrectmsg [lindex $incorrectmsgs [rand [llength $incorrectmsgs]]]
  if { $hlinuse == 1 } {
    	set guess [lindex $args 0]
    if { [string tolower $guess] == [string tolower $correctnumber] } {
      set hlinuse 0
      putquick "PRIVMSG $chan :10$nick13 got the correct guess of 12$correctnumber13. $correctmsg"
    }
    if { [string tolower $guess] > [string tolower $correctnumber] } {
      	putquick "PRIVMSG $chan :7$incorrectmsg 10$nick7. Your guess of $guess was too high. Try a lower number."
    }
    if { [string tolower $guess] < [string tolower $correctnumber] } {
      	putquick "PRIVMSG $chan :3$incorrectmsg 10$nick3. Your guess of $guess was too low. Try a higher number."
    }
    if { [string tolower $guess] > [string tolower $highestnumber] } {
      	putquick "NOTICE $nick :0,1$hlinvalidguess $highestnumber."
    }
    } else {
    putquick "PRIVMSG $chan :1Sorry 10$nick,1 $hlnoton"
  }
  	if {$guess == ""} {
    	putquick "NOTICE $nick :0,1$hlcommand"
  }
}

proc hl:off {nick uhost hand chan args} {
  global hlinuse hlturnedoff hlalreadyoff
  if { $hlinuse == 1 } {
    set hlinuse 0
    putquick "PRIVMSG $chan :4$hlturnedoff 10$nick."
    } else {
    putquick "PRIVMSG $chan :1Sorry 10$nick,1 $hlalreadyoff"
  }
}

putlog "Justdabot's High Low Script Loaded"
Yeah!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Couple of suggestions: Set the !guess bind when you run !hlon and unset the bind when you do !hloff, otherwise you get an error from the !guess command when the game is not active:
Tcl error [hl:guess]: can't read "guess": no such variable

When you use color codes in puthelp/putquick/putserv it might be better to use the \003<code> syntax, rather than a literal ^C (control-c) because when I cut and pasted the script for testing, my paste ate the control codes (small problem, and obviously would not be an issue if the script was directly downloaded rather than cut/pasted.)

Perhaps limit the number of guesses people can make, so they're not just spamming guesses, and if you're going to have a score file, there should probably be a limit otherwise obviously someone would always win.

Another test you could use would be [string is integer] to see if input was actually a number, and give an error msg if it's not a number. You don't really need the [string tolower] for numbers.

And last suggestion, tabulate properly :P

Code: Select all

if {something} {
            do this (1 tab)
} else {
            do that (1 tab)
            if {something else} {
                     so forth and so on (2 tabs)
             }
}
Makes things easier to read, and to debug, cos it's easier to see where functions, subfunctions and nested tests begin and end. It'll be very useful when you have many layers of nested tests.

Other than those suggestions, it's pretty good for a beginning script. =)
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Colour and formatting codes

Justdabomb2: Following the above guide you will be able to fix your script.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
m
metroid
Owner
Posts: 771
Joined: Wed Jun 16, 2004 2:46 am

Post by metroid »

rosc2112 wrote:

Code: Select all

if {something} {
            do this (1 tab)
} else {
            do that (1 tab)
            if {something else} {
                     so forth and so on (2 tabs)
             }
}
IMO, that's way too many spaces.

Code: Select all

if {something} {
  do this (2 spaces)
} else {
  do that (2 spaces)
  if {something else} {
    so forth and so on (4 spaces)
  }
}
This looks much better to me, and it's easier to read.
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Well, yeah, my tabs were a little exaggerated in the example :)

I usually have my tabs set at 8 spaces (although 4 is pretty common too, and some editor programs allow you to define your tabs, so 2 or even variable number of spaces are possible. I've seen editor programs that allow you to start the 1st tab at 8 spaces, the 2nd tab at 4, then 2, so that you're not using like 200+ columns at the 3rd, 4th, 5th tab, etc.)

Tabs make it easier to move around (at least for me, using arrow-keys to move left and right columns), as opposed to using spaces, but just a difference of style really.
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

Post by Justdabomb2 »

Alchera wrote:Colour and formatting codes

Justdabomb2: Following the above guide you will be able to fix your script.
Umm, I already know how to use those, but I edit my scripts in mIRC script editor becuase I was too lazy to uninstall that client and then I got an eggdrop and the script editor helps me a lot, with spacing, and replacing text. So it's easiest for me to just use the ctrl+commands, sorry. Next scripts that I share I will use the editor to replace those.
Yeah!
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

newest update

Post by Justdabomb2 »

I made a few updates and additions to it, it should run a little more smoothly and I added some new things so that you can say like !hl on 100
and it would be on a random number in 100. I also made it so that you can set a global variable to the lowest random number a user can have the bot pick from, and also the highest number so that the bot won't have any glitchy problems (like if someone tries !hl on 1000000000000000000 or something). So, test this update and tell me what you think. Thanks guys.

Code: Select all

##########################################
##                                      ##
##  Author: Justdabomb2                 ##
##  Script: High Low                    ##
##  Version: v1.0                       ##
##  Date: 10/16/2006                    ##
##                                      ##
##         Thanks for the great         ##
#           suggestions Rolcol!         ##
##                                      ##
##########################################

#######################################################################
## Set this to the highest number you want to be able to guess from. ##
#######################################################################

set highestnumber "100000"

###################################################################
## Set this to the lowest number you want to be able guess from. ##
###################################################################

set lowestnumber "10"

######################################################################
## Random messages the bot will use when you get the correct guess. ##
######################################################################

set correctmsgs {
  "Good job!"
  "Congratulations!"
  "Wowzers!"
  "Great Guess!"
  "Good work!"
  "Outstanding!"
  "Now win again!"
}

#########################################################################
## Random messages your bot will use when you make an incorrect guess. ##
#########################################################################

set incorrectmsgs {
  "Sorry"
  "Too bad,"
  "Try again,"
  "Incorrect guess,"
  "Keep trying"
}

######################################################
## You don't need to edit anything below this line. ##
######################################################

set hlinuse 0
set numbertouse ""
set correctnumber ""
set hlcreator "Justdabomb2"
set hlturnedoff "High Low has been turned off by"
set hlnoton "\0039High Low\0031 is not currently on."
set hlalreadyoff "\0039High Low\0031 is already off."
set hlinvalidguess "Your guesses must be bewteen"
set hlinvalidnumber "Please use a number between"
set hlalreadyon "\0039High Low\0031 is already on."
set hlnumberstoguess "\0031The numbers vary from\0033 \0021\002 \0031to\0037"
set hlturnedon "\0039High Low\00314 has been turned on by"
set hlguesscommand "Type \002!guess <number>\002"
set hlcommand "Type \002!hl on <highest number>.\002"
set hloncommand "on"
set hloffcommand "off"

bind pub - !hl hl:activate
bind pub - !guess hl:guess

proc hl:activate {nick uhost hand chan arg} {
  global hlinuse correctnumber hlcreator hlalreadyon numbertouse highestnumber lowestnumber hlturnedon hlcommand hlguesscommand hlnumberstoguess hloncommand hloffcommand hlturnedoff hlalreadyoff hlinvalidnumber
  set command [lindex $arg 0]
  if {$command == ""} {
    putquick "NOTICE $nick :\0030,1Type $hlcommand"
  }
  if {[string tolower $command] == [string tolower $hloncommand]} { 
    if { $hlinuse == 0 } {
      set numbertouse [lindex $arg 1]
      if {[string tolower $numbertouse] < [string tolower $lowestnumber]} { 
        putquick "NOTICE $nick :\0030,1I won't use that number, it is too low. $hlinvalidnumber $lowestnumber and $highestnumber."
        return
      }
      if {[string tolower $numbertouse] > [string tolower $highestnumber]} { 
        putquick "NOTICE $nick :\0030,1I won't use that number, it is too high. $hlinvalidnumber $lowestnumber and $highestnumber."
        return
      }
      if {$numbertouse == ""} {
        putquick "NOTICE $nick :\0030,1Type $hlcommand"
        } else {
        set hlinuse 1
        set correctnumber [rand $numbertouse]
        putquick "PRIVMSG $chan :\0039,1High Low\0038,14 By: $hlcreator" 
        putquick "PRIVMSG $chan :$hlturnedon \00310$nick\00314. $hlguesscommand to guess a number." 
        putquick "PRIVMSG $chan :$hlnumberstoguess \002$numbertouse\002\0031." 
      }
      } else {
      putquick "PRIVMSG $chan :$hlalreadyon"
    }
  }
  if {[string tolower $command] == [string tolower $hloffcommand]} { 
    if { $hlinuse == 1 } {
      set hlinuse 0
      set numbertouse ""
      putquick "PRIVMSG $chan :\0034$hlturnedoff \00310$nick."
      } else {
      putquick "PRIVMSG $chan :\0031$hlalreadyoff"
    }
  }
}

proc hl:guess {nick uhost hand chan args} {
  global hlinuse correctnumber numbertouse hlnoton hlinvalidguess correctmsgs incorrectmsgs hlguesscommand lowestnumber
  set correctmsg [lindex $correctmsgs [rand [llength $correctmsgs]]]
  set incorrectmsg [lindex $incorrectmsgs [rand [llength $incorrectmsgs]]]
  if { $hlinuse == 1 } {
    	set guess [lindex $args 0]
    if { [string tolower $guess] == [string tolower $correctnumber] } {
      set hlinuse 0
      putquick "PRIVMSG $chan :\00310$nick\00313 got the correct guess of \002\00312$correctnumber\00313\002. $correctmsg"
    }
    if { [string tolower $guess] > [string tolower $correctnumber] } {
      	putquick "PRIVMSG $chan :\0037$incorrectmsg \00310$nick\0037. Your guess of \002$guess\002 was too \002high\002. Try a lower number."
    }
    if { [string tolower $guess] < [string tolower $correctnumber] } {
      	putquick "PRIVMSG $chan :\0033$incorrectmsg \00310$nick\0033. Your guess of \002$guess\002 was too \002low\002. Try a higher number."
    }
    if { [string tolower $guess] > [string tolower $numbertouse] } {
      	putquick "NOTICE $nick :\0030,1$hlinvalidguess \0033,1 \002$lowestnumber\002 \0030,1and\0037,1 \002$numbertouse\002."
    }
    } else {
    putquick "PRIVMSG $chan :\0031Sorry \00310$nick,\0031 $hlnoton"
  }
  	if {$guess == ""} {
    	putquick "NOTICE $nick :\0030,1$hlguesscommand"
  }
}

putlog "Justdabot's High Low Script Loaded"

P.S.
I am not very good at .txt files (as rosc knows ;) XD) so if you think a score board would be a good idea, you can help me out with it.
Last edited by Justdabomb2 on Tue Oct 17, 2006 10:43 pm, edited 1 time in total.
Yeah!
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

Justdabomb2 wrote:
Alchera wrote:Colour and formatting codes

Justdabomb2: Following the above guide you will be able to fix your script.
Umm, I already know how to use those, but I edit my scripts in mIRC script editor becuase I was too lazy to uninstall that client and then I got an eggdrop and the script editor helps me a lot, with spacing, and replacing text. So it's easiest for me to just use the ctrl+commands, sorry. Next scripts that I share I will use the editor to replace those.
Tcl scripts should be saved using UTF-8 encoding i.e. no weird end of line characters being added.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

Post by Justdabomb2 »

well, I didn;t add that score board thing anyways, it's probably better I didn't, cuz poeple might play alone just to boost scores and start on the lowest possible... but whatever.

You can find the latest version at:

http://www.egghelp.org/tclhtml/3478-4-0 ... abomb2.htm
Yeah!
Post Reply