Your IP : 216.73.216.224


Current Path : /home/mudbot/eggdrop-keep/scripts/
Upload File :
Current File : //home/mudbot/eggdrop-keep/scripts/trivia_2000v2.3.tcl

#####################################################################################################
#                                                                                                   #
# "Trivia 2000" Version 2.3 �Ian-Highlander 2000-2007 (ian.highlander@eggdropsrus.co.uk)            #
# A Trivial Pursuit style game with seven queston categories available to choose from by public     #
# command, automatic host adding for tracking users scores, top ten scores command, multi question  #
# rounds, switchable answers, question number announcements and much more.                          #
#                                                                                                   #
# This script started life as a fun hobby for a chat room I was in many years ago and has become    #
# incredibly popular, after a break from the world of IRC I thought it was time I started the long  #
# promised updates. To say the popularity of this script was a surprise to me is an understatement, #
# even with no updates in four years it was still the seventh most popular script downloaded from   #
# egghelp.org's archives. The 1.3 update was downloaded nearly 500 times in a week which is gob     #
# -smacking to say the least. I am constantly emailed by people asking for updates and information  #
# which humbles me beyond words. Thanks for the support to everyone out there who uses my little    #
# scripts. I apologise for the length of this script header but there's so much to say :o)          #
# ------------------------------------------------------------------------------------------------- #
#                                                                                                   #
#     IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT IMPORTANT     #
#     =========================================================================================     #
# Due to major changes in the code of Trivia 2000 from version 2.2 onwards, this script will now    #
# only run on Eggdrop version 1.6.17 or higher due to new commands implented in that version that   #
# are used in Trivia 2000's code.                                                                   #
#                                                                                                   #
# Even if you don't read all of this header message, please make sure you read all the comments in  #
# the configuration section of the script at the top. I have tried to make these as easy to follow  #
# as possible, if you have genuine problems please contact me, but 95% of "faults" are due to users #
# not actually reading the instructions on how to configure the script properly or use it.          #
#                                                                                                   #
# ------------------------------------------------------------------------------------------------- #
# Trivia 2000 would not exist as it is now without the help of the people below, so thanks to them. #
#                                                                                                   #
# Brian (^^Highlander^^) for his hard work helping me on the randomisation code. It's actually very #
# clever and tracks all questions used within a category so it wont repeat a question until it's    #
# used them all from that category unless you change categories at which point all counters are     #
# reset which does result in repeats if you switch back to the previous one.                        #
#                                                                                                   #
# Stdragon/stdarg who helped write and test the user host adding code which adds users to your bots #
# userlist when they get a question right and then tracks them by nickname and hostmask adding new  #
# hostmasks as needed automatically. It wont however add hostmasks to anyone who has any flags on   #
# their username in the bots userlist thus avoiding spamming to gain access to the room.            #
#                                                                                                   #
# The amazing TCL guru's over at egghelp.org's forums who have helped me regain my very rusty TCL   #
# knowledge and without whose help, many of the new features just wouldnt work. Especially Sir_Fz.  #
#                                                                                                   #
# Thanks to the guys and gals over at the official Queen Online chat room and forums for putting up #
# with me and helping me test it thoroughly, nothing tests this script better than a load of mad    #
# Queen fans in a Queen quiz in a Queen chat room, you guys rock!! :o)                              #
#                                                                                                   #
# The scores section is adapted from Wordgame.tcl v1.0 by "Murf" which was my original inspiration  #
# to write this script, a very clever little word game that formed the base for the original beta   #
# versions of Trivia 2000 before it grew into what it is today.                                     #
#                                                                                                   #
# The new style hints are adapted from code written by Tomas Creemers and emailed to me as an idea  #
# it was something I was trying to do anyway, but Tomas suggested much cleaner code for it which is #
# a lot nicer than anything I'd come up with, I adapted this to give the multi option hints.        #
#                                                                                                   #
# My partner Kerry (The_Vixen) who not only puts up with me being on a PC 24/7 but also helped      #
# choose and test the hideous colours in the new colour scheme.                                     #
# ------------------------------------------------------------------------------------------------- #
# A trivia game script that asks trivia questions to the room and tracks users scores.              #
# With seven different question categories built in and question files provided.                    #
# Single or multiple question rounds.                                                               #
# Switchable answer giving by public command for questions where no one got the answer.             #
# Switchable announcing of how many questions are left at the beginning of each question.           #
# Switchable hints (2 types) which give the first few letters of the answer over a period of time.  #
# Designed for people wanting something other than the standard word game i or trivia scripts.      #
# ------------------------------------------------------------------------------------------------- #
# I take no responsibility if this script causes any problems for you or your bot.                  #
# Originally designed on Eggdrop 1.3.23 and tested up to Eggdrop 1.6.17 up to Trivia 2000 v2.1      #
# ****IMPORTANT NOTE AS FROM VERSION 2.2 THIS SCRIPT WILL ONLY WORK ON EGGDROP 1.6.17 OR HIGHER**** #
# This script is provided completely free of charge.                                                #
# Feel free to amend or improve this script, but if you make improvements,please send me a copy :o) #
# All I ask is that this message, the copyright message in the script and the "Loaded" message at   #
# the end of the script are not changed.                                                            #
# ------------------------------------------------------------------------------------------------- #
# If You would like to receive updates as and when they are available, please email me.             #
# Updates will also be posted on my website http://www.eggdropsrus.co.uk                            #
# ------------------------------------------------------------------------------------------------- #
# New in Version 2.3                                                                                #
# Fancy coloured ASCII fireworks added to the action when user hits max score.                      #
# New variable added to user config section "maxscorereset" which allows setting of the max score   #
# users can reach before fireworks are set off and all scores are reset to zero.                    #
# New style hints added giving empty dashes per character in the answer to give a better hint.      #
# New variable added to user config section "hintsys" which allows choosing of old or new hints.    #
# Delay added between questions in multiple question rounds, delay time can be adjusted in seconds  #
# in the configuration section. Delay and delay announcement can be disabled by setting to zero.    #
# The !choose command will now accept a second part and skip the selection of categories completely #
# i.e. echoose will bring up the choice of categories as normal and then users have to choose by    #
# typing the category in as normal OR !choose geography for example will automatically set it to    #
# Geography and put the game in start mode without having to display the choices or wait for one.   #
# Bug Fix: Corrected an issue where the bot wouldn't respond to room hosts using the !stop or !game #
# on/off commands. Thanks to Thomas Creemers for reporting this.                                    #
# ------------------------------------------------------------------------------------------------- #
# New in Version 2.2                                                                                #
# Completely recoded large sections of the script in order to make the bot respond to coloured text #
# Previously if you werent using black text it just ignored you. Now works fine with all colours.   #
# IMPORTANT: This new code will ONLY work on Eggdrop 1.6.17 or higher making this a requirement for #
# Trivia 2000 to work now. New code added to give error message and switch script off if older bot  #
# version is in use.                                                                                #
# Bug Fix: Changed a duplicate variable in the !hints command that was causing it to switch off     #
# hints completely under certain circumstances. Now works correctly throughout the game.            #
# Bug Fix: Changed a procedure name and recoded slightly to remove a conflict with wordgame by Murf #
# if both games where loaded the timers on one or the other werent killed properly (thanks Roger).  #
# ------------------------------------------------------------------------------------------------- #
# New in Version 2.1                                                                                #
# User definable colours added with a choice of two templates supplied in the script - new multi    #
# coloured or original Trivia 2000 style. Instructions added for users to customise the new one.    #
# Hints function added, the script will automatically give the first character of the answer, the   #
# first two characters of the answer and the first three characters of the answer at set intervals  #
# If there are only two characters in the answer it will only give the first clue and if there are  #
# only three characters in the answer it will only give the first two hints.                        #
# New command !hints on/off added to be able to switch the hints function on or off as required.    #
# Added timer variables to set how long each hint takes to come up and maximum question time length #
# General code clean up.                                                                            #
# Bug Fix: Bot no longer accepts correct answers in non-game rooms. (I hadn't noticed it did it).   #
# ------------------------------------------------------------------------------------------------- #
# New in Version 2.0.5.beta                                                                         #
# Multi word answers can now be used in the question files and are accepted correctly by the bot.   #
# !start command enhanced to accept the number of questions required in this round, maximum number  #
# to allow is configured at the top of the script (default 25). The new command format is !start ** #
# i.e !start 10 will start a ten question round. The !start command still works the same as always. #
# New option to announce the number of questions left in the round before each question by default. #
# New public command !announce on/off to switch on or off the above function.                       #
# New option to display the answers if nobody gets the question right after each question.          #
# New public command !answers on/off to switch on or off the above function.                        #
# New function that notifies users when the round has finished.                                     #
# Bug Fix: !stop command now stops the game timers correctly and the game wont respond to a correct #
# answer after the !stop command is issued. (I hadn't realised it was even doing it before).        #
# Bug Fix: !game off command now cant be used while a round is in progress, !stop command must be   #
# issued first to stop the game as it also wasnt stopping the timers correctly.                     #
# ------------------------------------------------------------------------------------------------- #
# New in Version 1.3                                                                                #
# Slight cock up on the !score command which was only reading the top ten scores in the file and    #
# sorting those into order, it's now reading them all and sorting correctly the top ten. Basically  #
# I recoded something wrong when I adapted it from Wordgame.tcl, put my error right and its ok now. #
# ------------------------------------------------------------------------------------------------- #
# New in Version 1.2.5                                                                              #
# Modification made so that the bot now gives your daily AND total scores so far when you get a     #
# question correct allowing users to track their own scores if not in the top ten.                  #
# Trivia version variable added for easier use and tracking during future "enhancements".           #
# ------------------------------------------------------------------------------------------------- #
# New in Version 1.2                                                                                #
# Bug Fix: Any answers which are numbers now work correctly instead of taking the first digit as a  #
# colour code and displaying it with the first digit missing it now works as it should.             #
# !score command now works and shows the top ten scorers "Overall" and "Today" scores.              #
# ------------------------------------------------------------------------------------------------- #
# New in Version 1.1                                                                                #
# !trivia command bound to same list of commands available as !help command, too many people using  #
# !trivia because other scripts use this command :o), this needed to be explained to users easily.  #
# Bot can now be in multiple rooms, game can only be playing in one, set this in $gamechan variable #
# anyone trying to use game commands in any room other than game room will be directed to the       #
# correct room.                                                                                     #
# Bot now adds new players automatically, and keeps score for them from first correct answer.       #
# Re-wrote half of the score keeping section ready for the !score command to be implemented.        #
#                                                                                                   #
#####################################################################################################

