set tcqdb "/home/eggdrop/scripts/ccnaquestions.txt"

set questionfiles "$tcqdb&default
/home/d/eggdrop/scripts/demoquestions.txt&demo
/home/d/eggdrop/scripts/ccnaquestions.txt&CCNA"

set tcchoosecmd "!playyyyyyy"

set tccommandlist $tcchoosecmd$

set tcflagschoose "-|-"

set tcqdbsep "|"

set tcmultiplesep "$"

set tcmultifact 2

set tccheat "ON"

set tcqdbquestionfirst 0

set tcscf "game/trivia.scores"

set tcerrmethod 0

set tcerrfil "scripts/trivia.errors"

set tcerremail "indra82@gmail.com"

set tcerrmailtmp "/tmp"

set tchtmlfile "public_html/mychan.html"

set tchtmlrefresh 0

set tchtmlfont "verdana,helvetica,arial"

set tcchan "#dago25"

set tcpointsperanswer 10

set tcmaxhint 3

set tcalwaysshowq 0

set tccapsquestion 0

set tccapsanswer 0

set tccapshint 0

set tcstreakmin 0

set tcmaxmissed 0

set tchintchar "*"

set tctimehint 60

set tctimenext 15

set tccongrats [list "Congratulations" "Well done" "Nice going" "Way to go" "You got it" "That's the way" "Show 'em how it's done" "Check out the big brain on"]

set tcnobodygotit [list "Nobody got it right." "Hello? Anybody home?" "You're going to have to try harder!" "Are these too tough for you?" "Am I alone here or what?" "You're not going to score any points this way!"]

set tctrythenextone [list "emang susah yah ? kok pada diem seh ?" "siap-siap buat pertanyaan selanjutnya" "ok deh qta ganti pertanyaannya" "kalo emang susah kita ganti pertanyaannya" "wah kayaknya mesti belajar lagi neh atau mau saya kasih contekan ?:)"]

set tctimeanswer 1

set tcshowanswer 1

set tcshowallscores 0

set tcusebold 0

set tcpriv2msg 0

set tccmdhelp "?"

set tccmdstart "!startsssss"

set tcflagsstart "-|-"

set tccmdstop "!stopsssssss"

set tcflagsstop "o|o"

set tccmdhint "!hintssssss"

set tcflagshint "-|-"

set tctempnohint 10

set tccmdskip "!skipsssssss"

set tcflagsskip "o|o"

set tccmdtop10 "!top10sssssss"

set tcflagstop10 "-|-"

set tccmdreset "resetssssssss"

set tcflagsreset "m|m"

set tcresetreqpw 1

set tcrules "No advertising, no profanity, no harassing of users, no active scripts and no flooding. Break the rules and expect to be banned. Have fun. :-)"

set tcerrremindtime 15


set tccolourstart "03"		;#Game has started.
set tccolourstop "04"		;#Game has stopped.
set tccolourskip "10"		;#Question has been skipped.
set tccolourerr "04"		;#How to report errors.
set tccolourmiss "10"		;#Nobody answered the question.
set tccolourqhead "04"		;#Question heading.
set tccolourqbody "12"		;#Question text
set tccolourhint "03"		;#Hint.
set tccolourstrk "12"		;#Person is on a winning streak.
set tccolourscr1 "04"		;#Score of person in first place.
set tccolourscr2 "12"		;#Score of person in second place.
set tccolourscr3 "03"		;#Score of person in third place.
set tccolourrset "04"		;#Scores have been reset.
set tccolourstend "12"		;#Winning streak ended.
set tccolourmisc1 "06"		;#Miscellaneous colour #1.
set tccolourmisc2 "04"		;#Miscellaneous colour #2.
set tccolourmpca "00,04"	;#Color of multiplechoice answer code

set tcwrngansw " "


set tcver "1.3.4"
set tcrel "release"
if {[info tclversion]<8.2} {
	putlog "\002[file tail [info script]]\002 failed to load: in order to use this script, eggdrop needs to be compiled to use tcl 8.2 or higher (recommended: latest stable version)."
	return
}
if {$tctimeanswer==1&&[info tclversion]<8.3} {
	putlog "\002[file tail [info script]]\002 warning: timing of answers has been automatically disabled. this feature requires tcl 8.3 or higher."
	set tctimeanswer 0
}
if {![info exists alltools_loaded]||$allt_version<205} {
	putlog "\002[file tail [info script]]\002 failed to load: please load alltools.tcl v1.14 or higher (available with eggdrop 1.6.13 or higher) before attempting to load this script."
	return
}
if {[utimerexists tchtml]!=""} {killutimer $tchtmlrefreshtimer}
if {$tchtmlrefresh>0} {
	set tchtmlrefreshtimer [utimer $tchtmlrefresh tchtml]
}
if {![file exists $tcqdb]} {
	putlog "\002[file tail [info script]]\002 failed to load: $tcqdb does not exist."
	return
}
if {[llength [split $tcchan]]!=1} {
	putlog "\002[file tail [info script]]\002 failed to load: too many channels specified."
	return
}
if {![info exists tcplaying]} {
	set ctcp-version "${ctcp-version} kamus.tcl M.C.-questions and categories. Based upon $tcver ($tcrel) from www.ast3rix.net)"
	set tcplaying 0
}
if {![info exists tchintnum]} {set tchintnum 0}
if {![info exists tcmissed]} {set tcmissed 0}

#Binds
bind pubm $tcflagsstart "$tcchan %$tccmdstart" tcstart
bind pubm $tcflagsstop "$tcchan %$tccmdstop" tcstop
proc tcbindhintcmd {} {
	global tcflagshint tccmdhint
	bind pubm $tcflagshint "$::tcchan %$tccmdhint" tcforcehint
}
proc tcunbindhintcmd {} {
	global tcflagshint tccmdhint
	unbind pubm $tcflagshint "$::tcchan %$tccmdhint" tcforcehint
}
tcbindhintcmd
bind pubm $tcflagsskip "$tcchan %$tccmdskip" tcskip
bind pubm $tcflagstop10 "$tcchan %$tccmdtop10" tcshowtop10
bind join -|- "$tcchan *" tcjoinmsg
bind msg - $tccmdhelp tcgivehelp
bind kick - "$tcchan $botnick" tcbotcotkicked
bind evnt - disconnect-server tcbotcotdisconnected


#this is the new choose command
bind pubm $tcflagschoose "$tcchan %$tcchoosecmd" give_choicenew
proc give_choicenew {nick uhost handle channel args} {
 global questions tcplaying tcqdb quest usedq questionno questionfiles gameplaying gameonoff chan tcquestionstotal tctotalquestfiles tcquestionfiles tcset_catcentrig tcchoosecmd 
  if {$tcplaying != 0} {
  putserv "PRIVMSG $channel :Game is already running, please either wait for it to finish or enter !stop (if ur autorized) then $tcchoosecmd again to set category"
	return
}
	set questionno 0
	set quest ""
	set usedq ""
	set tcset_catcentrig ""
set tcquestionfiles [split $questionfiles]
set tctotalquestfiles [llength $questionfiles]
 		set i 0
			while {$i<$tctotalquestfiles} {
			set tcfilename [lindex [split [lindex $tcquestionfiles $i] &] 0]
			set tcdesc [lindex [split [lindex $tcquestionfiles $i] &] 1]
			if {$tcqdb ==$tcfilename} {tcgamemsg "[tccolqbody] Current category:\00304$tcdesc[tccolqbody] with \00304$tcquestionstotal [tccolqbody]questions"}
			incr i
			}
			tcgamemsg "[tccolqbody] Current \00304$tctotalquestfiles\003 [tccolqbody]categories available."
 			set i 0
			set qfile ""
			while {$i<$tctotalquestfiles} {
			set tcfilename [lindex [split [lindex $tcquestionfiles $i] &] 0]
			set tcdesc [lindex [split [lindex $tcquestionfiles $i] &] 1]
			set qfile [open $tcfilename r]
			set tclist [split [read -nonewline $qfile] "\n"]
			set tcquestioncount [llength $tclist]
			close $qfile
			incr i
			tcgamemsg "\00304$tcdesc[tccolqbody] with \00304$tcquestioncount\003 [tccolqbody]questions."
				bind pub -|- $tcdesc set_catcen
				lappend tcset_catcentrig $tcdesc
			}
			tcgamemsg "[tccolqbody] Which category u want to use?"
}