#########################################################
#                 USER DEFINED VARIABLES                #
#########################################################

#****IMPORTANT NOTE AS FROM VERSION 2.2 THIS SCRIPT WILL ONLY WORK ON EGGDROP 1.6.17 OR HIGHER****
#Checks your bots version and disables the script if your bot is older than 1.6.17
#The new colour stripping code was only introduced in that version so the script will fail on earlier versions.
if {$numversion < 1061700} {
        putlog "\002\### Sorry Trivia 2000 requires at least Eggdrop 1.6.17 to play, You are running [lindex $version 0]. ###\002"
	putlog "\002\### All Trivia 2000 commands have been disabled, please upgrade Eggdrop to play. ###\002"
	set botversioncheck "1"
	bind pubm -|- * strip_colour_codes
} else {
	set botversioncheck "0"
	bind pubm -|- * strip_colour_codes
}

proc strip_colour_codes {nick uhost handle channel args} {
   global botversioncheck version
      set args [string tolower [string trim [stripcodes c $args] "{}" ]]
	if {$botversioncheck == "1"} {
        set versionerror "\002\***Sorry Trivia 2000 requires at least Eggdrop 1.6.17 to play, You are running \00304[lindex $version 0]\003.***\002"
        switch [string tolower [lindex [split $args] 0]] {
"!trhelp" {putserv "PRIVMSG $channel :$versionerror"}
"!trtrivia" {putserv "PRIVMSG $channel :$versionerror"}
"!trscore" {putserv "PRIVMSG $channel :$versionerror"}
"!trchoose" {putserv "PRIVMSG $channel :$versionerror"}
"!trstart" {putserv "PRIVMSG $channel :$versionerror"}
"!trhints" {putserv "PRIVMSG $channel :$versionerror"}
"!transwers" {putserv "PRIVMSG $channel :$versionerror"}
"!trannounce" {putserv "PRIVMSG $channel :$versionerror"}
"!trgame" {putserv "PRIVMSG $channel :$versionerror"}
"!trstop" {putserv "PRIVMSG $channel :$versionerror"}
    }
} else {
#These are the main commands for the game, all commands can be used by anyone by default
#Apart from  "!game on/off" & "!trstop", which can be used by authorised ops only.
	switch [string tolower [lindex [split $args] 0]] {
"!trhelp" {give_help $nick $uhost $handle $channel $args}
"!trtrivia" {give_help $nick $uhost $handle $channel $args}
"!trscore" {give_score $nick $uhost $handle $channel $args}
"!trchoose" {give_choice $nick $uhost $handle $channel $args}
"!trstart" {start_game_check $nick $uhost $handle $channel $args}
"!trhints" {hints_onoff $nick $uhost $handle $channel $args}
"!transwers" {give_answers $nick $uhost $handle $channel $args}
"!trannounce" {quest_announce $nick $uhost $handle $channel $args}
"!trgame" {game_onoff $nick $uhost $handle $channel $args}
"!trstop" {stop_game $nick $uhost $handle $channel $args}
    }
return 0
  }
}