#set category
proc set_catcen {nick uhost handle channel text} {
 global tcqdb tctotalquestfiles tcquestionfiles tcdesc lastbind tcset_catcentrig tccmdstart
 			set i 0
 			while {$i<$tctotalquestfiles} {
			set tcfilename [lindex [split [lindex $tcquestionfiles $i] &] 0]
			set tcdesc [lindex [split [lindex $tcquestionfiles $i] &] 1]
			if {[strlwr $tcdesc] != [tcstripcodes [strlwr [string trim $lastbind]]]} {
			incr i
			}
			if {[strlwr $tcdesc] == [tcstripcodes [strlwr [string trim $lastbind]]]} {
			tcgamemsg "[tccolqbody] Current category set to: \00304$lastbind"
			tcgamemsg "[tccolqbody] Use \00304$tccmdstart[tccolqbody] to start the game!"
			set tcqdb $tcfilename
						set i 0
			 			while {$i<$tctotalquestfiles} {
			 			unbind pub -|- [lindex $tcset_catcentrig $i] set_catcen		
			 			incr i
			 			}
			return
			}	
	}
}
###############################################################################
#starts the game if it isn't running.
proc tcstart {nick host hand chan text} {
	global tcplaying tcstreak tcchan tcerrremindtime tcerrremindtimer tcmissed tcchoosecmd tccheat
	if {[strlwr $tcchan]==[strlwr $chan]} {
		if {$tcplaying==0} {
		if {$tccheat != "ON"} {set tccheat "OFF"}			
			tcgamemsg "[tccolstart]Trivia game started by $nick! For an other category use: $tcchoosecmd [tccolstart]The cheat protection is \00304$tccheat"
			tcnextq
			set tcplaying 1
			set tcstreak 0
			set tcmissed 0
			set tcerrremindtimer [timer $tcerrremindtime tcerrremind]
		}
	}
}


#stops the game if it's running.
proc tcstop {nick host hand chan text} {
	global tchinttimer tcnextqtimer tcplaying tcchan tccurrentanswer tcstreak tcstreakmin
	global tcerrremindtimer tcrebindhinttimer
	if {[strlwr $tcchan]==[strlwr $chan]} {
		if {$tcplaying==1} {
			tcgamemsg "[tccolstop]Trivia game stopped by $nick!"
			if {$tcstreakmin>0&&[lindex [split $tcstreak ,] 1]>=$tcstreakmin} { tcstreakend }
			set tcstreak 0
			set tcplaying 0
			catch {unbind pubm -|- "$tcchan *" tccheckanswer}
			if {[utimerexists tchint]!=""} {killutimer $tchinttimer}
			if {[utimerexists tcnextq]!=""} {killutimer $tcnextqtimer}
			if {[timerexists tcerrremind]!=""} {killtimer $tcerrremindtimer}
			if {[utimerexists tcrebindhinttimer]!=""} {killtimer $tcrebindhinttimer}
		}
	}
}

#gives a hint if there is currently a question to answer.
proc tcforcehint {nick host hand chan text} {
	global tchinttimer tcnextqtimer tcplaying tcchan tccurrentanswer tcstreak tcstreakmin
	global tctempnohint tcmaxhintcurrent tchintnum tcrebindhinttimer tctempnohint
	
	if {[strlwr $tcchan]==[strlwr $chan]} {
		if {$tcplaying==1&&[utimerexists tchint]!=""} {
			killutimer $tchinttimer
			tchint
			tcunbindhintcmd
			if {$tchintnum<$tcmaxhintcurrent} {
				set tcrebindhinttimer [utimer $tctempnohint tcbindhintcmd]
			}
		}
	}
}

#skips the current question if one has been asked.
proc tcskip {nick host hand chan text} {
	global tchinttimer tcnextqtimer tcplaying tcchan tccurrentanswer tcstreak
	global tcstreakmin tctimenext tcrebindhinttimer
	if {[strlwr $tcchan]==[strlwr $chan]} {
		if {$tcplaying==1&&[utimerexists tchint]!=""} {
			tcgamemsg "[tccolskip]Skipping to next question by [tccolmisc2]$nick's[tccolskip] request..."
			if {$tcstreakmin>0&&[lindex [split $tcstreak ,] 1]>=$tcstreakmin&&[strlwr [lindex [split $tcstreak ,] 0]]==[strlwr $nick]} {
				tcstreakend
				set tcstreak 0
			}
			catch {unbind pubm -|- "$tcchan *" tccheckanswer}
			killutimer $tchinttimer
			if {[utimerexists tcrebindhinttimer]!=""} {killtimer $tcrebindhinttimer}
			set tcnextqtimer [utimer $tctimenext tcnextq]
		}
	}
}

#reminds channel how to report errors in questions/answers
proc tcerrremind {} {
	global tcerrremindtimer tcerrremindtime botnick tccmderror
	tcgamemsg "[tccolerr]Remember: to report errors in questions/answers, type /msg $botnick $tccmderror <number> \[description\]"
	set tcerrremindtimer [timer $tcerrremindtime tcerrremind]
}

#bot got kicked. stop the game.
proc tcbotcotkicked {nick host hand chan targ text} {
	tcquietstop
}

#bot got disconnected. stop the game.
proc tcbotcotdisconnected {disconnect-server} {
	tcquietstop
}

#stops the game without telling the channel.
proc tcquietstop {} {
	global tcplaying tcstreak tcchan tccurrentanswer tchinttimer tcnextqtimer tcerrremindtimer
	global tcrebindhinttimer
	if {$tcplaying==1} {
		set tcstreak 0
		set tcplaying 0
		catch {unbind pubm -|- "$tcchan *" tccheckanswer}
		if {[utimerexists tchint]!=""} {killutimer $tchinttimer}
		if {[utimerexists tcnextq]!=""} {killutimer $tcnextqtimer}
		if {[timerexists tcerrremind]!=""} {killtimer $tcerrremindtimer}
		if {[utimerexists tcrebindhinttimer]!=""} {killtimer $tcrebindhinttimer}
	}
}

#reads the question database.
proc tcreadqdb {} {
	global tcqdb tcquestionstotal tcquestionslist
	set tcquestionstotal 0
	set tcquestionslist ""
	set qfile [open $tcqdb r]
	set tcquestionslist [split [read -nonewline $qfile] "\n"]
	set tcquestionstotal [llength $tcquestionslist]
	close $qfile
}

#selects the next question.
proc tcnextq {} {
	global tcqdb tccurrentquestion tccurrentanswer tcquestionnumber
	global tcquestionstotal tchintnum tcchan tcquestionslist tcqdbsep tcqdbquestionfirst
	global tccapsquestion tccapsanswer
	tcreadqdb
	set tccurrentquestion ""
	set tccurrentanswer ""
	while {$tccurrentquestion == ""} {
		set tcquestionnumber [rand [llength $tcquestionslist]]			
		set tcquestionselected [lindex $tcquestionslist $tcquestionnumber]
#Striping all the *mess* leaving alphanumeric.
		set tcquestionselected [tcstripcodes $tcquestionselected]

		set tccurrentquestion [lindex [split $tcquestionselected $tcqdbsep] [expr $tcqdbquestionfirst^1]]
		if {$tccapsquestion==1} {
			set tccurrentquestion [strupr $tccurrentquestion]
		}
		set tccurrentanswer [string trim [lindex [split $tcquestionselected $tcqdbsep] $tcqdbquestionfirst]]
		if {$tccapsanswer==1} {
			set tccurrentanswer [strupr $tccurrentanswer]
		}
	}
	unset tchintnum
	tchint
	bind pubm -|- "$tcchan *" tccheckanswer
	return
}