#Resets all the daily scores to zero each night
bind time - "05 03 % % %" reset_scores

#The data files need to be held on your shell account.
#Set your questions data files here
set geography /home/mudbot/eggdrop/scripts/geography.txt
set entertain /home/mudbot/eggdrop/scripts/entertainment.txt
set history /home/mudbot/eggdrop/scripts/history.txt
set art_lit /home/mudbot/eggdrop/scripts/art_lit.txt
set sci_nat /home/mudbot/eggdrop/scripts/science_nature.txt
set spo_lei /home/mudbot/eggdrop/scripts/sport_leisure.txt
set queen /home/mudbot/eggdrop/scripts/queen.txt

#Set your scores data file here
#IMPORTANT NOTE: The name of the file is score, do NOT create a directory called score, do NOT change the filename to score.txt
#Simply change the path to where this file is going to be kept exactly as with the question files above.
set scores /home/mudbot/eggdrop/scripts/score

#Set the maximum number of questions per round to allow, default 25.
set maxquesttoask "25"

#Announce the number of questions left in each round at each question?
#(0 for off, 1 for on) - Default 1
set questannounce "1"

#Give the answers if no one gets it right?
#(0 for no, 1 for yes) - Default 1
set giveanswer "1"

#Switch game on or off as default
#(0 for off, 1 for on) - Default 1
set gameonoff "1"

#Give hints during the questions?
#(0 for no, 1 for yes) - Default 1
set givehints "1"

#Set the name of the channel the script is running in here
set gamechan "#coffeemud"

#Set length of time in seconds before the first hint is given
#IMPORTANT: This MUST be less than all the others below - Default 15
set 1sthint "15"

#Set length of time in seconds before the second hint is given
#IMPORTANT: This MUST be more than the one above but less than all the others below - Default 25
set 2ndhint "25"

#Set length of time in seconds before the third hint is given
#IMPORTANT: This MUST be more than the ones above but less than the total below - Default 35
set 3rdhint "35"

#Set the overall length of time in seconds before the question times out and moves onto next question or ends game
#IMPORTANT: This MUST be more than the 3rdhint set above - Default 45
set endquest "45"

#Use New or Old style hint system
#(0 for old, 1 for new) - Default 1
set hintsys "1"

#Delay in seconds between questions in multiple question rounds - Default 15
#Setting this to 0 disables the delay and the delay announcement
set questdelay "15"

#As soon as any player hits this score, the fireworks go off and all scores for all players are reset to zero
#Default 500
set maxscorereset "500"

#########################################################
#                GAME COLOUR SELECTION                  #
#########################################################

#Set your preferred default colour scheme
#(0 for Original Trivia 2000, 1 for New multi coloured) - Default 1
set colourscheme "1"

#New Colour Scheme - Users May Edit This One
#
# You can edit these colours to be anything you like using the numbers below to change the colours
#
# 00 = White        04 = Red      08 = Yellow       12 = Blue
# 01 = Black        05 = Brown    09 = Lime Green   13 = Pink
# 02 = Dark Blue    06 = Purple   10 = Teal         14 = Dark Grey
# 03 = Dark Green   07 = Khaki    11 = Cyan         15 = Light Grey
#
# The first number in any of the pairs of numbers is the font colour and the second colour is the background colour
# So for example: set copycol1 "08,01" gives yellow text on a black background for the Copyright Logo
if {$colourscheme == 1} {
set copycol1 "08,01"		;#Copyright Logo Colours
set copycol2 "01,15"		;#Copyright Text Colours
set categcol1 "02,04"		;#Category Instructions
set categcol2 "04,15"		;#Categorys Offered Colours
set choosecol "02,13"		;#Choose Category Colour
set quessetcol1 "01,08"		;#Questions Set Primary Colour
set quessetcol2 "03,08"		;#Questions Set Secondary Colour
set quessetcol3 "04,08"		;#Questions Set Tertiary Colour	
set statcol1 "12,09"		;#Statement Primary Colour
set statcol2 "04,09"		;#Statement Secondary Colour
set announcecol1 "02,15"	;#Announce Question Numbers Primary Colour
set announcecol2 "04,15"	;#Announce Question Numbers Secondary Colour
set questcol1 "11,05"		;#Question Primary Colour
set questcol2 "04,11"		;#Question Secondary Colour
set hintcol1 "11,05"		;#Hints Primary Colour
set hintcol2 "13,02"		;#Hints Secondary Colour
set answercol1 "00,04"		;#Correct Answer Primary Colour
set answercol2 "04,00"		;#Correct Answer Secondary Colour
set answercol3 "13,00"		;#First Correct Answer Primary Colour
set answercol4 "00,13"		;#First Correct Answer Secondary Colour
set scorecol1 "13,00"		;#Correct Answer Score Primary Colour
set scorecol2 "00,13"		;#Correct Answer Score Secondary Colour
set scorecol3 "06,00"		;#Correct Answer Score Tertiary Colour
set firecol1 "06,15"		;#Fireworks Action Primary Colour
set firecol2 "11,02"		;#Fireworks Action Secondary Colour
set firecol3 "13,15"		;#Fireworks Action Tertiary Colour
set noonecol1 "12,11"		;#Noone Got It Right Primary Colour
set noonecol2 "04,00"		;#Noone Got It Right Secondary Colour
set noonecol3 "11,12"		;#Noone Got It Right Tertiary Colour
set helpcol1 "04,11"		;#Help Primary Colour
set helpcol2 "02,13"		;#Help Secondary Colour
set topcol1 "05,11"		;#Top Scores Primary Colour
set topcol2 "14,08"		;#Top Scores Secondary Colour
set topcol3 "02,15"		;#Top Scores Tertiary Colour
set sorrycol "10,15"		;#Sorry Not In This Room Colour
}

#Original Trivia 2000 Colour Scheme - Users May NOT Edit This One
if {$colourscheme == 0} {
set copycol1 ""            ;#Copyright Logo Colours
set copycol2 ""            ;#Copyright Text Colours
set categcol1 ""           ;#Category Instructions
set categcol2 "04"         ;#Categorys Offered Colours
set choosecol "06"         ;#Choose Category Colour
set quessetcol1 ""         ;#Questions Set Primary Colour
set quessetcol2 ""         ;#Questions Set Secondary Colour
set quessetcol3 "04"       ;#Questions Set Tertiary Colour
set statcol1 ""            ;#Statement Primary Colour
set statcol2 "04"          ;#Statement Secondary Colour
set announcecol1 ""        ;#Announce Question Numbers Primary Colour
set announcecol2 "04"      ;#Announce Question Numbers Secondary Colour
set questcol1 ""           ;#Question Primary Colour
set questcol2 "04"         ;#Question Secondary Colour
set hintcol1 "04"          ;#Hints Primary Colour
set hintcol2 ""            ;#Hints Secondary Colour
set answercol1 ""          ;#Correct Answer Primary Colour
set answercol2 "04"        ;#Correct Answer Secondary Colour
set answercol3 ""          ;#First Correct Answer Primary Colour
set answercol4 "04"        ;#First Correct Answer Secondary Colour
set scorecol1 ""           ;#Correct Answer Score Primary Colour
set scorecol2 ""           ;#Correct Answer Score Secondary Colour
set scorecol3 ""           ;#Correct Answer Score Tertiary Colour
set firecol1 ""            ;#Fireworks Action Primary Colour
set firecol2 ""            ;#Fireworks Action Secondary Colour
set firecol3 ""            ;#Fireworks Action Tertiary Colour
set noonecol1 ""           ;#Noone Got It Right Primary Colour
set noonecol2 "04"         ;#Noone Got It Right Secondary Colour
set noonecol3 ""           ;#Noone Got It Right Tertiary Colour
set helpcol1 "04"          ;#Help Primary Colour
set helpcol2 "06"          ;#Help Secondary Colour
set topcol1 ""             ;#Top Scores Primary Colour
set topcol2 "04"           ;#Top Scores Secondary Colour
set topcol3 ""             ;#Top Scores Tertiary Colour
set sorrycol ""            ;#Sorry Not In This Room Colour
}

#########################################################
#              GAME VARIABLES DON'T TOUCH               #
#########################################################

#Script version number variable
#DONT TOUCH THIS
set triviaversion "2.3"

#The script requires data files holding the questions
#DONT TOUCH THESE TWO LINES!
set questfile ""
set questions $questfile

#Initialises the place in the question list to 0
#DONT TOUCH THIS!
set questionno 0

#Initialises the global question list to null
#DONT TOUCH THIS!
set quest ""

#Initialises list of used questions to null
#DONT TOUCH THIS!
set usedq ""

#Number of questions available to ask variable - leave set to NULL.
#DONT TOUCH THIS!
set questtoask ""

#Tells the bot wether or not the game is already running
#DONT TOUCH THIS!
set gameplaying 0

#Allows the bot to keep tabs on total questions played
#DONT TOUCH THIS!
set player Trivia

#########################################################
#                  SCRIPT STARTS HERE                   #
#########################################################

#On/off switch (useful if the game is annoying people!) :o)
proc game_onoff {nick uhost handle channel args} {
   global botnick gameonoff gameplaying gamechan statcol1 statcol2 copycol1 sorrycol
	if {[string tolower $channel] != [string tolower $gamechan]} {
	putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	if {![matchattr $handle o|o $gamechan]} {
	putserv "PRIVMSG $channel :\002\003$statcol1\Sorry the !trgame on/off command is restricted to authorised ops only."
return
}
	set chan $gamechan
	set onoff [string tolower [ string trim [lindex [split $args] 1] "{}" ]]
	if {($onoff == "on") && ($gameonoff == 0)} {
	set gameonoff 1
	putserv "PRIVMSG $chan :\002\003$statcol1\Game is now switched on! Enter \003$statcol2\!trstart\003$statcol1\ to play."
return
}
	if {($onoff == "on") && ($gameonoff != 0)} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Game is already switched on!"
return
}
	if {$gameplaying == 1} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Please wait until round has finished or stop game using \003$statcol2\!trstop\003$statcol1\ command before turning game off!"
	return
}
	if {($onoff == "off") && ($gameonoff != 0)} {
	set gameonoff 0
	set gameplaying 0
	set questtoask ""
	set answer ""
	killall_timers
	putserv "PRIVMSG $chan :\002\003$statcol1\Game is now switched off!"
return
}
	if {($onoff == "off") && ($gameonoff == 0)} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Game is already switched off!"
return
}
	putserv "PRIVMSG $chan :\002\003$statcol1\To switch game on or off use \003$statcol2\!trgame on/off"
return
}

#Give answers if no one gets it right switch
proc give_answers {nick uhost handle channel args} {
   global gameonoff gameplaying gamechan giveanswer statcol1 statcol2 copycol1 sorrycol
        if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
        set chan $gamechan
        set answeronoff [string tolower [ string trim [lindex [split $args] 1] "{}" ]]
        if {($answeronoff == "on") && ($gameonoff == 0)} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is switched off, please switch game on using \003$statcol2\!trgame on\003$statcol1\ command before trying this command!"
return
}
        if {($answeronoff == "off") && ($gameonoff == 0)} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is switched off, please switch game on using \003$statcol2\!trgame on\003$statcol1\ command before trying this command!"
return
}
	if {$gameplaying == 1} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Please wait until round has finished or stop game using \003$statcol2\!trstop\003$statcol1\ command before trying this command!"
return
}
	if {($answeronoff == "on") && ($gameonoff == 1)} {
	set giveanswer "1"
	putserv "PRIVMSG $chan :\002\003$statcol1\Answers will now be given after questions that are not correctly answered!"
return
}
	if {($answeronoff == "off") && ($gameonoff == 1)} {
	set giveanswer "0"
	putserv "PRIVMSG $chan :\002\003$statcol1\Answers will no longer be given after questions that are not correctly answered!"
return
}
	putserv "PRIVMSG $chan :\002\003$statcol1\To switch answers on or off use \003$statcol2\!transwers on/off"
return
}

#Give hints switch
proc hints_onoff {nick uhost handle channel args} {
   global gameonoff gameplaying gamechan givehints statcol1 statcol2 copycol1 sorrycol
        if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
        set chan $gamechan
        set switchgivehints [string tolower [ string trim [lindex [split $args] 1] "{}" ]]
        if {($switchgivehints == "on") && ($gameonoff == 0)} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is switched off, please switch game on using \003$statcol2\!trgame on\003$statcol1\ command before trying this command!"
return
}
        if {($switchgivehints == "off") && ($gameonoff == 0)} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is switched off, please switch game on using \003$statcol2\!trgame on\003$statcol1\ command before trying this command!"