#shows timed hints.
proc tchint {} {
	global tcmaxhint tchintnum tccurrentanswer tchinttimer tcchan tcmultiplesep tcmultifact
	global tctimehint tchintchar tcquestionnumber tcquestionstotal
	global tccurrentquestion tchintcharsused tcnextqtimer tctimenext tcstreak tcstreakmin
	global tcnobodygotit tctrythenextone tcmissed tcmaxmissed tccmdstart tcshowanswer
	global tctimestart tctimeanswer tcalwaysshowq tcmaxhintcurrent tctempnohint tccapshint tcwrngansw
	global KAOSAnswers KAOSNumAnswered KAOSQuestionTimer KAOSAdTimer
	#global cepotcurrentanswer cepothinttimer cepottimenext cepotchan cepotnextqtimer cepotstreak cepotstreakmin
	#global cepotscoresbyname cepotranksbyname cepotranksbynum cepotcongrats cepotscorestotal cepotmissed
	#global cepottimestart cepotshowallscores cepotrealnames cepotscoresbyrank cepottimeanswer


	if {[catch {incr tchintnum}]!=0} {
		set tchintnum 0
		regsub -all -- "\[^A-Za-z0-9\]" $tccurrentanswer "" _hintchars
		set tcmaxhintcurrent [expr [strlen $_hintchars]<=$tcmaxhint?[expr [strlen $_hintchars]-1]:$tcmaxhint]
		catch {tcunbindhintcmd}
		if {$tcmaxhintcurrent>0} {
			set tcrebindhinttimer [utimer $tctempnohint tcbindhintcmd]
		}
	}
	if {$tchintnum >= [expr $tcmaxhintcurrent+1]} {
		incr tcmissed
		set _msg ""
		append _msg "\0032Waktunya telah habis..."

		if {$tcshowanswer==1} {
			append _msg "\0036 $tccurrentanswer"
		}
		if {$tcmaxmissed>0&&$tcmissed>=$tcmaxmissed} {
			append _msg " That's $tcmissed questions gone by unanswered! The game is now automatically disabled. To start the game again, type $tccmdstart"
			tcquietstop
		} else {
			append _msg ""
		}
		tcgamemsg "[tccolmiss]$_msg"
		if {$tcstreakmin>0&&[lindex [split $tcstreak ,] 1]>=$tcstreakmin} { tcstreakend }
		set tcstreak 0
		catch {unbind pubm -|- "$tcchan *" tccheckanswer}
		if {$tcmaxmissed==0||$tcmissed<$tcmaxmissed} {
		KAOSAskQuestion
		#set cepotnextqtimer [utimer $cepottimenext cepotnextq]
 			#set cepotplaying 1
 			#set cepotstreak 0
 			#set cepotmissed 0

#			set tcnextqtimer [utimer $tctimenext tcnextq]
		}
		return
	} elseif {$tchintnum == 0} {
		set i 0
		set _hint {}
		set tchintcharsused {}
		foreach word [split $tccurrentanswer] {
			regsub -all -- "\[A-Za-z0-9\]" $word $tchintchar _current
			lappend _hint $_current
		}
		if {$tctimeanswer==1} {
			set tctimestart [clock clicks -milliseconds]
		}
	} elseif {$tchintnum == 1} {
		set i 0
		set _hint {}
		while {$i<[llength [split $tccurrentanswer]]} {
			set _word [lindex [split $tccurrentanswer] $i]
			set j 0
			set _newword {}
			while {$j<[strlen $_word]} {
				if {$j==0} {
					append _newword [stridx $_word $j]
					lappend tchintcharsused $i,$j
				} else {
					if {[string is alnum [stridx $_word $j]]} {
						append _newword $tchintchar
					} else {
						append _newword [stridx $_word $j]
						lappend tchintcharsused $i,$j
					}
				}
				incr j
			}
			lappend _hint $_newword
			incr i
		}
		} else {
			set i 0
			set _hint {}
			while {$i<[llength [split $tccurrentanswer]]} {
				set _word [lindex [split $tccurrentanswer] $i]
				set j 0
				set _newword {}
				set _selected [rand [strlen $_word]]
				regsub -all -- "\[^A-Za-z0-9\]" $_word "" _wordalnum
				if {[strlen $_wordalnum]>=$tchintnum} {
					while {[lsearch $tchintcharsused $i,$_selected]!=-1||[string is alnum [stridx $_word $_selected]]==0} {
					 set _selected [rand [strlen $_word]]
					}
				}
				lappend tchintcharsused $i,$_selected
				while {$j<[strlen $_word]} {
					if {[lsearch $tchintcharsused $i,$j]!=-1||[string is alnum [stridx $_word $j]]==0} {
						append _newword [stridx $_word $j]
					} else {
						if {[string is alnum [stridx $_word $j]]} {
							append _newword $tchintchar
						}
				}
				incr j
			}
			lappend _hint $_newword
			incr i
		}
	}
	if {$tccapshint==1} {
		set _hint [strupr $_hint]
	}
	tcgamemsg "0,2..:: Competition Game 8\[11 Pilihan Ganda8 \] 0Tegal@DALnet ::.."
 # reseting wronganswer counter # tcgamemsg "resetting wrong answer counter for the hint"
	set tcwrngansw ""
#Detection of a multiplechoice question
set tcmultiple 0	
set tcmultiquestion [split $tccurrentquestion $tcmultiplesep]
set tcmultiple [llength $tcmultiquestion]
#Normal question
if {$tcmultiple==0} {
if {$tcalwaysshowq==1||$tchintnum==0} {
 
		tcgamemsg "\0036 $tccurrentquestion geen multiple"
	}
}
#Detected an multiplechoice 
if {$tcmultiple!=0} {
if {$tcalwaysshowq==1||$tchintnum==0} {
		set i 0
			while {$i<$tcmultiple} {
			if {$i==0} {
			tcgamemsg "\0032 [lindex $tcmultiquestion $i]"
			}
			if {$i!=0} {
			set tcanswername [strupr [string range [lindex $tcmultiquestion $i] 0 0]]
			set tcanswertxt [string range [lindex $tcmultiquestion $i] 2 end]
			tcgamemsg "2 $tcanswername  : $tcanswertxt"
			}
			incr i
			}
	}
}
	tcgamemsg "0,2..:: 11+10 0Points Bila Anda Menjawab Dengan Benar ::.."
	if {$tcmultiple ==0 } {	set tchinttimer [utimer $tctimehint tchint]}
	if {$tcmultiple !=0 } {	set tchinttimer [utimer [expr $tctimehint+$i] tchint]}
}