return
}
        if {$gameplaying == 1} {
        putserv "PRIVMSG $chan :\002\003$statcol1\Please wait until round has finished or stop game using \003$statcol2\!trstop\003$statcol1\ command before trying this command!"
        return
}
        if {($switchgivehints == "on") && ($gameonoff == 1)} {
        set givehints "1"
        putserv "PRIVMSG $chan :\002\003$statcol1\Hints will now be given during questions!"
return
}
        if {($switchgivehints == "off") && ($gameonoff == 1)} {
        set givehints "0"
        putserv "PRIVMSG $chan :\002\003$statcol1\Hints will no longer be given during questions!"
return
}
        putserv "PRIVMSG $chan :\002\003$statcol1\To switch hints on or off use \003$statcol2\!trhints on/off"
return
}

#Announce how many questions are in the round before every question switch
proc quest_announce {nick uhost handle channel args} {
   global gameonoff gameplaying gamechan questannounce statcol1 statcol2 copycol1 sorrycol
        if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
        set chan $gamechan
        set announceonoff [string tolower [ string trim [lindex [split $args] 1] "{}" ]]
        if {($announceonoff == "on") && ($gameonoff == 0)} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is switched off, please switch game on using \003$statcol2\!trgame on\003$statcol1\ command before trying this command!"
return
}
        if {($announceonoff == "off") && ($gameonoff == 0)} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is switched off, please switch game on using \003$statcol2\!trgame on\003$statcol1\ command before trying this command!"
return
}
        if {$gameplaying == 1} {
        putserv "PRIVMSG $chan :\002\003$statcol1\Please wait until round has finished or stop game using \003$statcol2\!trstop\003$statcol1\ command before trying this command!"
        return
}
        if {($announceonoff == "on") && ($gameonoff == 1)} {
        set questannounce "1"
        putserv "PRIVMSG $chan :\002\003$statcol1\The number of questions left in the round will now be announced before each question!"
return
}
        if {($announceonoff == "off") && ($gameonoff == 1)} {
        set questannounce "0"
        putserv "PRIVMSG $chan :\002\003$statcol1\The number of questions left in the round will no longer be announced before each question!"
return
}
        putserv "PRIVMSG $chan :\002\003$statcol1\To switch question number announcements on or off use \003$statcol2\!trannounce on/off"
return
}

#Stop command to stop it running away with itself! :o)
proc stop_game {nick uhost handle channel args} {
   global gameplaying gameonoff gamechan statcol1 statcol2 copycol1 sorrycol
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
        if {![matchattr $handle o|o $gamechan]} {
        putserv "PRIVMSG $channel :\002\003$statcol1\Sorry the !trstop command is restricted to authorised ops only."
return
}
	set chan $gamechan
	if {$gameonoff == 0} {
	putserv "PRIVMSG $chan :\002\003$statcol1\How can I stop something that's not switched on??!! :o)"
return
}
	if {($gameonoff != 0) && ($gameplaying == 0)} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Game is already stopped!!"
return
}
	if {($gameonoff != 0 ) && ($gameplaying != 0)} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Game stopped, enter \003$statcol2\!trstart\003$statcol1\ to restart game!"
	set gameplaying 0
	set questtoask ""
	set answer ""
	killall_timers
        unbind pubm -|- * answercheck
return 0
}
}

#Give people a choice of category before starting the game
#Or change the category with the !trchoose command
proc give_choice {nick uhost handle channel args} {
   global questions questfile quest usedq questionno puzzle geography entertain history art_lit sci_nat spo_lei queen gameplaying gameonoff gamechan triviaversion copycol1 copycol2 statcol1 statcol2 categcol1 categcol2 choosecol sorrycol
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	set chan $gamechan
	if {$gameplaying != 0} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Game is already running, please either wait for it to finish or enter \003$statcol2\!trstop\003$statcol1\ then \003$statcol2\!trchoose\003$statcol1\ again to set category"
return
}
	if {$gameonoff == 0} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Sorry $nick but the game isn't switched on right now, please try later!"
return
}
	set questfile ""
	set questionno 0
	set quest ""
	set usedq ""
	set puzzle ""

	putserv "PRIVMSG $chan :\002\003$copycol1\'Trivia 2000'\002 \003$copycol2\Version $triviaversion �Ian-Highlander 2000-2007 started, please wait for a moment."
        bind pubm -|- * strip_colour_choices
        if {[string trim [lindex [split $args] 1] "{}" ] == ""} {
	putserv "PRIVMSG $chan :\003$categcol1\Please select a category of questions to be answered"
	putserv "PRIVMSG $chan :Current categories available are: \003$categcol2\Geography, Entertainment, History, Art & Literature, Science & Nature, Sport & Leisure, Queen"
	putserv "PRIVMSG $chan :\003$choosecol\To choose a category simply type in the first word of that category."
#	bind pubm -|- * strip_colour_choices
 } else {
	set args [string trim [lindex [split $args] 1] "{}" ]
	strip_colour_choices $nick $uhost $handle $channel $args
return 0
 }

return 0
}

proc strip_colour_choices {nick uhost handle channel args} {
   global questfile geography entertain history art_lit sci_nat spo_lei queen gamechan quessetcol1 quessetcol2 quessetcol3 categcol1
     set args [string tolower [string trim [stripcodes c $args] "{}" ]]
        switch [string tolower [lindex [split $args] 0]] {
"geography"
{
	set chan $gamechan
	set questfile $geography
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ Geography\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
"entertainment"
{
	set chan $gamechan
	set questfile $entertain
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ Entertainment\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
"history"
{
	set chan $gamechan
	set questfile $history
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ History\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
"art"
{
	set chan $gamechan
	set questfile $art_lit
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ Art & Literature\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
"science"
{
	set chan $gamechan
	set questfile $sci_nat
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ Science & Nature\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
"sport"
{
	set chan $gamechan
	set questfile $spo_lei
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ Sport & Leisure\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
"queen"
{
	set chan $gamechan
	set questfile $queen
	putserv "PRIVMSG $chan :\003$quessetcol1\Questions set to \002\003$quessetcol2\ Queen\002 \003$quessetcol1\ by $nick enter\002\003$quessetcol3\ !trstart\002 \003$quessetcol1\ to play!"
	unbind pubm -|- * strip_colour_choices
return
}
   }
	putserv "PRIVMSG $channel :\003$categcol1\That is not a valid category. Please try again."
	unbind pubm -|- * strip_colour_choices
return 0
}
  
#Are we playing more than one question at a time and is it within the maximum set in the config at the top?
proc start_game_check {nick uhost handle channel args} {
   global questtoask maxquesttoask gameplaying statcol1 statcol2 copycol1 sorrycol
	if {$gameplaying == 1} {
	putserv "PRIVMSG $channel :\002\003$statcol1\The game is already running!"
return
} else {
	set questtoask [string trim [lindex [split $args] 1] "{}" ]
	if {$questtoask == ""} {
	start_game $nick $uhost $handle $channel
} else {
	if {$questtoask > $maxquesttoask} {
	putserv "PRIVMSG $channel :\002\003$statcol1\Sorry $nick the maximum number of questions per round is set to\003$statcol2\ $maxquesttoask\003$statcol1\ please retry."
return 0
}
	count_questions $nick $uhost $handle $channel
}
}
}

#Procedure to keep count of and track the number of questions asked in a round.
proc count_questions {nick uhost handle channel args} {
   global questfile questtoask questannounce gamechan gameonoff gameplaying statcol1 statcol2 announcecol1 announcecol2 copycol1 sorrycol questdelay
        if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	if {$gameonoff == 0} {
	putserv "PRIVMSG $channel :\002\003$statcol1\Sorry $nick but the game isn't switched on right now, please try later!"
return 0
}
        if {($questfile == "") && ($gameonoff !=0)} {
        putserv "PRIVMSG $channel :\002\003$statcol1\There is no category set please select a category by entering \003$statcol2\!trchoose"
return 0
}
	if {$questtoask == ""} {
	set gameplaying 0
return 0
} else {
	if {$questtoask == "0"} {
	putserv "PRIVMSG $channel :\002\003$announcecol1\That is the end of the current round."
	set questtoask ""
return 0
} else {
	if {($questannounce == "1") && ($questtoask == "1")} {
	putserv "PRIVMSG $channel :\002\003$announcecol1\This is the last question in this round."
	set questtoask [expr $questtoask-1]
} elseif {($questannounce == "1") && ($questtoask > "1")} {
	putserv "PRIVMSG $channel :\002\003$announcecol1\There are\003$announcecol2\ $questtoask \003$announcecol1\questions left in this round."
	set questtoask [expr $questtoask-1]
} elseif {$questannounce == "0"} {
        set questtoask [expr $questtoask-1]
} elseif {($questannounce == "1") && ($questtoask > "1")} {
        putserv "PRIVMSG $channel :\002\003$announcecol1\There are\003$announcecol2\ $questtoask \003$announcecol1\questions left in this round."
        set questtoask [expr $questtoask-1]
} else {
return 0
}
	if {$questdelay != "0"} {
	putserv "PRIVMSG $channel :\002\003$announcecol1\Next question coming in\003$announcecol2\ $questdelay \003$announcecol1\seconds."
        utimer $questdelay [list start_game $nick $uhost $handle $channel]
} else {
	start_game $nick $uhost $handle $channel
 }
}
}
}

#Ok, now the fun part starts!
proc start_game {nick uhost handle channel args} {
   global questions questfile scores gameonoff gameplaying questionno quest player answer ques_pair puzzle ques_split usedq gamechan questtoask givehints statcol1 statcol2 questcol1 questcol2 hintcol1 hintcol2 copycol1 sorrycol endquest 1sthint 2ndhint 3rdhint hintsys
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	set chan $gamechan
	set questions $questfile
	if {![validuser $player]} {
	adduser $player Trivia2000!trivia2000@trivia.2000.net
	foreach chan $channel {
	setuser $player XTRA wcount.$chan 0
}
}
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	if {($questfile == "") && ($gameonoff !=0)} {
	putserv "PRIVMSG $chan :\002\003$statcol1\There is no category set please select a category by entering\003$statcol2\ !trchoose"
return
} 
	validate_user
	if {$gameonoff == 0} {
	putserv "PRIVMSG $chan :\002\003$statcol1\Sorry $nick but the game isn't switched on right now, please try later!"
return
 }
	if {($gameonoff == 1) && ($gameplaying != 0)} {
	putserv "PRIVMSG $chan :\002\003$statcol1\The game is already running!"
return
 }
	if {($gameonoff == 1) && ($gameplaying == 0)} {
	set gameplaying 1
	setuser $player XTRA wcount.$chan $questionno

	set chan $gamechan
	if {$questionno == 0} {
	validate_user
	set questionno [getuser $player XTRA wcount.$chan]
	set quest ""	
	set fd [open $questions r]
	while {![eof $fd]} {
	lappend quest [gets $fd]
}
	close $fd
}
	set questionno [rand [llength $quest]]			
	while {([lsearch -exact $usedq $questionno] >= 0) &&
	([llength $usedq] <= [llength $quest])} {
	set questionno [rand [llength $quest]]}
	lappend usedq $questionno
	if {[llength $usedq] == [llength $quest]} {
	set usedq ""}
	set ques_pair [lindex $quest $questionno]
	set puzzle [lindex [split $ques_pair :] 1]
	set answer [lindex [split $::ques_pair :] 0]

	if {$hintsys == 0} {
	set hint [split $answer {}]
	set clue1 [lindex $hint 0]
	set clue2 [lindex $hint 1]
	set clue3 [lindex $hint 2]
} elseif {$hintsys == 1} {
	regsub -all -- {[^\ ]} $answer "-" hiddenanswer
	set hiddenanswer $hiddenanswer
        set clue1 [string index $answer 0]
        set clue2 [string index $answer 1]
        set clue3 [string index $answer 2]
}

	bind pubm -|- * answercheck
	putserv "PRIVMSG $chan :\003$questcol1\Question.......\003$questcol2\ $puzzle"
	incr questionno
	utimer $endquest [list no_answer $nick $uhost $handle $channel]
	if {$givehints == "1"} {

	if {$hintsys == 0} {
	set answerlength [llength [split $answer {}]]	
	if {$answerlength > 1} {
	utimer $1sthint [list 1st_clue $clue1 $channel]
}
	if {$answerlength > 2} {
	utimer $2ndhint [list 2nd_clue $clue1 $clue2 $channel]
}
	if {$answerlength > 3} {
        utimer $3rdhint [list 3rd_clue $clue1 $clue2 $clue3 $channel]
}

} elseif {$hintsys == 1} {
	set answerlength [llength [split $answer {}]]
        if {$answerlength > 1} {
        utimer $1sthint [list 1st_clue_new $clue1 $hiddenanswer $channel]
}
        if {$answerlength > 2} {
        utimer $2ndhint [list 2nd_clue_new $clue1 $clue2 $hiddenanswer $channel]
}
        if {$answerlength > 3} {
        utimer $3rdhint [list 3rd_clue_new $clue1 $clue2 $clue3 $hiddenanswer $channel]
}
}

}
	setuser $player XTRA wcount.$chan $questionno
}
}

#New hint system procedures
proc 1st_clue_new {clue1 hiddenanswer channel} {
   global hintcol1 hintcol2
	set clue $clue1
	append clue [string range $hiddenanswer 1 end]
	putserv "PRIVMSG $channel :\003$hintcol1\**Hint**\003$hintcol2\ First letter ---> $clue."
}

proc 2nd_clue_new {clue1 clue2 hiddenanswer channel} {
   global hintcol1 hintcol2
        set clue "$clue1$clue2"
        append clue [string range $hiddenanswer 2 end]
        putserv "PRIVMSG $channel :\003$hintcol1\**Hint**\003$hintcol2\ First two letters ---> $clue."
}

proc 3rd_clue_new {clue1 clue2 clue3 hiddenanswer channel} {
   global hintcol1 hintcol2
        set clue "$clue1$clue2$clue3"
        append clue [string range $hiddenanswer 3 end]
        putserv "PRIVMSG $channel :\003$hintcol1\**Hint**\003$hintcol2\ First three letters ---> $clue."
}

#Old hint system procedures
proc 1st_clue {clue1 channel} {
   global hintcol1 hintcol2
	set clue $clue1
	putserv "PRIVMSG $channel :\003$hintcol1\**Hint**\003$hintcol2\ First letter ---> $clue."
}

proc 2nd_clue {clue1 clue2 channel} {
   global hintcol1 hintcol2
        set clue "$clue1$clue2"
        putserv "PRIVMSG $channel :\003$hintcol1\**Hint**\003$hintcol2\ First two letters ---> $clue."
}

proc 3rd_clue {clue1 clue2 clue3 channel} {
   global hintcol1 hintcol2
        set clue "$clue1$clue2$clue3"
        putserv "PRIVMSG $channel :\003$hintcol1\**Hint**\003$hintcol2\ First three letters ---> $clue."
}

proc answercheck {nick uhost handle channel arg} { 
   global answer gamechan
        if {[string tolower $channel] != [string tolower $gamechan]} {
	return 0
}
     set arg [string tolower [string trim [stripcodes c $arg] "{}" ]]
	if {[string equal -nocase $answer $arg]} { 
	winner $nick $uhost $handle $channel
}
}

#Random answers to say when answer is right
#Change these to whatever you like
set winnersay {
"congratulations!!"
"well done!!"
"good guess!!"
"ok, I'll give you that one!!"
"smart arse!!"
"How did you get that??!!"
"Big Head!!"
"way to go!!"
}


#When someone wins tell them they've won
#How many times they've won and add to scores
proc winner {nick uhost handle channel args} {
   global answer chan gameplaying scores winnersay gamechan answercol1 answercol2 answercol3 answercol4 scorecol1 scorecol2 scorecol3 firecol1 firecol2 firecol3 copycol1 sorrycol maxscorereset
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	set chan $gamechan
	putserv "PRIVMSG $chan :\003$answercol1\Woohoo \003$answercol2\ $nick!! \003$answercol1\ You got it right..... \002\003$answercol2\ $answer"
	killall_timers
	unbind pubm -|- * answercheck
	validate_user noreset
	if {![file exists $scores]} {
	set fd [open $scores w]
	close $fd
}
	set fd [open $scores 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 {$handle == $scnick} {
	set newd [expr [lindex $score [expr $k + 1]] + 1]
	set newf [expr [lindex $score [expr $k + 2]] + 1]
	set score [lreplace $score [expr $k + 1] [expr $k + 2] $newd $newf]
	set dscore [lindex $score [expr $k + 1]]
	set rand_say [lindex $winnersay [rand [llength $winnersay]]]
	set chan $gamechan
	putserv "PRIVMSG $chan :\003$scorecol1\ $nick you've won \002\003$scorecol2\ $dscore times today \002\003$scorecol3\ and \002\003$scorecol2\ $newf times overall \003$scorecol3\ $rand_say"
	if {$newf == $maxscorereset} {
	putserv "PRIVMSG $chan :\002\003$firecol1\OH MY GAWD!! \003$firecol2\ $scnick \002\003$firecol2\ just scored \002\003$firecol3\ $maxscorereset \003$firecol2\ 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 sets off fireworks and starts the count again!"
        putserv "PRIVMSG $chan :\00308,01*            *     *             \00309,01 )        \00308,01 *              *"
        putserv "PRIVMSG $chan :\00308,01*    *  \00313,01 ..''..         \00308,01 *     \00309,01 _\\)/_          \00308,01*         *"
        putserv "PRIVMSG $chan :\00308,01*     \00313,01 : \00304,01_\\/_\00313,01 :     \00311,01.''.   \00308,01 *  \00309,01 /(\\         \00300,01 ..''..        \00308,01*"
        putserv "PRIVMSG $chan :\00308,01*     \00313,01 :  \00304,01 /\\  \00313,01  :  \00311,01 :    :        \00309,01 '        \00300,01 : \00315,01_\\/_\00300,01 :     \00308,01*"
        putserv "PRIVMSG $chan :\00308,01*        \00313,01 ''..''     \00311,01 :    :    \00300,01 \\'/          \00300,01 : \00315,01  /\\ \00300,01   :     \00308,01*"
        putserv "PRIVMSG $chan :\00308,01*            *     \00311,01  '..'   \00300,01 = o =   \00308,01 *    \00300,01 ''..''        \00308,01*"
        putserv "PRIVMSG $chan :\00308,01*    *          *            \00300,01 /`\\   \00308,01*                      *"
}
	set gameplaying 0
	set chan ""
	set fd [open $scores w]
	foreach line $score {
	puts $fd $line
} 
	close $fd
	set answer ""
	count_questions $nick $uhost $handle $channel
return 0
}  
}
	set chan $gamechan
	putserv "PRIVMSG $chan :\003$answercol3\ $nick this is your first ever win!!!...\002\003$answercol4\ Now try and win again!"
	set score [lappend score $handle]
	set score [lappend score 1]
	set score [lappend score 1]
	set fd [open $scores w]
	foreach line $score {
	puts $fd $line
}
	close $fd
	set gameplaying 0
	set chan ""
	set answer ""
	count_questions $nick $uhost $handle $channel
return 0
}

#If no one gets it right within the alloted time, stop game and reset.
proc no_answer {nick uhost handle channel args} {
   global gameplaying answer chan gamechan questtoask giveanswer noonecol1 noonecol2 noonecol3
	set chan $gamechan
	if {$giveanswer == "0"} {
	putserv "PRIVMSG $chan :\003$noonecol1\No body got it right!!.....\002\003$noonecol2\ Try Again!!"
}
	if {$giveanswer == "1"} {
	putserv "PRIVMSG $chan :\003$noonecol1\No body got it right!!.....\003$noonecol3\ The answer was..... \002\003$noonecol2\ $answer"
}
	killall_timers
	unbind pubm -|- * answercheck
	set gameplaying 0
	set chan ""
	set answer ""
	count_questions $nick $uhost $handle $channel
return 0
}

# Kill all  timers. 
proc killall_timers {} { 
 global chan 
	foreach j [utimers] { 
	if {[string match -nocase "no_answer *" [lindex $j 1]]} { 
	killutimer [lindex $j 2] 
}
	if {[string match -nocase "1st_clue *" [lindex $j 1]]} {
	killutimer [lindex $j 2]
}
        if {[string match -nocase "2nd_clue *" [lindex $j 1]]} {
        killutimer [lindex $j 2]
}
        if {[string match -nocase "3rd_clue *" [lindex $j 1]]} {
        killutimer [lindex $j 2]
}
        if {[string match -nocase "1st_clue_new *" [lindex $j 1]]} {
        killutimer [lindex $j 2]
}
        if {[string match -nocase "2nd_clue_new *" [lindex $j 1]]} {
        killutimer [lindex $j 2]
}
        if {[string match -nocase "3rd_clue_new *" [lindex $j 1]]} {
        killutimer [lindex $j 2]
}
        if {[string match -nocase "start_game *" [lindex $j 1]]} {
        killutimer [lindex $j 2]
}


}
return 0
}

#New help command gives help on the commands available
proc give_help {nick uhost handle channel args} {
   global gameplaying gamechan statcol1 helpcol1 helpcol2 copycol1 sorrycol
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	set chan $gamechan
	if {$gameplaying != 0} {
        putserv "PRIVMSG $chan :\002\003$statcol1\The game is currently playing, please wait for game to end before asking for help on commands."
return
}
        putserv "PRIVMSG $chan :\002\003$helpcol1\Current commands available are:\002"
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trhelp / !trtrivia\002\003$helpcol2\ - Gives this list of commands."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trchoose\002\003$helpcol2\ - Gives choice of categories available."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trchoose category\002\003$helpcol2\ - Chooses category if available and sets it to play mode."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trstart\002\003$helpcol2\ - Starts the game and asks a question from the chosen category."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trstart **\002\003$helpcol2\ - Starts the game and asks ** number of questions without stopping."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trscore\002\003$helpcol2\ - Gives top ten scores both total and daily."
	putserv "PRIVMSG $chan :\002\003$helpcol2\!trhints on/off\002\003$helpcol2\ - Turns on or off hints during the questions."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trannounce on/off\002\003$helpcol2\ - Turns on or off how many questions are left in the round before each question."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!transwers on/off\002\003$helpcol2\ - Turns answers on or off if no one gets it right."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trstop\002\003$helpcol2\   - Stops the game if the necessity arises \003$helpcol1\(authorised ops only!)."
        putserv "PRIVMSG $chan :\002\003$helpcol2\!trgame on/off\002\003$helpcol2\ - Main on/off switch for the game \003$helpcol1\(authorised ops only!)."
}

#Clear all the daily scores once a day.
proc reset_scores {m h d mo y} {
   global scores 
	set fd [open $scores 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 $scores w]
	foreach line $score {
	puts $fd $line
} 
	close $fd
return 1
}

#Give the top ten scores when someone issues the !score command
proc give_score {nick uhost handle channel args} {
   global botnick scores answer gameplaying gameonoff gamechan chan statcol1 statcol2 topcol1 topcol2 topcol3 copycol1 sorrycol
	if {[string tolower $channel] != [string tolower $gamechan]} {
        putserv "PRIVMSG $channel :\003$sorrycol\Sorry $nick, \002\003$copycol1\'Trivia 2000'\002 \003$sorrycol\is not running in $channel try going to $gamechan its playing there :o)"
return
}
	if {$gameonoff == 0} {
	putserv "PRIVMSG $channel :\002\003$statcol1\The game is switched off, please switch game on using\003$statcol2\ !trgame on\003$statcol1\ command before trying this command!"
return 0
}
	if {$gameplaying == 1} {
	putserv "PRIVMSG $channel :\002\003$statcol1\Please wait until the game has stopped before asking for scores"
return 0
}
	if {![file exists $scores]} {
	putserv "PRIVMSG $channel :\002\003$statcol1\No one has scored yet!"
return
}
	set fd [open $scores 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]
	if {$newtempsortscore != ""} {
	append sortscore [format "\003$topcol2\ %s\. \003$topcol3\ %s\(%d\/%d\) \003  " [expr {$i + 1}] [lindex $tiscore 2] $newtempsortscore [lindex $tiscore 1]]
}
}
	if {$sortscore == ""} {
	putserv "PRIVMSG $channel :\002\003$statcol1\No one has scored yet!"
return
}
	set slength [llength $sortscore]
	putserv "PRIVMSG $channel :\002\003$topcol1\The top 10 scorers are (Overall/Today):\002"
	putserv "PRIVMSG $channel :$sortscore"
}

#Is this a user that has played before on a different IP address, check and add host securely
#Will only add hostmasks if the user does not have any flags set thus avoiding spamming
proc validate_user {{func doreset}} {
	upvar nick nick
	upvar uhost uhost
	upvar handle hand
	upvar channel chan
	if [validuser $hand] {
return 0
}
	if [validuser $nick] {
	set flags [chattr $nick $chan]
	if {$flags == "-|-"} {
	putlog "\002\*Trivia 2000*\002 $nick automatically updated with hostmask [maskhost $uhost]"
	setuser $nick HOSTS [maskhost $uhost]
}
} else {
	putlog "\002\*Trivia 2000*\002 $nick automatically added to user list with hostmask [maskhost $uhost]"
	adduser $nick [maskhost $uhost]
}
	if {$func == "doreset"} {
	global player
	setuser $player XTRA wcount.$chan 0
}
	set hand $nick
return 0
}

if { $botversioncheck == "0" } {
putlog "\002\'Trivia 2000'\002 Version $triviaversion �Ian-Highlander 2000-2007 loaded"
}