#checks if anyone has said the correct answer on channel.
proc tccheckanswer {nick host hand chan text} {
	global tccurrentanswer tcwrngansw tccommandlist tccheat
#cheat protection on
		if {$tccheat == "ON"} {
		if {[strlwr $tccurrentanswer] != [tcstripcodes [strlwr [string trim $text]]]} {
		
		if { ([string length $text] == [string length $tccurrentanswer]) || [string first $text $tccommandlist] != -1} {
		set firstone [lsearch $tcwrngansw $nick]
		if {$firstone ==-1} {lappend tcwrngansw $nick}
	   if {$firstone !=-1} {tcgamemsg "\0036 $nick, \0032ga bisa jawab dua kali. tunggu soal berikutnya ok!"}		
		}
	}
	
 	if {[strlwr $tccurrentanswer] == [tcstripcodes [strlwr [string trim $text]]]} {
 			set firstone [lsearch $tcwrngansw $nick]
		if {$firstone ==-1} {
		tccorrectanswer $nick
			}
		if {$firstone !=-1} {tcgamemsg "\0036 $nick, \0032jangan asal nebak jawabannya, Tadi kan udah salah jawab"}
		}
		return
	}
	
#cheatprotection is not ON
		if {[strlwr $tccurrentanswer] == [tcstripcodes [strlwr [string trim $text]]]} {
		tccorrectanswer $nick
		}
}

#triggered when someone says the correct answer.
proc tccorrectanswer {nick} {
	global tccurrentanswer tchinttimer tctimenext tcchan tcnextqtimer tcstreak tcstreakmin
	global tccongrats tcmissed
	global tctimestart tcrealnames tctimeanswer tcpointsperanswer
      global KAOSAnswers KAOSNumAnswered KAOSQuestionTimer KAOSAdTimer
    global lastwinner lastwinnercount botnick userlist quizconf rankfile timerankreset

	#global cepotcurrentanswer cepothinttimer cepottimenext cepotchan cepotnextqtimer cepotstreak cepotstreakmin
	#global cepotscoresbyname cepotranksbyname cepotranksbynum cepotcongrats cepotscorestotal cepotmissed
	#global cepotimestart cepotshowallscores cepotrealnames cepotscoresbyrank cepottimeanswer
	

    variable bestscore 0 lastbestscore 0 lastbest ""
    variable userarray
    variable waitforrank 0 gameend 0

    mx_getcreate_userentry $nick $nick
    array set userarray $userlist($nick)
#    set hostmask $userarray(mask)

	    set lastbest [lindex [lsort -command mx_sortrank [array names userlist]] 0]
	    if {$lastbest == ""} {
		set lastbestscore 0
	    } else {
		array set aa $userlist($lastbest)
		set lastbestscore $aa(score)
	    }
	    incr userarray(score) $tcpointsperanswer
	    if {$userarray(score) == 1} {
		set userarray(started) [unixtime]
	    }
	    set userlist($nick) [array get userarray]

	set _timetoanswer ""
	if {$tctimeanswer==1} {
		set _timetoanswer [expr [expr [clock clicks -milliseconds]-$tctimestart]/1000]
	}
	set _msg "2Jawaban Benar: 6 $tccurrentanswer 2oleh 6 $nick 2setelah 6 $_timetoanswer 2detik -  Score: 6+10 2Points.  Total Score:6  $userarray(score) 2Points - Rank:6  [mx_get_rank_pos $nick]"
	tcgamemsg "$_msg"
#	pushmode $tcchan +v $nick
	if {$tcstreak!=0} {
		if {[lindex [split $tcstreak ,] 0]==[strlwr $nick]} {
			set tcstreak [strlwr $nick],[expr [lindex [split $tcstreak ,] 1]+1]
			if {$tcstreakmin>0&&[lindex [split $tcstreak ,] 1]>=$tcstreakmin} {
				tcgamemsg "[tccolstrk][tccolmisc2]$nick[tccolstrk] is on a winning streak! [tccolmisc2][lindex [split $tcstreak ,] 1] [tccolstrk]in a row so far!"
			}
		} else {
			if {$tcstreakmin>0&&[lindex [split $tcstreak ,] 1]>=$tcstreakmin} { tcstreakend }
			set tcstreak [strlwr $nick],1
		}
	} else {
		set tcstreak [strlwr $nick],1
	}
	set tcmissed 0
	catch {unbind pubm -|- "$tcchan *" tccheckanswer}
	killutimer $tchinttimer
      tmcquiz_rank_save {} {} {}    
 	KAOSAskQuestion
	#set cepotnextqtimer [utimer $cepottimenext cepotnextq]
 			#set cepotplaying 1
 			#set cepotstreak 0
 			#set cepotmissed 0

#	set tcnextqtimer [utimer $tctimenext tcnextq]
}

proc tcstripcodes {text} {
	regsub -all -- "\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?" $text "" text
#stripping tabs as well
	regsub -all -- "\t" $text " " text
	set text "[string map -nocase [list \002 "" \017 "" \026 "" \037 ""] $text]"
	return $text
}

proc tcgamemsg {what} {
	global tcchan

	putquick "PRIVMSG $tcchan :[tcbold]$what"
}

proc tcbold {} {
	global tcusebold
	if {$tcusebold==1} { return "\002" }
}
proc tccolstart {} {
	global tccolourstart
	if {$tccolourstart!=""} { return "\003$tccolourstart" }
}
proc tccolstop {} {
	global tccolourstop
	if {$tccolourstop!=""} { return "\003$tccolourstop" }
}
proc tccolskip {} {
	global tccolourskip
	if {$tccolourskip!=""} { return "\003$tccolourskip" }
}
proc tccolerr {} {
	global tccolourerr
	if {$tccolourerr!=""} { return "\003$tccolourerr" }
}
proc tccolmiss {} {
	global tccolourmiss
	if {$tccolourmiss!=""} { return "\003$tccolourmiss" }
}
proc tccolqhead {} {
	global tccolourqhead
	if {$tccolourqhead!=""} { return "\003$tccolourqhead" }
}
proc tccolqbody {} {
	global tccolourqbody
	if {$tccolourqbody!=""} { return "\003$tccolourqbody" }
}
proc tccolhint {} {
	global tccolourhint
	if {$tccolourhint!=""} { return "\003$tccolourhint" }
}
proc tccolstrk {} {
	global tccolourstrk
	if {$tccolourstrk!=""} { return "\003$tccolourstrk" }
}
proc tccolscr1 {} {
	global tccolourscr1
	if {$tccolourscr1!=""} { return "\003$tccolourscr1" }
}
proc tccolscr2 {} {
	global tccolourscr2
	if {$tccolourscr2!=""} { return "\003$tccolourscr2" }
}
proc tccolscr3 {} {
	global tccolourscr3
	if {$tccolourscr3!=""} { return "\003$tccolourscr3" }
}
proc tccolrset {} {
	global tccolourrset
	if {$tccolourrset!=""} { return "\003$tccolourrset" }
}
proc tccolstend {} {
	global tccolourstend
	if {$tccolourstend!=""} { return "\003$tccolourstend" }
}
proc tccolmisc1 {} {
	global tccolourmisc1
	if {$tccolourmisc1!=""} { return "\003$tccolourmisc1" }
}
proc tccolmisc2 {} {
	global tccolourmisc2
	if {$tccolourmisc2!=""} { return "\003$tccolourmisc2" }
}
proc tcpriv {} {
	global tcpriv2msg
	if {$tcpriv2msg==1} { return "putmsg" } else { return "putnotc" }
}
proc tccolmpca {} {
	global tccolourmpca
	if {$tccolourmpca!=""} {return "\003$tccolourmpca" }
}

#this generates an html file with all the people on the chan with
#their score, as well as a list of all scores, sorted by rank
proc tchtml {} {
	global tcchan botnick tchtmlfile tchtmlrefresh server tcscoresbyname tcranksbyname
	global tcscorestotal tcranksbyname tcrealnames tcscoresbyrank tcranksbynum tcplaying
	global tcquestionstotal tchtmlrefreshtimer tchtmlfont
	tcgetscores
	tcreadqdb
	set _file [open $tchtmlfile~new w]
	puts $_file "<!DOCTYPE HTML PUBLIC \"-/W3C/DTD HTML 4.01 Transitional/EN\">"
	puts $_file "<html>"
	puts $_file " <head>"
	puts $_file "  <title>$botnick's trivia channel: $tcchan on [lindex [split $server :] 0]</title>"
	puts $_file "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">"
	puts $_file "  <meta http-equiv=\"refresh\" content=\"$tchtmlrefresh\">"
	puts $_file "  <meta name=\"generator\" content=\"trivia.tcl script for eggdrop. http://www.eggdrop.za.net/\">"
	puts $_file "  <style type=\"text/css\">"
	puts $_file "  <!--"
	puts $_file "  body,td{font-family:$tchtmlfont;font-size:13px;}"
	puts $_file "  a{text-decoration:none;color:#09f;}"
	puts $_file "  -->"
	puts $_file "  </style>"
	puts $_file " </head>"
	puts $_file " <body>"
	puts $_file "  <h1>$tcchan on [lindex [split $server :] 0]</h1>"
	puts $_file "  <hr size=\"1\" noshade>"
	if {![onchan $botnick $tcchan]} {
		puts $_file "  <p>Hmmm... for some reason I'm not on $tcchan at the moment. Please try again later.</p>"
	} else {
		puts $_file "  <p>Trivia game is currently <b>[expr $tcplaying==1?"on":"off"]</b>. There are <b>$tcquestionstotal</b> questions in the database."
		puts $_file "  <p>People on $tcchan right now:<br>"
		puts $_file "  <table width=\"50%\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\"><tr><td><table width=\"100%\" cellspacing=\"3\" border=\"0\">"
		puts $_file "   <tr>"
		puts $_file "    <td><b>Nick</b></td>"
		puts $_file "    <td><b>Score</b></td>"
		puts $_file "    <td><b>Rank</b></td>"
		puts $_file "    <td><b>Idle</b></td>"
		puts $_file "   </tr>"
		foreach nick [lsort [chanlist $tcchan]] {
			puts $_file "   <tr>"
			puts $_file "    <td>[expr [isop $nick $tcchan]?"@":""][expr [isvoice $nick $tcchan]?"+":""]$nick[expr [string match $nick $botnick]?" (that's me!)":""]</td>"
			if {[info exists tcscoresbyname([strlwr $nick])]} {
				puts $_file "    <td>$tcscoresbyname([strlwr $nick])</td>"
			} else {
				puts $_file "    <td>-</td>"
			}
			if {[info exists tcranksbyname([strlwr $nick])]} {
				puts $_file "    <td>$tcranksbyname([strlwr $nick])</td>"
			} else {
				puts $_file "    <td>-</td>"
			}
			puts $_file "   <td>[expr [getchanidle $nick $tcchan]>10?"[getchanidle $nick $tcchan]m":"-"]</td>"
			puts $_file "   </tr>"
		}
		puts $_file "  </table></td></tr></table>"
	}
	if {$tcscorestotal>0} {
		puts $_file "  <p><small>There [expr $tcscorestotal==1?"is":"are"] currently <b>$tcscorestotal</b> [expr $tcscorestotal==1?"nick":"nicks"] in the score table:<br>"
		set _rank 1
		while {$_rank<=$tcscorestotal} {
			puts $_file "  <b>$_rank</b>. $tcrealnames($tcranksbynum($_rank)) $tcscoresbyrank($_rank)<br>"
			incr _rank
		}
	} else {
		puts $_file "  <p><small>There are currently no nicks in the score table.<br>"
	}
	puts $_file "  </small></p>"
	puts $_file "  <hr size=\"1\" noshade>"
	puts $_file "  <small>Generated on [strftime %A,\ %d\ %B\ %Y\ @\ %H:%M:%S] by <a href=\"http://www.eggdrop.za.net/\">trivia.tcl</a> for <a href=\"http://www.eggheads.org\">eggdrop</a>.<br>"
	puts $_file "  This page is automatically updated (and refreshed if supported by your browser) every [expr $tchtmlrefresh==1?"second":"$tchtmlrefresh seconds"].</small>"
	puts $_file " </body>"
	puts $_file "</html>"
	close $_file
	file rename -force $tchtmlfile~new $tchtmlfile
	set tchtmlrefreshtimer [utimer $tchtmlrefresh tchtml]
}

putlog "Pilihan Ganda by Roney SuccessFully Loaded"

