All pastes #886578 Raw Edit

Mine

public text v1 · immutable
#886578 ·published 2008-01-31 19:43 UTC
rendered paste body
;For newer versions check http://web.dreamsoft.com/tat/trivia.htm
;Or for information email DragonRib@yahoo.com
;Please note: Alter, Modify, Butcher or Steal this script in any way you see fit.
;You are also permitted to republish in any form

alias trivia.version { return 3.21 }
;########################################################
;# Direct IRC interactions.                             #
;########################################################
on *:START: { init }
on *:LOAD: {
  var %v = 6.01
  if ($version < %v) {
    echo Please use mIRC %v or later.
    if ($input(Not using mirc %v or later, would you like to use the script anyway?,8,Override?)) { init.load }
    else { unload -rs $script }
  }
  else { init.load }
}
on *:INVITE:*: { if ($trivchan) { join $chan } }
on *:JOIN:*: {
  inc -u5 %trivia.netsplit
  if ((%trivia.netsplit >= 3) || (!$trivchan) || (!$getset(status,bot))) { return }
  if ($nick != $me) { if ($getset(status,onjoin)) { inform $msg.trivia.onjoin } }
  elseif ($getset(status,autostart) == 1) { trivia }
  award join $nick
}
on *:INPUT:#goldenmembers: {
  if ((!$trivchan) || (/* iswm $1-)) { return }
  if ($pre $+ * iswm $1-) { processcommand $1- }
  elseif ($question.on) { processguess $1- }
}
on *:ctcpreply:ping*:{ if (% [ $+ ping. [ $+ [ $nick ] ] ] ) { tsay $msg.ping.reply } }
on *:TEXT:*:#goldenmembers:{
  if (($pre $+ * iswm $1-) && ($trivchan)) { processcommand $1- } 
  if (($trivchan) && ($question.on) && ($left($1,1) != /)) { processguess $1- }
}
on *:TEXT:*:?: { if (($pre $+ report* iswm $1-) || ($pre $+ add* iswm $1-)) { processcommand $1- } }
;########################################################
;# Related checks.                                      #
;########################################################
alias tscid { if (($version >= 6) && ($tchan($trivchan,2) != 0) && ($scid($tchan($trivchan,2)) isnum)) { scid $tchan($trivchan,2) } }
alias trivchan {
  var %i = 1, %chan = $tchan(%i)
  while (%chan) {
    if ((((%chan == $iden) && (($version < 6) || (($tchan(%i,2) != 0) && ($ifd($scid($tchan(%i,2)),$cid) == $cid)))) && ((($1 == op) && ($iif($2,$2,$nick) isop %chan)) || ($1 != op))))  { return %i }
    inc %i
    var %chan = $tchan(%i)
  }
}
alias tchan { return $ifd($gettok($getset(chan, $1), $ifd($2,1), 59),$null) }
alias tchan.noqs { setset chan $1 $gettok($getset(chan, $1),1-4,59) }
alias tchan.set {
  if ($3- != $null) {
    var %nl = $getset(chan,$1)
    if (!%nl) { %nl = $1 $+ ;0;0; $+ $scoresfil $+ ; $+ trivia.txt }
    if ($2 > $numtok(%nl,59)) %nl = %nl $+ $str(;0,$calc($2 - $numtok(%nl,59)))
    %nl = $puttok(%nl,$3-,$2,59)
    setset chan $1 %nl
  }
}
;########################################################
;# Menubar and submenu functions.                       #
;########################################################
menu channel,menubar {
  Trivia
  .Trivia Options:{ if (!$dialog(trivset)) { dialog -m trivset trivset } }
  .Start Trivia
  ..Standard:{ $trivia }
  ..Unlimited Game:{ $trivia(unlimited) }
  ..Team Game:{ $trivia(team) }
  ..Theme Game
  ...$submenu($theme.submenu($1))
  ..Specify round:{ $trivia($$?="How many question in the trivia round?") }
  .Stop Trivia:{ strivia }
  .Set Channel:{ chan.add $$chan }
  .Set CID:{ setset trivia cid $cid }
  .-
  .Features
  ..Build Scores HTML:{ htmlbuild }
  ..HTML Options:{  if (!$dialog(trivbuild)) { dialog -m trivbuild trivbuild } }
  ..Themes Setup: {  if (!$dialog(triviatheme)) { dialog -m triviatheme triviatheme } }
  ..$iif($getset(trivia,ranks),Ranks Setup): {  if (!$dialog(trivrank)) { dialog -m trivrank trivrank } }
}
alias theme.submenu {
  if (($1 == begin) || ($1 == end)) return -
  return $getset(triviamode $+ $1, name) $+ : /trivia $getset(triviamode $+ $1, name)
}
menu menubar {
  Trivia
  .Force Question:{ ask }
  .Scores
  ..Scores:{ if (!$dialog(triviascores)) { dialog -m triviascores triviascores } }
  ..Give Points: { trivia.credit $$?="Credit whom?" $$?="How many points do you wish to give, -# to remove score" }
  .Echo
  ..Records:{ tsay $msg.trivia.records }
  ..HoF:{ tsay $msg.trivia.hof }
  ..Repeat:{ tsay $msg.question.current }
  ..Hint:{ tsay $msg.hint.hint }
  .Open
  ..Additions:{ if $exists(" $+ $triv(dir) $+ / $+ $triv(additions) $+ ") { run " $+ $triv(dir) $+ / $+ $triv(additions) $+ " } }
  ..Report:{ if $exists(" $+ $triv(dir) $+ / $+ $triv(report) $+ ") { run " $+ $triv(dir) $+ / $+ $triv(report) $+ " } }
  .-
  .Trivia [ $trivon ] $+ :{ setset status bot $iif($getset(status,bot) == 1,0,1) }
  .-
  .Trivia Unload:{ if ($?!="Really Unload?") { unload -rs $script } }
}
menu nicklist {
  Trivia
  .Control
  ..Ban:{ tban $$1 }
  ..Unban:{ tunban $$1 }
  .Add as Friend: { triviafriend.add $address($$1,7) }
  .Credit
  ..Award
  ...1: { trivia.credit $$1 1 }
  ...5: { trivia.credit $$1 5 }
  ...10: { trivia.credit $$1 10 }
  ..Deduct
  ...1: { trivia.credit $$1 -1 }
  ...5: { trivia.credit $$1 -5 }
  ...10: { trivia.credit $$1 -10 }
  ..Input Amount: { trivia.credit $$1 $$?="How many points do you wish to give, -# to remove score" }
}
;########################################################
;# Menubar related, aliases.                            #
;########################################################
alias trivia.credit {
  if ($2 isnum) {
    setvar $1 Score $calc($getvar($1,Score) + $2)
    if ($2 > 0) { tsay $msg.trivia.awarded($1,$2) }
    else { tsay $msg.trivia.deducted($1,$2) }
  }
}
alias -l trivon { return $iif($getset(status,bot), $iif($trivia.paused,Paused,Enabled), Disabled) }
alias -l trivia.chan { return $iif($tchan(1) ischan, Yes, No) }
alias -l trivia.dir { return $iif($isdir(" $+ $triv(dir) $+ "), Yes, No) }
alias -l trivia.file { return $iif($isfile($qfile(1)), Yes, No) }
alias -l trivia.onoff { return $iif($trivia.on, On, Off) }
alias -l team.onoff { return $iif($team, On, Off) }
;########################################################
;# Color aliases.                                       #
;########################################################
alias -l colorcode { return $gettok(default.white.black.blue.green.lightred.brown.purple.orange.yellow.lightgreen.cyan.lightcyan.lightblue.pink.grey.lightgrey,$calc($1 + 1),$asc(.)) }
alias -l fixer { return $base($1,10,10,2) }
alias varcolors {
  unset %c1 %c1o %c2 %c2o
  if (!$getset(color,on)) { return }
  %c1o = $iif($tc(1).b,$chr(2)) $+ $iif($tc(1).u,$chr(31)) $+ $chr(3)
  %c2o = $iif($tc(2).b,$chr(2)) $+ $iif($tc(2).u,$chr(31)) $+ $chr(3)
  %c1 = %c1o $+ $iif($tc(1), $fixer($calc($tc(1) - 1))) $+ $iif(($tc(3)) && ($getset(color,bon)), $chr(44) $+ $fixer($calc($tc(3) - 1)))
  %c2 = %c2o $+ $iif($tc(2), $fixer($calc($tc(2) - 1))) $+ $iif(($tc(4)) && ($getset(color,bon)), $chr(44) $+ $fixer($calc($tc(4) - 1)))
}
alias rdc {  
  var %a
  !.echo -q $regsub($1,/(?<=\x03|\x03\d\d\x2C)(\d)(?!\d)/g,0\1, %a)
  while ($regsub(%a, /(?<=\x03\d\d\x2C\d\d|\x03\d\d\x03|\x03)([\x02\x1F\x16\s]+)(\x03(?:\d\d(?:\x2C\d\d)?)?)/g,\2\1, %a)) { }
  !.echo -q $regsub(%a, /(\x02)([\x1F\x16\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(\x1F)([\x02\x16\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(\x16)([\x02\x1F\s]*)\1/g,\2, %a) $&
    $regsub(%a, /(?:\x03(?:\d\d(?:\x2C\d\d)?)?)+(\x03(?:(?!\d)|\d\d\x2C\d\d))/g,\1, %a) $&
    $regsub(%a, /(?:\x03\d\d)(\x2C\d\d)(?:\x03\d\d)*(\x03\d\d)/g,\2\1, %a) $&
    $regsub(%a, /(?<=\x03\d\d)(\x2C\d\d)([^\x03]+\x03\d\d)\1/g,\1\2, %a)
  while ($regsub(%a,/(\x03\d\d)((\x2C\d\d)?[^\x03]+)\1/g,\1\2, %a)) { }
  !.echo -q $regsub(%a, /^\x03(?!\d)|(\x03(\d\d(\x2C\d\d)?)?|\x02|\x16|\x1F)+$/g,,%a) $&
    $regsub(%a, /(?<=\x03|\x03\d\d\x2C)0(\d)(?!\d)/g,\1, %a)
  return %a
}
;########################################################
;# Init aliases.                                        #
;########################################################
alias -l nset { if ($getset($1, $2) == $null) { setset $1- } }
alias -l init.load {
  convertscores
  convertscores $tempini
  nset award 1 1 1 1 50 0  gives * a high five for getting ^ wins! Way to go * !
  nset award 2 1 1 1 100 0 gives * a large pizza for getting ^ wins! Way to go * !
  nset award 3 1 1 1 150 0 ^ wins... I am not worthy...
  nset award 4 2 1 1 3 0 hands * a cold beer for getting the last ^ questions!
  nset award 5 2 1 1 5 0 hands * 6-pack of icy beers for getting the last ^ questions!
  nset award 6 2 1 1 10 0 gives * keg of beer for kicking everybodies asses! ^ questions!
  nset award 7 2 1 1 15 0 bows before * a trivia god...
  nset award 8 2 2 2 3 5 You're on fire!
  nset award 9 3 4 5 1.5 0 Autoban based on speed.
  nset award 10 4 3 5 120 0 Autoban based on Words per minute.
}
alias -l init {
  nset status bot 1 | nset status echo 0 | nset status autohint 1 | nset status showanswer 1 | nset status cross 1
  nset status number 30 | nset status hintpause 1 | nset trivia additions additions.txt | nset trivia channel #temptrivia 
  nset color 1 $fixer($rand(1,15)) | nset color 2 $fixer($rand(1,15)) | nset trivia default 10 | nset trivia dteam 5 | nset color on 1
  nset trivia delimiter * | nset trivia tnaoff 5 | nset trivia hintpause 5 | nset trivia perchint 30 | nset trivia numhint 1
  nset trivia ppq 1 | nset trivia dph 0 | nset lag answered 10 | nset lag hint 10 | nset lag start 15 | nset lag timed 15
  nset lag timedout 60 | nset lag hintallow 10 | nset trivia questions questions.txt | nset trivia dir $nofile($findfile($mircdir,$triv(questions), 1))
  nset trivia report report.txt | nset trivia reset 1000 | nset team 0victory The *t1 and the *t2 tied | nset team 1 'Team 1's
  nset team 1victory The *t1 beat the *t2 | nset team 2 'Team 2's | nset team 2victory The *t2 beat the *t1 | nset team JoinBefore 2
  nset team JoinBeforeOn 1
  varcolors
}
alias -l trivia.fail {
  if ($version < 5.91) { return Please use mIRC 5.91 or later. }
  if (!$server) { return Please connect to a server before attempting to use $msg.trivia.version }
  if ($getset(status,bot) == 0) { return The trivia bot is off. Commands, Trivia, Disabled to reenable. }
  if ($tchan(1) !ischan) { return You are not in the set trivia channel: $tchan(1) }
  if ($isdir(" $+ $triv(dir) $+ ") == $false) { return The trivia directory, $triv(dir) $+ , is invalid. }
  if (!$numl) { return There appear to be no questions within the question file(s). }
}
alias get.find { if ($qread($1-)) return $qread($1-) - $readn }
;########################################################
;# Trivia command, related aliases.                     #
;########################################################
alias -l ifd { return $iif($1, $1, $2) }
;########################################################
;# Command processing.                                  #
;########################################################
alias pre { return $ifd(%command-prefix, !) }
alias commandtokens { return state;disable;enable;op;trivia;strivia;pause;resume;theme;themes;stats;stat;won;hof;top10;hofstreak;row;streak;hoffast;fast;hofwpm;wpm;server;record;records;champ;version;web;add;report;ping;triviaping;help;join;showteams;roundscores;answer;next;hint;!hint;words;last;vowels;repeat }
alias ctok { return $findtok($commandtokens,$1,1,59) }
alias gtok { return $gettok($commandtokens,$1,59) }
alias -l processcommand {
  var %ctok = $ctok($right($1,-1))
  if (!%ctok) { return }
  set -u0 %ident $chan
  if (%ctok == 1) { inform $msg.trivia.state }
  if (%ctok == 2) { opcommand disable } 
  if (%ctok == 3) { opcommand enable }
  if (%ctok == 4) { opcommand $2- }
  if (($getset(status,bot) == 0) || ($trivia.banned)) { return }
  if (%ctok == 5) { if ($trivia.allowed(on)) { trivia $2- } }
  if (%ctok == 6) { if (($trivia.allowed(off)) && ($trivia.on) && ((!$team) || ($nick isop $iden))) { strivia $iden } }
  if (%ctok == 8) { if (($trivia.paused) && (!$isdis(31))) { trivia.pause 1 } }
  if (%ctok == 7) { if ((!$trivia.paused) && (!$isdis(31))) { trivia.pause } }
  if (%ctok isnum 9-10) { if (!$isdis(5)) { inform $msg.trivia.themes } }
  if (%ctok isnum 11-13) { processcommand.stats $2 }
  if (%ctok isnum 14-15) { if (!$isdis(7)) { inform $msg.trivia.hof } }
  if (%ctok isnum 16-18) { if (!$isdis(8)) { inform $msg.trivia.ten(streak) } }
  if (%ctok isnum 19-20) { if (!$isdis(9)) { inform $msg.trivia.ten(time) } }
  if (%ctok isnum 21-22) { if (!$isdis(10)) { inform $msg.trivia.ten(wpm) } }
  if (%ctok == 23) { inform $server }
  if (%ctok isnum 24-25) { if (!$isdis(15)) { inform $msg.trivia.records } }
  if (%ctok == 26) { inform $msg.trivia.champ }
  if (%ctok == 27) { inform $msg.trivia.version }
  if (%ctok == 28) { inform $msg.trivia.web }
  if (%ctok isnum 29-30) { if (!$isdis(18)) { trivia.report $1- } }
  if (%ctok isnum 31-32) { if (!$isdis(6))  { do.ping } }
  if (%ctok == 33) { givehelp $2- }
  if (%ctok == 34) { if ($team) { $setteam($nick, $2) } }
  if (%ctok == 35) { if ($team) { inform $msg.trivia.showteams } }
  if (%ctok == 36) { inform $msg.trivia.roundscores }
  if (%ctok == 37) { if (($nick isop $chan) && (!$isdis(20))) { inform $msg.question.answer } }
  if ((!$question.on) || ($trivia.paused)) { return }
  if (%ctok == 38) { if (($calc($question.time * 2) >= $lag(timedout)) && (!$isdis(2))) { trivx } }
  if (%ctok isnum 39-43) { 
    if (($question.time >= $lag(hintallow))) {
      if (($getset(trivia, hintpause)) && ($getset(status, hintpause))) { hadd -u $+ $triv(hintpause) Trivia $+ $iden $eval(hinted. $+ $nick,1) 1 }
      if (%ctok isnum 39-40) { if (!$isdis(1)) { give.hint $iden } }
      if (%ctok == 41) { if (!$isdis(21)) { $iif($getset(status,msghint), tsay, inform) $msg.hint.words } }
      if (%ctok == 42) { if (!$isdis(22)) { $iif($getset(status,msghint), tsay, inform) $msg.hint.last } }
      if (%ctok == 43) { if (!$isdis(23)) { $iif($getset(status,msghint), tsay, inform) $msg.hint.vowels } }
    }
  }
  if (%ctok == 44) { if (!$isdis(3)) { inform $$thget(trivq.say) } }
}
alias -l trivia.allowed {
  if (!$getset(status,oponly $+ $$1)) { return $true }
  var %level = $getset(trivia, $1 $+ level)
  if (%level == 5) { return }
  if (($nick isop $chan) && (%level < 4))  { return $true }
  if (($nick ishelp $chan) && (%level < 3)) { return $true }
  if (($nick isvoice $chan) && (%level < 2))  { return $true }
  if (($nick ison $chan) && (%level < 1))  { return $true }
}
;########################################################
;# Help structure.                                      #
;########################################################
alias -l givehelp {
  if (!$1-) {
    inform $e2(Commands:) $e1($pre $+ $gtok(6) $pre $+ $gtok(5) $pre $+ $gtok(39) $pre $+ $gtok(34) $pre $+ $gtok(29) $pre $+ $gtok(30) $pre $+ $gtok(31) $pre $+ $gtok(27) $pre $+ $gtok(28) $pre $+ $gtok(14) $pre $+ $gtok(19) $pre $+ $gtok(16) $pre $+ $gtok(21) $pre $+ $gtok(25) $pre $+ $gtok(38) $pre $+ $gtok(23) $pre $+ $gtok(26) $pre $+ $gtok(44) $pre $+ $gtok(37) $pre $+ $gtok(11) $pre $+ $gtok(1) $pre $+ $gtok(3) $pre $+ $gtok(2) $pre $+ $gtok(10) $pre $+ $gtok(41) $pre $+ $gtok(42) $pre $+ $gtok(43) $pre $+ $gtok(35) $pre $+ $gtok(36) $pre $+ $gtok(4) $pre $+ $gtok(7) $pre $+ $gtok(8))
    inform $e1($pre $+ help <command>) $e2(for specific help. Some commands may be disabled.)
  }
  if ($1 == $pre $+ $gtok(1)) { inform $e1($1 -----) $e2(Displays the state of the bot) }
  if ($1 == $pre $+ $gtok(6)) { inform $e1($1 ---) $e2(Stops trivia) }
  if ($1 == $pre $+ $gtok(3)) { inform $e1($1 ----) $e2(Enables trivia bot) }
  if ($1 == $pre $+ $gtok(2)) { inform $e1($1 ---) $e2(Disables trivia bot) }
  if ($1 == $pre $+ $gtok(7)) { inform $e1($1 ----) $e2(Pauses trivia bot) }
  if ($1 == $pre $+ $gtok(8)) { inform $e1($1 ----) $e2(Resumes trivia bot) }
  if ($1 == $pre $+ $gtok(4)) { inform $e1($1 <command> -) $e1(enable) $+ $e2($chr(44)) $e1(disable) $+ $e2($chr(44)) $e1(ban) $+ $e2($chr(44)) $e1(unban) $+ $e2($chr(44)) $e1(banned) $+ $e2($chr(44)) $e1(add) $+ $e2($chr(44)) $e1(ask) $+ $e2($chr(44)) $e1(find) $+ $e2($chr(44) commands to allow ops to control the trivia bot.) }
  if ($1 == $pre $+ $gtok(5)) { inform $e1($1 x --) $e2(Starts trivia, x can be a number, "unlimited" or "team" for team mode) }
  if ($1 == $pre $+ $gtok(39)) { inform $e1($1 ------) $e2(Gives a hint) }
  if ($1 == $pre $+ $gtok(42)) { inform $e1($1 ------) $e2(Gives the last character of the answer) }
  if ($1 == $pre $+ $gtok(41)) { inform $e1($1 ------) $e2(Gives the number of words in the answer) }
  if ($1 == $pre $+ $gtok(43)) { inform $e1($1 ------) $e2(Gives the vowels of the answer) }
  if ($1 == $pre $+ $gtok(34)) { inform $e1($1 x ----) $e2(Joins a team, must be in team mode, x can be a 1 or 2) }
  if ($1 == $pre $+ $gtok(29)) { inform $e1($1 -------) $e2(Allows you to add questions: $pre $+ add What is the square root of 4*two*2) }
  if ($1 == $pre $+ $gtok(30)) { inform $e1($1 ----) $e2(Lets you report problems with the questions: $pre $+ report The square root of 4 is also -2) }
  if ($1 == $pre $+ $gtok(31)) { inform $e1($1 -----) $e2(Checks your lag from the bot) }
  if ($1 == $pre $+ $gtok(27)) { inform $e1($1 ---) $e2(Displays the version of the bot) }
  if ($1 == $pre $+ $gtok(28)) { inform $e1($1 -------) $e2(Displays the web page for the bot) }
  if ($1 == $pre $+ $gtok(14)) { inform $e1($1 -------) $e2(Displays the hall of fame) }
  if ($1 == $pre $+ $gtok(19)) { inform $e1($1 ---) $e2(Displays the record times) }
  if ($1 == $pre $+ $gtok(16)) { inform $e1($1 --) $e2(Displays the record streaks) }
  if ($1 == $pre $+ $gtok(21)) { inform $e1($1 ----) $e2(Displays the record words per minute) }
  if ($1 == $pre $+ $gtok(25)) { inform $e1($1 ---) $e2(Displays the record row & streak & wpm) }
  if ($1 == $pre $+ $gtok(23)) { inform $e1($1 ----) $e2(Displays the bot's server) }
  if ($1 == $pre $+ $gtok(26)) { inform $e1($1 -----) $e2(Displays the champ stats) }
  if ($1 == $pre $+ $gtok(36)) { inform $e1($1) $e2(Displays the scores for the current round.) }
  if ($1 == $pre $+ $gtok(35)) { inform $e1($1) $e2(Displays the teams and which players are on each.) }
  if ($1 == $pre $+ $gtok(44)) { inform $e1($1 ----) $e2(Repeats the question) }
  if ($1 == $pre $+ $gtok(37)) { inform $e1($1 ----) $e2(Provides the answer to the last question to an op who requests it) }
  if ($1 == $pre $+ $gtok(38)) { inform $e1($1 ----) $e2(After half the time to answer has expired allows an instant timeout.) }
  if ($1 == $pre $+ $gtok(10)) { inform $e1($1 ----) $e2(Lists available themes) }
  if ($1 == $pre $+ $gtok(11)) { inform $e1($1 ------) $e2(Returns your current stats, or $pre $+ stats (name) for somebody else) }
}
;########################################################
;# !Op command structure.                               #
;########################################################
alias -l opcommand {
  if ($isdis(24)) { return }
  if ((!$trivchan(op)) && ($nick != $me) && (!$istrivia.friend)) { return }
  if (($1 == enable) && (!$isdis(4)) && ($getset(status,bot) == 0)) { 
    setset status bot 1
    tsay $msg.trivia.enabled
  }
  if (($1 == disable) && (!$isdis(4)) && ($getset(status,bot) == 1)) {
    setset status bot 0
    tsay $msg.trivia.disabled
    strivia
  }
  if (($1 == ban) && (!$isdis(25))) {
    if (!$2) { inform $e1(You need to specify a user to ban) }
    else {
      tban $2
      inform $e1(User is banned.)
    }
  }
  if (($1 == unban) && (!$isdis(26))) {
    if (!$2) { inform $e1(You need to specify a user to unban) }
    else {
      tunban $2
      inform $e1(User is unbanned.)
    }
  }
  if ($1 == banned) { inform $msg.trivia.banlist }
  if (($1 == ask) && (!$isdis(27))) {
    if ((!$2) || (!$isvalidask($2))) { inform $e1(You need to specify a valid question number to be asked.) }
    else {
      ask $2
      inform $e1(Question will be asked.)
    }
  }
  if (($1 == add) && (!$isdis(28))) {
    if (!$2) { inform $e1(You need append the question that is to be added directly into the question file.) }
    elseif ($triv(delimiter) !isin $2-) { inform $e1(You need at least one delimiter to indicate: question $+ $triv(delimiter) $+ answer) }
    else { 
      add $2-
      inform $e1(Question has been added.)
    }
  }
  if (($1 == find) && (!$isdis(29))) {
    if (!$2) { inform $e1(You need at least some search text.) }
    inform $e1($ifd($get.find($2-),That text was not found.))
  }
}
;########################################################
;# Trivia ON.                                           #
;########################################################
alias trivia {
  tscid
  if (($trivia.banned) || ($trivia.on) || (!$trivchan)) { return }
  if ($trivia.paused) { 
    tsay $msg.trivia.pause
    return
  }
  trivia.flush
  if ($trivia.fail) {
    echo $trivia.fail
    return
  }
  if ($hget(Trivia $+ $iden)) { hfree Trivia $+ $iden }
  hmake Trivia $+ $iden 20
  if ($hget(Asked $+ $iden)) { hfree Asked $+ $iden }
  hmake Asked $+ $iden 50
  trivia.defaultgame
  thset STime $time $date
  thset SUser $iif($nick,$nick,$me)
  if (($getset(Trivia,odefault) == unlimited) || (($1 == unlimited) && (!$isdis(12))) ) { thset Max Unlimited }
  if (($getset(trivia,odefault) == team) || (($1 == team) && (!$isdis(11)))) { thset team 1 }
  if (($1 isnum 0 - $numl) && (!$isdis(13))) { thset Max $int($1) }
  if ($1 == pi) { thset Max 3.14159265358979323846 }
  if (!$isdis(16)) { trivia.themecheck $1- }
  if ($thget(team)) { trivia.teammode $2 }
  tsay $msg.trivia.started
  .timerq $+ $iden 1 $lag(start) trivq $chan
}
;########################################################
;# Trivia OFF.                                          #
;########################################################
alias strivia {
  tscid
  set -u0 %ident $1
  if ($team) { strivia.teammode }
  else {
    tsay $msg.trivia.stopped
    if ($thget(Current) >= 10) { tsay $strivia.end($triv(Record)) }
  }
  trivia.flush
}
alias strivia.end {
  if ($1 == 1) { return $msg.trivia.hof }
  elseif ($1 == 2) { return $msg.trivia.ten(streak) }
  elseif ($1 == 3) { return $msg.trivia.ten(time) }
  elseif ($1 == 4) { return $msg.trivia.ten(wpm) }
  elseif ($1 == 5) { return $msg.trivia.champ }
  elseif ($1 == 6) { return $msg.trivia.web }
  elseif ($1 == 7) { return $msg.trivia.roundscores }
  return $msg.trivia.records
}
;########################################################
;# STATUS CLEARING.                                     #
;########################################################
alias -l trivia.flush {
  if ($hget(Asked $+ $iden)) { hfree Asked $+ $iden }
  if ($hget(Trivia $+ $iden)) { hfree Trivia $+ $iden }
  trivia.timersoff
}
alias -l trivia.timersoff {
  .timer* $+ $iden off
}
;########################################################
;# DEFAULT setup.                                       #
;########################################################
alias trivia.defaultgame {
  thset File questions.txt
  thset Scores $scoresfil
  if ($tchan($trivchan, 4)) { thset Scores $tchan($trivchan, 4) }
  if ($tchan($trivchan, 5)) {
    thset File
    var %i = 5
    while ($tchan($trivchan, %i)) {
      thset File $thget(file) $+ ; $+ $tchan($trivchan, %i)
      inc %i
    }
  }
  thset Max $triv(default)
  thset PPQ $iif($getset(Trivia,PPQ) != $null,$getset(Trivia,PPQ),1)
  thset DPH $iif($getset(Trivia,DPH) != $null,$getset(Trivia,DPH),0)
  thset RRS $iif($getset(Status,RRS) != $null,$getset(Status,RRS),0)
  thset guess $iif($getset(status,oneguess) != $null,$getset(status,oneguess),0)
  thset lagstart $iif($getset(lag, start) != $null, $getset(lag, start), 0)
  thset laganswered $iif($getset(lag, answered) != $null, $getset(lag, answered), 0)
  thset lagtimedout $iif($getset(lag, timedout) != $null, $getset(lag, timedout), 0)
  thset laghint $iif($getset(lag, hint) != $null, $getset(lag, hint), 0)
  thset lagtimed $iif($getset(lag, timed) != $null, $getset(lag, timed), 0)
  thset laghintallow $iif($getset(lag, hintallow) != $null, $getset(lag, hintallow), 0)
}
;########################################################
;# THEMED start.                                        #
;########################################################
alias trivia.themecheck {
  var %i = 1
  while ($getset(triviamode $+ %i, Name)) {
    if ($1 == $getset(triviamode $+ %i, Name)) {
      var %j = $setini(triviamode $+ %i,0)
      while (%j >= 1) {
        var %mode = $setini(triviamode $+ %i, %j)
        thset %mode $getset(triviamode $+ %i, %mode)
        dec %j
      }
      thset File $getset(triviamode $+ %i, file)
      if (($2 isnum) && ($2 <= $numq) && ($2 > 0) && (!$isdis(13))) { thset Max $int($2) }
      return
    }
    inc %i
  }
}
;########################################################
;# TEAM setup.                                          #
;########################################################
alias -l trivia.teammode {
  thset Score1 0
  thset Score2 0
  thset Score3 0
  thset Score4 0
  if ($1 isnum 1 - $numq) { thset Max $int($1) }
  else { thset Max $triv(dteam) }
  tsay $msg.team.start
}
alias -l strivia.teammode {
  var %s1 = $thget(Score1)
  var %s2 = $thget(Score2)
  var %s3 = $thget(Score3)
  var %s4 = $thget(Score4)
  if ($getset(team,4-team)) {
    if ((%s1 > %s2) && (%s1 > %s3) && (%s1 > %s3)) { tsay $msg.team.over($te(1).victory) }
    elseif ((%s2 > %s1) && (%s2 > %s3) && (%s2 > %s4)) { tsay $msg.team.over($te(2).victory) }
    elseif ((%s3 > %s1) && (%s3 > %s2) && (%s3 > %s4)) { tsay $msg.team.over($te(3).victory) }
    elseif ((%s4 > %s1) && (%s4 > %s2) && (%s4 > %s3)) { tsay $msg.team.over($te(4).victory) }
    else { tsay $msg.team.over($te(0).victory) }
  }
  else {
    if (%s1 > %s2) { tsay $msg.team.over($te(1).victory) }
    elseif (%s1 < %s2) { tsay $msg.team.over($te(2).victory) }
    else { tsay $msg.team.over($te(0).victory) }
  }
  if ($getset(status, noshowt)) { tsay $msg.trivia.showteams }
}
alias -l setteam {
  if (($thget(Current) >= $getset(Team, JoinBefore)) && ($getset(Team, JoinBeforeOn) == 1)) { 
    inform $msg.team.joinover
    return 
  }
  if ($2 isnum 1 - 4) {
    if ($thget(Team. $+ $nick) == $2) { inform $msg.team.alreadyon }
    else { tsay $msg.team.add($getset(team,$2), $nick) }
    thset $eval(Team. $+ $nick,1) $2
  }
}
;########################################################
;# Trivia QUESTION.                                     #
;########################################################
alias isvalidask { if ($1 isnum 1 - $numq) { return $true } }
alias trivq {
  tscid
  set -u0 %ident $1
  if (!$hget(Trivia $+ $iden)) { return }
  if ($trivia.fail) {
    echo $trivia.fail
    return
  }
  thset Current $calc($thget(Current) + 1)
  if (($team) && ($thget(Current) == $getset(Team, JoinBefore)) && ($getset(Team, JoinBeforeOn) == 1)) { tsay $msg.team.joinbefore }
  create.question
  .timerend $+ $iden 1 $lag(timedout) trivx $1
  trivia.startautohint
  setset Var Asked $calc($getset(Var,Asked) + 1)
  thset Start $ticks
  trivia.sayquestion $right($thget(catq),-1)
  if ($getset(status,echo) == 1) { echo $iden $e2(Answer:) $e1($trivq.answer) }
  if ($getset(status,answers)) { tsay $msg.hint.answerspace }
}
alias -l create.question {
  if ($thget(ask1)) {
    while ((!$isvalidask($thget(Ask1))) && ($thget(ask1) isnum)) { ask.deleteitem 1 }
    if ($thget(Ask1)) {
      if ($thget(Ask1) !isnum) { thset Trivq $thget(Ask1) }
      else { thset Trivq $qread($thget(ask1)) }
      ask.deleteitem 1
      return
    }
  }
  var %temp.ask = $trivia.getq
  thset Catq $qcat(%temp.ask)
  thset Trivq $qread(%temp.ask)
  hadd Asked $+ $iden %temp.ask %temp.ask
}
alias -l trivia.getq {
  unset %ask
  while ((!%ask) || ($hget(Asked $+ $iden, %ask))) {
    if ($hget(Asked $+ $iden,0).item >= $numq) { hdel -w Asked $+ $iden * }
    var %ask = $rand(1, $numq)
    if (!$gettok($qread(%ask), 2,$asc($triv(delimiter)))) { hadd Asked $+ $iden %ask NA }
  }
  return %ask
}
alias -l ask.deleteitem {
  hdel Trivia $+ $iden Ask $+ $$1
  var %i = $1
  while ($thget(Ask $+ $calc(%i + 1))) {
    thset Ask $+ %i $thget(Ask $+ $calc(%i + 1))
    inc %i
  }
  if ($thget(Ask $+ %i)) { hdel Trivia $+ $iden Ask $+ %i }
}
alias -l trivia.startautohint { if ($getset(status,autohint) == 1) { .timerhint $+ $iden $triv(numhint) $lag(hint) give.hint $iden } }
;########################################################
;#  QUESTION over.                                      #
;########################################################
alias trivx {
  tscid
  set -u0 %ident $1
  if (!$hget(Trivia $+ $iden)) { return }
  if (!$2) {
    if ($getset(status,showanswer)) { tsay $iif($thget(temp.type) == T, $msg.answer.timeout.total, $msg.answer.timeout) }
    else { tsay $msg.answer.timeout2 }
    setset Var Row 0
    thset Unanswered $calc($thget(Unanswered) + 1)
  }
  trivia.timersoff
  if ($window($total.win)) { window -c $total.win }
  thset Answer $trivq.answer
  hdel -w Trivia $+ $iden Temp.*
  if (($getvar($nick,score) >= $triv(reset)) && ($getset(status,champ) == 1)) { trivia.newchamp }
  if ((($team) && ($thget(Score $+ $isteam($nick)) > $calc($thget(Max)/2))) || (($getset(status, naoff) == 1) && ($thget(unanswered) >= $triv(naoff))) || (($thget(Max) != unlimited) && ($thget(Current) >= $thget(Max)))) {
    strivia $1
    if (($getset(status, naoff) == 1) && ($thget(Unanswered) >= $triv(naoff))) { tsay $msg.trivia.unactive }
    return
  }
  .timerq $+ $iden 1 $iif($1, $lag(answered), $lag(timed)) trivq $iden
}
alias -l trivia.processscore {
  if ($getset(Var, Lastwinner) == $nick) { setset Var Row $calc($getset(Var, Row) + 1) }
  else { setset Var Row 1 }
  setset Var Wins $calc($getset(Var,Wins) + 1)
  setset Var Lastwinner $nick
  setvar $nick Lastwin $date
  thset WPM $calc(($len($1-) * 60) / ($thget(Time) * 5))
  if (($thget(WPM) > $getvar($nick,wpm)) || (!$getvar($nick,wpm))) { setvar $nick wpm $thget(WPM) }
  if (($getset(Var, Row) > $getvar($nick,streak)) || (!$getvar($nick,streak))) { setvar $nick Streak $getset(Var, Row) }
  if (($thget(Time) < $getvar($nick,time)) || (!$getvar($nick,time))) { setvar $nick Time $thget(Time) }
  thset temp.cng $calc($thget(PPQ) - ($thget(DPH) * $max.hinted))
  if ($thget(temp.points)) { thset temp.cng $thget(temp.points) }
  thset temp.rank $getrank($nick,$thget(temp.cng))
  setvar $nick Score $calc($getvar($nick, Score) + $thget(temp.cng))
  thset $eval(Score. $+ $nick,1) $calc($thget($eval(Score. $+ $nick,1)) + $thget(temp.cng))
  if (($getset(build,instabuild)) && ($getset(build,auto)) && ($getset(build,instabuild) // $getset(Var,Wins))) { htmlbuild }
}
alias -l answered {
  tscid
  thset Time $question.time
  if (($1 == $null) || ($trivia.banned) || ($trivia.negationcheck) || (($team) && (!$isteam($nick)))) { return }
  trivia.processscore $1-
  if ($team) {
    thset Score $+ $isteam($nick) $calc($thget( Score $+ $isteam($nick)) + 1)
    tsay $msg.team.score
  }
  else { tsay $iif(!$getset(status, tradwin),$msg.answer.correct($thget(WPM),$thget(temp.rank)),$msg.answer.correct2($thget(WPM),$thget(temp.rank))) }
  if (%uprank) { tsay $msg.trivia.uprank($nick,$calc($thget(temp.rank) - %uprank)) }
  if ((%promotion) && ($getset(trivia,ranks))) { tsay $msg.ranks.promotion(%promotion) }
  if (!$isdis(19)) {
    if (%uprank) award uprank %uprank
    if (%promotion) award promotion %promotion
    award score $getvar($nick, Score)
    award row $getset(Var, Row)
    award time $thget(Time)
    award wpm $thget(WPM)
  }
  if ($thget(RRS)) { tsay $msg.trivia.roundscores }
  hdel Trivia $+ $iden Unanswered
  if (($thget(temp.type) != T) || ($total.over)) { trivx $chan $true }
}
alias -l trivq.answer { return $iif(((($thget(temp.type) == T) || ($getset(status,showmatched))) && ($thget(temp.matched))), $thget(temp.matched),$tok(2)) }
;########################################################
;# QUESTION Typing.                                     #
;########################################################
alias -l trivia.sayquestion {
  if ($regex($tok(1), /^(\d+):\s(.+)$/)) {
    thset temp.points $regml(1)
    var %tq $msg.question.points($regml(2))
  }
  elseif (($tok(1) == Scramble) || ($tok(1) == UWord)) { var %tq $msg.question.scramble($1-) }
  elseif (Multi: * iswm $tok(1)) {
    var %tq $msg.question.multi($1-)
    thset temp.type M
  }
  elseif (Total: * iswm $tok(1)) { 
    var %tq $msg.question.total($1-)
    thset temp.type T
    total.init
  }
  else { var %tq $msg.question.standard($1-) }
  thset trivq.say $e2($thget(Current) $+ .) %tq
  tsay $thget(trivq.say)
}
;########################################################
;# TOTAL question type, control.                        #
;########################################################
alias total.win { return @total $+ $iden }
alias total.init {
  var %i = 2
  if ($window($total.win)) { window -c $total.win }
  window -h $total.win
  while (%i <= $tokq) {
    aline -n $total.win $tok(%i)
    inc %i
  }
}
alias total.is { return $fline($total.win,$1-,1) }
alias total.rem { dline $total.win $total.is($1-) }
alias total.over { return $iif($line($total.win,0) == 0, 1) }
alias gettotalremain {
  var %i = 1, %totalremain
  while (%i <= $line($total.win,0)) { var %totalremain = %totalremain $line($total.win,%i), %i = $calc(%i + 1) }
  return %totalremain
}
;########################################################
;# Categories.                                          #
;########################################################
alias -l numcat {
  if ($window(@categories)) { window -c @categories }
  window -eh @categories
  var %j = 1
  while ($qfile(%j)) {
    if ($exists($qfile(%j))) filter -fw $qfile(%j) @categories #*
    inc %j
  }
  .timer 1 0 window -c @categories
  return $line(@categories,0)
}
;########################################################
;# Trivia BLOCKS.                                       #
;########################################################
alias -l trivia.negationcheck {
  if ($thuser(Hinted)) {
    inform $msg.trivia.hintpaused
    return $true
  }
  if (($thuser(Guess)) && ($thget(guess))) {
    inform $msg.trivia.guessed
    return $true
  }  
}
;########################################################
;# Guess processing.                                    #
;########################################################
alias -l processguess {
  if ($trivia.paused) { return }
  var %i 2, %max = $iif($thget(temp.type) == M, 2, $tokq)
  while (%i <= %max) {
    var %pattern = /((^|\s)( $+ $lower($fix($tok(%i))) $+ )($|\s))/
    if ($getset(status, nomid)) { %pattern = /(( $+ $lower($fix($tok(%i))) $+ )$|^( $+ $lower($fix($tok(%i))) $+ ))/ }
    if ($regex($lower($fix($1-)), %pattern)) {
      thset temp.matched $tok(%i)
      if ($thget(temp.type) == T) { 
        if (!$total.is($tok(%i))) { return }
        total.rem $tok(%i)
      }
      answered $tok(%i)
      if ($thget(temp.type) != T) { return }
    }
    inc %i
  }
  if (!$thuser(Guess)) { thset $eval(Temp.Guess. $+ $nick,1) $1- }
}
alias -l fix {
  var %temp.fix = $1-
  if ($isdis(17)) { return %temp.fix }
  if (the * iswm $1-) { %temp.fix = $right($1-,-3) }
  if (a * iswm $1-) { %temp.fix = $right($1-,-1) }
  var %temp.fix = $remove(%temp.fix,',-,!,`,.,’,´,?,%,$chr(36),$chr(44))
  var %temp.fix = $replace(%temp.fix,kn,n,y,i,k,c,x,c,q,c,e,a,u,o,ph,f,m,n,ll,l,aa,a,oo,o,cc,c,z,s)
  if ((*s iswm %temp.fix) || (*ah iswm %temp.fix)) { var %temp.fix = $left(%temp.fix, -1) }
  return %temp.fix
}
;########################################################
;# PAUSE/RESUME processing.                             #
;########################################################
alias trivia.pause {
  if ($1) {
    .timerq $+ $iden -r
    .timerend $+ $iden -r
    .timerhint $+ $iden -r
    thset paused 0
    tsay $msg.trivia.resume
  }
  else {
    .timerq $+ $iden -p
    .timerend $+ $iden -p
    .timerhint $+ $iden -p
    thset paused 1
    tsay $msg.trivia.pause
  }
}
;########################################################
;# Hint setup.                                          #
;########################################################
alias -l give.hint {
  set -u0 %ident $1
  if ((!$hget(Trivia $+ $iden)) || ($max.hinted >= $triv(numhint))) { return }
  if (!$nick) {
    thset Temp.Hints $calc($thget(Temp.Hints) + 1)
    tsay $msg.hint.hint($calc($triv(perchint) * $thget(Temp.Hints)))
  }
  else {
    thuset Hint $calc($thuser(hint) + 1)
    $iif($getset(status,msghint), tsay, inform) $msg.hint.hint($calc($triv(perchint) * $thuser(hint)))
  }
}
alias -l get.hint {
  if (($thget(temp.type) == T) || ($thget(Temp.type) == M)) { return }
  if (($thget(temp.rhint. $+ $2)) && ($1 == hint)) { return $thget(temp.rhint. $+ $2) }
  var %hint, %in = $replace($trivq.answer, $chr(32), $chr(160)),%perhint = $iif($2,$2,$triv(perchint)), %break = $int($calc(($len(%in) / 100) * %perhint + 1)), %hintc
  if ($1 == space) { return $replace($iif($regsub(%in, /([[:alnum:]])/g, $iif($chr($triv(ch)),$chr($triv(ch)),_), %hintc), %hintc), $chr(160), $chr(32)) }
  if ($1 == last) { return $right($trivq.answer,1) }
  if ($1 == vowels) { return $iif($regsub($trivq.answer, /([^aeiouAEIOU\s])/g, $iif($chr($triv(ch)),$chr($triv(ch)),_), %hintc), %hintc, $trivq.answer) }
  if ($getset(status, scatter)) { %hint = $replace($scatter(%perhint, $trivq.answer),@,$iif($chr($triv(ch)),$chr($triv(ch)),_)) }
  else { %hint = $replace($left(%in, %break) $+ $iif(($regsub($right(%in, $calc(-1 * %break)), /([[:alnum:]])/g, $iif($chr($triv(ch)),$chr($triv(ch)),_), %hintc)) && ($getset(status,cross) == 1), %hintc), $chr(160), $chr(32)) }
  if ($1 == hint) { thset temp.rhint. $+ $2 %hint }
  return %hint
}
alias -l scramble {
  tokenize 32 $1-
  var %i = 1, %temp.smbl
  while (%i <= $0) {
    var %word = $eval($+($,%i),2)
    while (%word) { var %rand = $rand(1, $len(%word)), %temp.smbl = %temp.smbl $+ $mid(%word, %rand, 1), %word = $left(%word, $calc(%rand - 1)) $+ $right(%word, $calc(-1 * %rand)) }
    %temp.smbl = %temp.smbl $+ ;
    inc %i
  }
  return $lower($replace(%temp.smbl,;,$chr(32)))
}
alias scatter {
  var %rnum = $int($calc(($regex($2-,/([[:alnum:]])/g) / 100) * (100 - $1))), %hintc = $2-, %i = 1,%k
  while (%i <= %rnum) {
    while ($mid(%hintc,%k,1) !isalnum) { %k = $rand(1,$len(%hintc)) }
    %hintc = $left(%hintc,$calc(%k - 1)) $+ @ $+ $right(%hintc,$calc(-1 * %k))
    inc %i
  }
  return %hintc
}
alias plot {
  var %hintc
  var %rnum = $int($calc(($regsub($2-,/[[:alnum:]]/g,@,%hintc) / 100) * $1))
  var %i = 1
  while (%i <= %rnum) {
    var %m = $regex($2-, /\S*(@)\S*/g)
    var %k = $regml($calc(((%i - 1) % %m) + 1)).pos
    while ($mid(%hintc,%k,1) != @) { inc %k }
    %hintc = $left(%hintc,$calc(%k - 1)) $+ $mid($2-,%k,1) $+ $right(%hintc,$calc(-1 * %k))
    inc %i
  }
  return %hintc
}
;########################################################
;# CHAMP aliases.                                       #
;########################################################
alias -l trivia.newchamp {
  .rename $scoresfil $asctime(yymmddhhmmss) $+ .bak
  setset Champ $calc($setini(Champ, 0) + 1) $nick
  tsay $msg.trivia.victory($nick)
  trivia.flush
  haltdef
}
;########################################################
;# HALL Of FAME, RANKING.                               #
;########################################################
alias sort {
  window -h $twin
  var %alias = better $+ $1
  filter -fwca $scoresfil $twin %alias *
}
alias -l hof { return $gettok($line($twin,$1),$2,59) }
alias -l msg.trivia.ten {
  sort $1
  var %temp.by = $gttok($1), %temp.ten = $e1($hof(1,1)) $e2(has the best $1 of) $e1($hof(1,%temp.by)) $+ $e2(;)
  var %i = 2
  while (%i <= 10) {
    var %temp.ten = %temp.ten $e2($iif($hof(%i,1),$hof(%i,1) - $hof(%i,%temp.by) $+ ;))
    inc %i
  }
  return %temp.ten
}
alias -l twin { return @trivia $+ $scoresfil }
alias -l getrank {
  sort score
  var %rank = $fline($twin,$+($1,;,*),1), %score = $hof(%rank,2)
  while (%score == $hof(%rank,2)) { dec %rank }
  inc %rank
  unset %uprank
  if (!$2) { return %rank }
  set -u0 %uprank 1
  var %upscore = $calc(%score + $2)
  while ((%upscore >= $hof($calc(%rank - %uprank),2)) && (%rank >= %uprank)) { inc %uprank }
  dec %uprank
  return %rank
}
alias getmrank {
  if (!$getset(trivia, ranks)) { return }
  var %score = $getvar($1,score), %i = $setini(ranks,0), %te = 0, %temax = 0
  while (%i >= 1) {
    %te = $setini(ranks,%i)
    if ((%score >= %te) && (%te >= %temax)) { %temax = %te }
    dec %i
  }
  if (%score == %temax) { set -u0 %promotion $getset(ranks,%temax) }
  return $getset(ranks,%temax)
}
alias -l recordstat {
  sort $1
  return $hof(1,1)
}
alias bettername { return $betterlow(1, $1, $2) }
alias betterscore { return $better(2, $1, $2) }
alias bettertime { return $betterlow(3, $1, $2) }
alias betterstreak { return $better(4, $1, $2) }
alias betterwpm { return $better(5, $1, $2) }
alias betterlow { return $iif($gettok($2, $1, 59) > $gettok($3, $1, 59),1,-1) }
alias better { return $iif($gettok($2, $1, 59) < $gettok($3, $1, 59),1,-1) }
;########################################################
;# AWARD setups.                                        #
;########################################################
alias -l msg.trivia.award { return %c2 $+ $replace($1,^, %c2 $+ $2 $+ %c2o,*, %c2 $+ $e1($getmrank($nick) $nick) $+ %c2o) $+ $c2o }
alias -l award {
  var %i = 1, %award = $1, %trigger = $2
  while ($aw(%i)) {
    tokenize 32 $aw(%i)
    if ($calc($findtok($award.on.tok, %award, 1, $asc(.)) - 1) == $1) {
      if ($istok(Join;Uprank;Promotion, %award, $asc(;))) { award.do $3 %trigger $6- }
      if (($2 == 1) && (%trigger == $4)) { award.act $3 %trigger $6- }
      if (($2 == 2) && (%trigger isnum $4 - $5)) { award.act $3 %trigger $6- }
      if (($2 == 3) && (%trigger >= $4)) { award.act $3 %trigger $6- }
      if (($2 == 4) && (%trigger <= $4)) { award.act $3 %trigger $6- }
      if (($2 == 6) && ($rand(1,$4) <= $5)) { award.act $3 %trigger $6- }
    }
    inc %i
  }
}
alias award.act {
  if ($1 == 1) { describe $chan $msg.trivia.award($3-,$2) }
  if ($1 == 2) { msg $chan $msg.trivia.award($3-,$2) }
  if ($1 == 3) { notice $chan $msg.trivia.award($3-,$2) }
  if ($1 == 4) { trivia.credit $nick $3 }
  if ($1 == 5) { tban $nick | msg $chan $msg.trivia.award($3-,$2) }
  if ($1 == 6) { $3- }
}
alias award.do {

}
alias award.on.tok { return Null.Score.Row.Time.WPM.Join.Question.Uprank.Promotion }
alias award.val.tok { return Null.Exactly.Between.At Least.At Most.Ranked.Random }
alias award.do.tok { return Null.Describe.Msg.Notice.Give Points.Ban.Special }
;########################################################
;# MESSAGING.                                           #
;########################################################
alias -l inform { if (($1) && ($server)) { $iif($nick == $me, .timer -m 1 $calc($timer(0) * 100)) $iif($getset(status,informc) == 1, msg $iden, $iif($nick != $me, .notice $nick, echo $chan)) $rdc($1-) } }
alias -l tsay { if (($1) && ($server)) { $iif($nick == $me, .timer -m 1 $calc($timer(0) * 100)) msg $iden $rdc($1-) } }
;########################################################
;# Direct basic processing, for special functions.      #
;########################################################
alias -l do.ping {
  ctcp $nick ping
  set -u120 % [ $+ ping. [ $+ [ $nick ] ] ] $ticks
}
alias -l trivia.report {
  inform $msg.trivia.thanks
  write " $+ $triv(dir) $+ / $+ $iif($1 == $pre $+ add, $triv(additions), $triv(report)) $+ " $nick $adate $time $2-
}
alias -l processcommand.stats {
  if ($1 isnum 1 - $hof.size) {
    sort score
    inform $msg.trivia.stats($hof($1,1))
  }
  else { inform $msg.trivia.stats($iif($1,$1,$nick)) }
}
;########################################################
;# FRIENDS/BANNED.                                      #
;########################################################
alias -l istrivia.friend {
  var %i = 1
  while ($getset(friend, %i)) {
    if ($getset(friend, %i) iswm $address($nick,5)) { return $true }
    inc %i
  }
}
alias is.friend {
  var %i = 1
  while ($getset(friend, %i)) {
    if ($getset(friend, %i) iswm $address($1,5)) { return $true }
    inc %i
  }
}
alias -l trivia.banned {
  var %i = 1
  while ($getset(banned,%i)) {
    if ($getset(banned,%i) == $iif($1,$1,$nick)) { 
      if (!$1) { inform $msg.trivia.banned }
      return %i
    }
    inc %i
  }
}
alias -l ban.size { return $calc(1 + $setini(banned, 0)) }
alias -l tban { if (!$trivia.banned($$1)) { setset banned $ban.size $1 } }
alias -l tunban {
  var %i = $trivia.banned($$1)
  while ($getset(banned, $calc(%i + 1))) {
    setset banned %i $getset(banned, $calc(%i + 1))
    inc %i
  }
  setset banned %i
}
;########################################################
;# CONVERTORS #
;########################################################
alias convertscores {
  var %ini = $iif($1,$1,triviascores.ini)
  if (!$exists(%ini)) { return }
  var %i = $ini(%ini,0)
  echo 4 -a Converting %i scores into Trivia 3.12+ format.
  while (%i > 0) {
    var %m = $ini(%ini,%i)
    write $iif($2,$2,$scoresfil) $+(%m,;,$readini(%ini,n,%m,score),;,$readini(%ini,n,%m,time),;,$readini(%ini,n,%m,streak),;,$readini(%ini,n,%m,wpm),;,$readini(%ini,n,%m,lastwin))
    dec %i
  }
  .rename %ini %ini $+ .bak
}
;########################################################
;# VAR MANIPULATIONS.                                   #
;########################################################
alias -l setvar {
  if (!$1) { return }
  if ($3- != $null) {
    var %isbackburner = $read($tempfil, w, $1 $+ ;*)
    if (%isbackburner) { copyentry $tempfil $scoresfil $1 }
    var %newline = $getvar($1)
    if (!%newline) { %newline = $1 $+ ;0;9999;0;0; $+ $date }
    %newline = $puttok(%newline,$3-,$gttok($2),59)
    write $iif($readn,-l $+ $readn) $scoresfil %newline
  }
}
alias getvar {
  var %scoreline = $read($scoresfil, w, $1 $+ ;*)
  if (!%scoreline) { return }
  if (!$2) { return %scoreline }
  return $gettok(%scoreline, $gttok($2), 59)
}
alias gttok { return $findtok(name.score.time.streak.wpm.lastwin, $1, 1, $asc(.)) }
alias ittok { return $gettok(name.score.time.streak.wpm.lastwin, $1, $asc(.)) }
alias -l varfil { return $iif($2 == $null, $iif($1 == 0, $lines($scoresfil), $gettok($read($scoresfil, $1),1,59)), $gettok($read($scoresfil, $1),$2,59)) }
alias -l setset {
  if ($3- != $null) { writeini -n trivia.ini $1 $2 $3- }
  else { remini -n trivia.ini $$1 $2 }
}
alias -l getset { return $readini(trivia.ini, n, $1, $2) }
alias -l setini { return $iif($2 != $null, $ini(trivia.ini, $1, $2), $ini(trivia.ini, $1)) }
alias -l thuser { return $thget($eval(Temp. $+ $1 $+ . $+ $nick,1)) }
alias -l thuset { thset $eval(Temp. $+ $1 $+ . $+ $nick,1) $2- }
alias -l thset { hadd Trivia $+ $iden $1- }
alias -l thget { return $hget(Trivia $+ $iden, $1) }
;########################################################
;# MISC.                                                #
;########################################################
alias iden { return $iif($chan, $chan, $iif(%ident, %ident, $tchan(1))) }
alias -l deleteplayer { if ($getvar($1)) { write -dl $+ $readn $scoresfil } }
alias -l hof.size { return $line($twin,0) }
alias -l scoresfil { return $ifd($thget(scores),$ifd($tchan($trivchan, 4), TriviaScores.fil)) }
alias -l trivia.on { if (($timer(q $+ $iden)) || ($timer(end $+ $iden))) { return $true } }
alias -l trivia.paused { if (($thget(paused)) && ($hget(Trivia $+ $iden))) { return $true } }
alias -l question.on { if ($timer(end $+ $iden)) { return $true } }
alias -l tokq { return $numtok($thget(Trivq), $asc($triv(delimiter))) }
alias -l tok { return $gettok($thget(Trivq), $1,$asc($triv(delimiter))) }
alias -l question.time { return $calc(($ticks - $thget(Start)) / 1000) }
alias -l te { return $getset(team, $1 $+ $prop) }
alias -l teamscore { return $thget(Score $+ $1) }
alias -l max.hinted { return $iif($calc($thget(Temp.Hints) + 0) > $calc($thuser(Hint) + 0), $thget(Temp.Hints), $thuser(hint)) }
alias -l isteam { return $thget(Team. $+ $1) }
alias -l chkadate { return $iif($getset(status,adate), $+($gettok($1,2,$asc(/)),/,$gettok($1,1,$asc(/)),/,$gettok($1,3,$asc(/))), $1) }
alias -l team { if ($thget(team) == 1) { return $true } }
alias -l tempini { return triviascbb.ini }
alias -l lag { return $iif($thget(lag $+ $1), $thget(lag $+ $1), $getset(lag,$1)) }
alias -l slag { return $getset(lag,$1) }
alias -l tc { return $getset(color, $1 $+ $iif($prop == b, -bold) $+ $iif($prop == u, -underline)) }
alias -l triv { return $getset(trivia, $1) }
alias -l aw { return $getset(award, $1) }
;########################################################
;# QUESTION MISC.                                       #
;########################################################
alias -l qfile {
  if ($gettok($thget(File),$1,$asc(;))) return " $+ $triv(dir) $+ \ $+ $gettok($thget(File),$1,$asc(;)) $+ "
  if ($tchan($ifd($trivchan,1),$calc(4 + $1))) return " $+ $triv(dir) $+ \ $+ $tchan($ifd($trivchan,1),$calc(4 + $1)) $+ "
}
alias -l numl { return $calc($numq - $numcat) }
alias -l numq {
  if ($1 isnum) { return $lines($qfile($1)) }
  var %i = 0, %j = 1
  while ($qfile(%j)) {
    inc %i $lines($qfile(%j))
    inc %j
  }
  return %i
}
alias -l numfile {
  var %i = 0, %j = 1, %k = $numq, %l
  while (%i <= %k) {
    %l = %i
    inc %i $numq(%j)
    if ($1 isnum %l - %i) { return $qfile(%j) $+ ; $+ $calc(%l + $1) }
    if (($1 !isnum) && ($read($qfile(%j), wn, $+(*,$1-,*), 1))) return $qfile(%j) $+ ; $+ $readn
    inc %j
  }
}
alias -l qread {
  var %nf = $numfile($1)
  return $read($gettok(%nf,1,$asc(;)),$gettok(%nf,2,$asc(;)))
}
alias -l qcat { 
  var %nf = $numfile($1)
  return $read($gettok(%nf,1,$asc(;)), wn, #*, $gettok(%nf,2,$asc(;)))
}
;########################################################
;# MESSAGE COLOR CODE SETTING ALIASES.                  #
;########################################################
alias -l e1 { return %c1 $+ $1- $+ %c1o }
alias -l e2 { return %c2 $+ $iif($isalias(trivtran),$trivtran($1-),$1) $+ %c2o }
;########################################################
;# MESSAGES.                                            #
;########################################################
alias -l msg.ping.reply { return $e1($nick) $+ $e2($chr(44) your ping is) $e1($calc(($ticks - % [ $+ ping. [ $+ [ $nick ] ] ] ) / 1000)) $e2(secs.) }
alias -l msg.answer.correct { return $e2(Winner:) $e1($getmrank($nick) $nick) $e2(Answer:) $e1($trivq.answer) $e2(Time:) $e1($thget(Time)) $e2(Streak:) $e1($getset(Var, Row)) $e2(Points:) $e1($getvar($nick,score)) $e2(WPM:) $e1($int($1)) $e2(Rank:) $e1($ord($2)) }
alias -l msg.answer.correct2 { return $e1($getmrank($nick) $nick) $e2(got the answer:) $e1($trivq.answer) $e2(in) $e1($thget(Time)) $e2(seconds.) $e2(Points:) $e1($getvar($nick,score)) $e2(Rank:) $e1($ord($2))  }
alias -l msg.answer.timeout { return $e2(Time's up! The answer was:) $e1($trivq.answer) }
alias -l msg.answer.timeout.total { return $e2(Time's up! Remaining answers were:) $e1($gettotalremain) }
alias -l msg.answer.timeout2 { return $e2(Time's up! Nobody got the answer!) }
alias -l msg.question.multi { return $e2(Multiple Choice:) $e1($right($tok(1),-7)) $+ $e2(; $get.multianswers) }
alias -l msg.question.total { return $e2(Give all Correct responces:) $e1($right($tok(1),-7)) }
alias -l msg.question.points { return $e2(For) $e1($thget(temp.points)) $e2(point $+ $iif($thget(temp.points) != 1,s) $+ :) $e1($get.question($1-)) }
alias -l msg.question.scramble { return $iif($getset(status, sayscramble),$e2(Unscramble the following:),$iif($1-,$e2($1 $+ :)))) $e1($scramble($tok(2)) $+ ?) }
alias -l msg.question.standard { return $e2($iif($1-, $1- $+ :)) $e1($get.question($tok(1))) }
alias -l msg.question.answer { return $e2(The answer to the last question was $+ :) $e1($thget(answer)) }
alias -l msg.trivia.stats { return $iif($getvar($1,score), $e1($getmrank($1) $1) $+ $e2(: Rank:) $e1($ord($getrank($1))) $e2(out of) $e1($hof.size) $+ $e2(. Current wins:) $e1($getvar($1,score)) $+ $e2(. Best streak:) $e1($getvar($1,streak)) $+ $e2(. Best time:) $e1($getvar($1,time)) $e2( secs. WPM:) $e1($getvar($1,wpm)) $iif($getvar($1,lastwin), $e2(Last Win:) $e1($chkadate($getvar($1, lastwin)))), $e2(No such user exists.)) }
alias -l msg.trivia.state { return $msg.trivia.version $e2(is currently) $e1($trivon) $+ $e2(.) $iif($getset(status,champ),$e2(Champ Mode Set to) $e1($triv(reset)) $e2(Wins.)) $e2(Question file contains) $e1($numq) $e2(lines. Trivia is:) $e1($trivia.onoff) $+ $e2(.) $iif($trivia.on, $e2(Max Questions:) $e1($thget(Max)) $e2(Team Game:) $e1($team.onoff) $+ $e2(. Trivia Round started by) $e1($thget(SUser)) $e2(on) $e1($thget(STime))) $e2(Bot time is:) $e1($time) }
alias -l msg.trivia.enabled { return $e2(Enabling the trivia. Have an op type:) $e1($pre $+ disable) $e2(to disable the bot.) }
alias -l msg.trivia.disabled { return $e2(Disabling the trivia. Have an op type:) $e1($pre $+ enable) $e2(to enable the bot.) }
alias -l msg.trivia.victory { return $e2(The game has been beaten by) $e1($1) $e2(all hail the new champ whose name shall reign supreme!) }
alias -l msg.trivia.unactive { return $e2(The game has been disabled due to inactivity.) }
alias -l msg.trivia.uprank { return $e1($1) $e2(has moved up in rank. Rank:) $e1($ord($2)) }
alias -l msg.trivia.pause { return $e2(Trivia paused.) $e1($pre $+ resume) $e2(to resume.) }
alias -l msg.trivia.resume { return $e2(Trivia resumed.) }
alias -l msg.trivia.started { return $e2(Starting the trivia. Round of) $e1($thget(Max)) $e2(questions.) $e1($pre $+ strivia) $e2(to stop. Total:) $e1($numl) }
alias -l msg.trivia.stopped { return $e2(Stopping the trivia.) $e1($pre $+ trivia <number>) $e2(to restart.) }
alias -l msg.trivia.awarded { return $e1($1) $e2(was awarded) $e1($2) $e2(point $+ $iif($2 > 1,s) $+ . Current Wins:) $e1($getvar($1,score)) }
alias -l msg.trivia.deducted { return $e1($1) $e2(was deducted) $e1($calc($2 * -1)) $e2(point $+ $iif($2 < -1,s) $+ . Current Wins:) $e1($getvar($1,score)) }
alias -l msg.trivia.hof { return $msg.trivia.champ(1) $msg.trivia.ten(score) }
alias -l msg.trivia.error.midq { return $e2(Cannot pause while trivia game has a question issued.) }
alias -l msg.trivia.banned { return $e1(You cannot play $+ $chr(44) you are banned.) }
alias -l msg.trivia.guessed { return $e2(You already had a guess ") $+ $e1($thuser(Guess)) $+ $e2(" was incorrect.) }
alias -l msg.trivia.thanks { return $e2(Thank you for your contribution!) }
alias -l msg.trivia.version { return $e1(Tat's Trivia Bot $+ $chr(44) v $+ $trivia.version) }
alias -l msg.trivia.web { return $e2(Get your own copy of) $msg.trivia.version $e2(at) $e1(http://web.dreamsoft.com/tat/trivia.htm) $e2(.) }
alias -l msg.trivia.onjoin { return $e2(Welcome) $e1($getmrank($nick) $nick) $+ $e2($chr(44)) $e1($msg.trivia.version) $e2(is activated. Type ') $+ $e1($pre $+ help) $+ $e2(' for a list of commands or just ') $+ $e1($pre $+ trivia) $+ $e2(' to start a game!) }
alias -l msg.trivia.records { return $e2(Record streak:) $e1($recordstat(streak)) $e2(of) $e1($hof(1,4)) $+ $e2(.) $e2(Record time:) $e1($recordstat(time)) $e2(of) $e1($hof(1,3)) $+ $e2(.) $e2(Record wpm:) $e1($recordstat(WPM)) $e2(of) $e1($hof(1,5)) $+ $e2(.) }
alias -l msg.trivia.themes { return $e2(Current themes are:) $e1($get.themes) }
alias -l msg.trivia.champ { return $iif($getset(status,champ), $e2(Current champ:) $e1($getset(Champ, $ini(trivia.ini, Champ, 0))) $+ $e2(. $get.champ($1))) }
alias -l msg.trivia.showteams { return $msg.trivia.showteam(1) $msg.trivia.showteam(2) $iif($getset(team, 4-team), $msg.trivia.showteam(3) $msg.trivia.showteam(4)) }
alias -l msg.trivia.showteam { return $iif($get.showteams($1), $e2(Current members of) $e1($te($1)) $e2(are:) $e1($get.showteams($1))) }
alias -l msg.trivia.hintpaused { return $e2(You requested a $pre $+ hint less than) $e1($triv(hintpause)) $e2(seconds ago.) }
alias -l msg.trivia.roundscores { return $e2(Current Round:) $e1($get.roundscores) }
alias -l msg.trivia.banlist { return $e1(The following people are banned:) $e1($get.banlist) }
alias -l msg.team.start { return $e2(Team Trivia: ') $+ $e1($pre $+ join 1) $+ $e2(' or ') $+ $e1($pre $+ join 2) $+ $iif($getset(team,4-team),$e2(' or ') $+ $e1($pre $+ join 3) $+ $e2(' or ') $+ $e1($pre $+ join 4)) $+ $e2(' to add to a team.) }
alias -l msg.team.add { return $e2(Team:) $e1($1) $e2(has a new member:) $e1($2) }
alias -l msg.team.joinover { return $e2(I am sorry no more people can join/change at this time.) }
alias -l msg.team.toomany { return $e2(That team currently has enough players.) }
alias -l msg.team.joinbefore { return $e2(Teams are no longer accepting player.) }
alias -l msg.team.alreadyon { return $e2(You are already on that team.) }
alias -l msg.team.score { return $e1($getmrank($nick) $nick) $e2(won. Point for) $e1($te($isteam($nick))) $+ $e2(.) $msg.team.cscore(1,2) $iif($getset(team,4-team), $msg.team.cscore(3,4)) }
alias -l msg.team.cscore { return $e1($te($1)) $e2(has) $e1($thget(Score $+ $1)) $e2(points.) $e1($te($2)) $e2(has) $e1($thget(Score $+ $2)) $e2(points.) }
alias -l msg.team.over { return %c2 $+ $replace($1-, *t1, %c2o $+ $e1($te(1)) $+ %c2,*t2, %c2o $+ $e1($te(2)) $+ %c2,*t3,%c2o $+ $e1($te(3)) $+ %c2,*t4,%c2o $+ $e1($te(4)) $+ %c2) $+ %c2o $+ $e2(!) }
alias -l msg.ranks.promotion { return $e1($nick) $+ $e2($chr(44) congratulations on your promotion to:) $e1($1) }
alias -l msg.hint.words { return $e2(There are) $e1($numtok($trivq.answer,32)) $e2(words in the answer.) }
alias -l msg.hint.vowels { return $e2(Vowels are:) $e1($$get.hint(vowels)) }
alias -l msg.hint.last { return $e2(The last character in the answer is:) $e1($$get.hint(last)) }
alias -l msg.hint.answerspace { return $e2(Answer:) $e1($get.hint(space)) }
alias -l msg.hint.hint { return $e2(Here's your $ord($ifd($thuser(hint),$thget(Temp.Hints))) hint:) $e1($$get.hint(hint,$1)) }
alias -l msg.hint.hint2 { return $e2(Here's a hint:) $e1($$get.hint(hint,$1)) }
alias -l msg.features.built { return $e2(Trivia scores updated:) $e1($1) $e2(!) }
;########################################################
;# MESSAGE PROCESSES.                                   #
;########################################################
alias -l get.question {
  if ($right($1,1) == -) { return $left($1-,-1) }
  return $1- $+ $iif(((!$isdis(30)) && ($right($1,1) != ?)),?)
}
alias -l get.banlist {
  var %i = 1, %b.temp
  while ($getset(banned,%i)) {
    var %b.temp = %b.temp $getset(banned,%i)
    inc %i
  }
  return %b.temp
}
alias -l get.roundscores {
  if ($window(@round $+ $iden)) { window -c @round $+ $iden }
  window -hn @round $+ $iden
  .timer 1 0 window -c @round $+ $iden
  var %i = 1
  while ($hmatch(Trivia $+ $iden, Score.*, %i)) {
    var %j = $line(@round $+ $iden,0)
    while (( $hget(Trivia $+ $iden, $hmatch(Trivia $+ $iden, Score.*, %i)) > $thget(Score. $+ $line(@round $+ $iden, %j))) && (%j >= 1)) { dec %j }
    iline @round $+ $iden $calc(%j + 1) $remove($hmatch(Trivia $+ $iden, Score.*, %i),Score.)
    inc %i
  }
  var %roundscores
  %i = 1
  while (%i <= 15) {
    %roundscores = %roundscores $iif($line(@round $+ $iden,%i),$line(@round $+ $iden,%i) $+ - $+ $thget(Score. $+ $line(@round $+ $iden,%i)))
    inc %i
  }
  return %roundscores
}
alias sortroundscores {
  var %j = 1
  while (%j <= $line(@round $+ $iden,0)) {
    var %k = %j
    while (%k <= $line(@round $+ $iden,0)) {
      if ($thget(Score. $+ $line(@round $+ $iden, %j)) > $thget(Score. $+ $line(@round $+ $iden, %k))) {
        var %temp.name = $line(@round $+ $iden, %j)
        rline @round $+ $iden %j $line(@round $+ $iden, %k)
        rline @round $+ $iden %j %temp.name
      }
      inc %k
    }
    inc %j
  }
}
alias -l get.showteams {
  var %i = 1
  while ($hmatch(Trivia $+ $iden, Team.*, %i)) {
    if ($isteam($remove($hmatch(Trivia $+ $iden, Team.*, %i),Team.)) == $1) { var %temp.team = %temp.team $remove($hmatch(Trivia $+ $iden, Team.*, %i),Team.) }
    inc %i
  }
  return %temp.team
}
alias -l get.champ {
  if (($setini(Champ,0) <= 0) || (!$getset(status,champ))) { return }
  var %temp.champ, %i = $calc($ini(trivia.ini, Champ, 0) - 1)
  while ((%i >= 1) && (!$1)) {
    var %temp.champ = %temp.champ $getset(Champ, %i)
    dec %i
  }
  return %temp.champ
}
alias -l get.multianswers {
  var %i 2, %answers.t
  if ($window(@multianswer)) { window -c @multianswer }
  window -h @multianswer
  .timer 1 0 window -c @multianswer
  while ($tok(%i)) {
    aline @multianswer $tok(%i)
    inc %i
  }
  filter -wwct 1 13 @multianswer @multianswer *
  var %i 1
  while ($line(@multianswer, %i)) { var %answers.t = %answers.t $line(@multianswer, %i), %i = $calc(%i + 1) }
  return %answers.t
}
alias -l get.themes {
  var %i = 1
  while ($getset(triviamode $+ %i, name)) {
    var %temp.themes = %temp.themes $getset(triviamode $+ %i, name)
    inc %i
  }
  return $e1(%temp.themes)
}
;########################################################
;# HTML BUILD                                           #
;########################################################
alias htmlbuild {
  var %start.ticks = $ticks, %htmlfile = $ifd($getset(build,html),triv.htm)
  sort score
  if ($exists(%htmlfile)) { .remove %htmlfile }
  write %htmlfile <HTML><head><title> $+ $iden Trivia Scores $+ </title></head>
  write %htmlfile <body bgcolor="#000000" text="#339933" link="#33FF00" alink="#666600" vlink="#666666">
  write %htmlfile The Scores File was Compiled By: $strip($msg.trivia.version) <br>
  write %htmlfile The Creation Date of the Scores file is: $time $adate <br><ol>
  write %htmlfile <table BORDER COLS=5 WIDTH="100%" >
  write %htmlfile <tr>
  write %htmlfile <TR>
  write %htmlfile <TH>Ranking</TH><TH>Name</TH><TH>Score</TH><TH>Best Time</TH><TH>Best Streak</TH><TH>Best WPM</TH>
  write %htmlfile </TR>
  var %i = 1, %j = $hof.size
  if ($getset(build,top) isnum 1 - %j) { %j = $getset(build,top) }
  while (%i <= %j) {
    write %htmlfile <tr><TH> $+ %i $+ </TH> <td> $+ $hof(%i,1) $+ </td> <td> $+ $hof(%i,2) $+ </td> <td> $+ $hof(%i,3) $+ </td> <td> $+ $hof(%i,4) $+ </td> <td> $+ $hof(%i,5) $+ </td></tr>
    inc %i
  }
  write %htmlfile </table><br>
  write %htmlfile Made with <a href="http://web.dreamsoft.com/tat/trivia.htm" "target="_top"> $+ $strip($msg.trivia.version) $+ </A><br>
  echo -a $e2(Finished:) $e1(%htmlfile) $e2(is written. In) $e1($calc(($ticks - %start.ticks) / 1000)) $+ $e2(secs.)
  if ($getset(build,web)) { tsay $msg.features.built($getset(build,web)) }
  if (($getset(build,auto)) && ($exists($+(",$triv(dir),\,ftpbatch.txt,")))) { run -n ftp $+(-s:,$triv(dir),\,ftpbatch.txt) }
}
;########################################################
;# SPECIAL COMMANDS. #
;########################################################
alias find { echo $get.find($1-) }
alias add { if ($exists($qfile(1))) write $qfile(1) $1- }
alias ask {
  var %asknm = 1
  while ($thget(Ask $+ %asknm)) { inc %asknm }
  if ($hget(Trivia $+ $iden)) { thset Ask $+ %asknm $iif($1-,$1-,$$?="Force which question number(#) or ask what question(Question*Answer)?") }
}
alias sortfile { 
  var %file = " $+ $sfile($mircdir) $+ "
  filter -ffct 1 13 %file %file *
}
alias killdup { 
  var %file = " $+ $sfile($mircdir) $+ ", %i = 0
  window -hn @temp.window
  while ($lines(%file) >= %i) {
    var %line = $read(%file,%i)
    if (%line) { aline -n @temp.window %line }
    unset %line
    inc %i
  }
  filter -wfc @temp.window %file *
  window -c @temp.window
}
alias tpurge {
  var %i = 1
  sort score
  while ($hof(%i,1)) {
    if ($hof(%i,2) <= $$1) { copyentry $$scoresfil $$tempfil $hof(%i,1) }
    inc %i
  }
}
alias tdpurge {
  var %i = 1
  sort score
  while ($hof(%i,1)) {
    if ($round($calc(($ctime($date) - $ctime($hof(%i,6)))/86400),0) > $$1) { copyentry $$scoresfil $$tempfil $hof(%i,1) }
    inc %i
  }
}
alias copyentry {
  write $2 $$read($1, w, $3 $+ ;*)
  write -dl $+ $$readn $1
}
alias tempfil { return backburner.txt }
alias tmerge {
  if (($$getvar($$1,score)) && ($$getvar($$2,score))) {
    setvar $2 score $calc($getvar($2,score) + $getvar($1,score))
    if ($getvar($1, wpm) > $getvar($2,wpm)) { setvar $2 wpm $getvar($1, wpm) }
    if ($getvar($1, streak) > $getvar($2,streak)) { setvar $2 streak $getvar($1, streak) }
    if ($getvar($1, time) < $getvar($2,time)) { setvar $2 time $getvar($1, time) }
    deleteplayer $1
  }
  tsay $msg.trivia.stats($2)
}
alias trename {
  setvar $1 name $2
  tsay $msg.trivia.stats($2)
}
alias triviad {
  if (($1 >= 1) && ($2)) { .timertriviaad 0 $calc($$1 * 60) timer.ad $active $2- }
  else { .timertriviaad off } 
}
alias triviad2 { 
  if (($1 >= 1) && ($2)) { .timertriviaad 0 $calc($$1 * 60) msg $active $e1($2-) } 
  else { .timertriviaad off } 
}
alias timer.ad { if (!$trivia.on) { msg $1 $e1($2-) } }
;########################################################
;# DIALOGS.                                             #
;########################################################
dialog trivset {
  title "Trivia Settings"
  size -1 -1 452 324
  option pixels
  tab General, 1, 0 0 452 327
  box Channels, 9, 8 28 266 80, tab 1
  text Delimiter, 10, 18 255 60 13, tab 1
  text Add/Report, 11, 18 233 60 13, tab 1
  button Add, 24, 20 124 52 16, tab 1
  text Directory, 13, 18 211 60 13, tab 1
  edit , 30, 80 81 186 22, tab 1 multi autohs
  edit $triv(delimiter), 31, 84 255 30 22, tab 1 multi autohs
  edit $triv(additions), 32, 84 229 86 22, tab 1 multi autohs
  edit $triv(report), 33, 172 229 86 22, tab 1 multi autohs
  edit $triv(dir), 35, 84 203 174 22, tab 1 multi autohs
  text Percent Hint, 14, 284 64 68 13, tab 1
  edit $triv(perchint), 99, 392 64 36 20, tab 1
  text Number of hints, 15, 284 46 80 13, tab 1
  edit $triv(numhint), 61, 392 42 36 20, tab 1
  text Hint Reduction, 16, 284 260 80 13, tab 1
  edit $triv(DPH), 63, 396 256 36 20, tab 1
  text Points per answer, 17, 284 238 88 13, tab 1
  edit $triv(PPQ), 65, 396 234 36 20, tab 1
  list 108, 78 40 188 40, tab 1 size
  button Add, 115, 22 48 50 16, tab 1
  button Remove, 119, 22 64 50 16, tab 1
  text Channel:, 125, 20 84 50 16, tab 1
  edit , 132, 80 164 186 21, tab 1
  box "Points", 133, 276 220 168 64, tab 1
  box "Global", 134, 8 192 264 92, tab 1
  button "Scores File", 141, 16 164 60 20, tab 1
  button "Define", 20, 124 256 47 17, tab 1
  check "Trivia Ranks", 148, 176 256 88 20, tab 1
  check Crosshatch, 47, 284 84 80 20, tab 1
  text Chr, 21, 384 88 19 13, tab 1
  edit , 961, 404 88 24 18, tab 1
  box "Hints", 80, 276 28 168 192, tab 1
  radio "Scatter", 58, 332 140 56 20, tab 1
  radio "Plot", 129, 388 140 44 20, hide tab 1
  radio "Basic", 130, 284 140 48 20, tab 1
  text "This is an example of a hint", 199, 284 124 154 16, tab 1
  check "Say Hint Number", 147, 284 100 100 20, hide tab 1
  radio "Standard", 149, 280 180 68 20, hide tab 1
  radio "Last", 150, 356 180 44 20, hide tab 1
  radio "Vowels", 151, 280 196 60 20, hide tab 1
  radio "Random", 152, 356 196 68 20, hide tab 1
  text "First Hint Type", 153, 284 164 74 16, hide tab 1
  button "Remove", 12, 20 140 52 16, tab 1
  list 34, 80 120 186 36, tab 1 sort size
  box "Questions", 83, 8 108 266 84, tab 1
  tab Options, 6
  text questions, 18, 52 188 52 13, tab 6
  check No-activity off, 88, 16 148 100 20, tab 6
  edit $triv(naoff), 89, 16 168 30 20, tab 6
  text seconds, 19, 166 188 44 13, tab 6
  check Hint-Pause, 96, 124 148 100 20, tab 6
  edit $triv(hintpause), 97, 122 168 30 20, tab 6
  check Echo Answer, 40, 16 48 100 20, tab 6
  check Auto-Hint, 41, 340 48 100 20, tab 6
  check Champ Mode, 42, 232 72 100 20, tab 6
  check Timeout Answer, 45, 340 72 100 20, tab 6
  check Join Message, 46, 124 48 100 20, tab 6
  check Traditional win, 48, 16 96 100 20, tab 6
  check Auto-Start, 49, 232 48 100 20, tab 6
  check Msg Reponces, 50, 124 72 100 20, tab 6
  check Say Scramble:, 53, 124 96 100 20, tab 6
  check Msg Hints, 54, 232 96 100 20, tab 6
  check Showteam End, 55, 340 96 100 20, tab 6
  check Answer Space, 56, 16 120 100 20, tab 6
  check No Mid-Match, 57, 124 120 100 20, tab 6
  check Show Matched, 59, 340 120 100 20, tab 6
  check Use Adate, 60, 16 72 100 20, tab 6
  check No ? end, 830, 340 168 88 20, tab 6
  check No Spell Correct, 817, 340 144 100 20, tab 6
  check "No bonus", 126, 340 192 100 20, hide tab 6
  check Limit Guesses, 51, 232 148 88 20, tab 6
  edit "1", 144, 264 168 44 20, disable read tab 6
  check Round HoF, 52, 232 120 88 20, tab 6
  box Settings, 70, 4 24 440 204, tab 6
  edit , 22, 4 236 432 57, tab 6 read multi autovs
  tab Defaults, 2
  box , 23, 4 43 250 64, tab 2
  box , 25, 254 43 130 64, tab 2
  check Colors, 116, 8 32 76 16, tab 2 push
  text Primary, 110, 14 58 60 13, tab 2
  text Secondary, 120, 14 78 60 13, tab 2
  edit $tc(1), 121, 76 58 30 20, tab 2 read
  edit $tc(2), 122, 76 78 30 20, tab 2 read
  edit $tc(3), 123, 259 58 30 20, tab 2 read
  edit $tc(4), 124, 259 78 30 20, tab 2 read
  check B, 117, 201 58 20 20, tab 2 push
  check U, 118, 224 58 20 20, tab 2 push
  check B, 127, 201 78 20 20, tab 2 push
  check U, 128, 224 78 20 20, tab 2 push
  combo 111, 112 60 80 240, tab 2 size drop
  combo 112, 112 80 80 240, tab 2 size drop
  combo 113, 296 60 80 240, tab 2 size drop
  combo 114, 296 80 80 240, tab 2 size drop
  box Time, 26, 4 108 196 192, tab 2
  text Before Start, 27, 14 126 120 13, tab 2
  text Between Questions (answered), 36, 14 228 120 29, tab 2
  text Given to Answer, 37, 14 150 120 13, tab 2
  text Before Auto-Hint, 38, 14 200 120 13, tab 2
  text (timed-out), 39, 14 258 120 17, tab 2
  text Before hint allowed, 62, 14 174 120 13, tab 2
  edit $slag(start), 135, 140 126 50 20, tab 2
  edit $slag(answered), 145, 140 236 50 20, tab 2
  edit $slag(timedout), 155, 140 148 50 20, tab 2
  edit $slag(hint), 165, 140 196 50 20, tab 2
  edit $slag(timed), 175, 140 258 50 20, tab 2
  edit $slag(hintallow), 185, 140 170 50 20, tab 2
  box Questions, 64, 202 108 150 152, tab 2
  text Default Round, 68, 276 118 70 13, tab 2
  text Champ Goal, 69, 212 200 62 13, tab 2
  text Team Round, 71, 276 158 70 13, tab 2
  edit $triv(default), 205, 276 134 63 20, tab 2
  edit $triv(reset), 215, 276 200 63 20, tab 2
  edit $triv(dteam), 217, 276 174 63 20, tab 2
  button $record.type($triv(Record)), 218, 210 230 133 20, tab 2
  button Themes, 700, 266 268 68 20, tab 2
  radio Unlimited, 201, 208 176 68 20, tab 2
  radio Team, 202, 208 152 52 20, tab 2
  radio Normal, 203, 208 128 60 20, tab 2
  check Disable, 816, 208 268 40 20, tab 2 push
  box , 8, 202 256 150 36, tab 2
  check "Background", 158, 256 32 76 16, tab 2 push
  check "Announce Next", 136, 16 276 116 20, hide tab 2
  tab Teams, 3
  box Names, 72, 8 72 400 72, tab 3
  text Team 1, 73, 16 88 42 20, tab 3
  text Team 2, 74, 16 112 42 20, tab 3
  text Team 3, 308, 208 88 42 20, disable tab 3
  text Team 4, 309, 208 112 42 20, disable tab 3
  box Victories, 75, 8 144 412 144, tab 3
  text Tied Message, 76, 16 168 66 13, tab 3
  text Team 1 Wins, 77, 16 192 66 13, tab 3
  text Team 2 Wins, 78, 16 216 66 13, tab 3
  text Team 3 Wins, 303, 16 240 66 16, disable tab 3
  text Team 4 Wins, 304, 16 264 66 16, disable tab 3
  edit $te(1), 380, 56 88 148 20, tab 3 multi autohs
  edit $te(2), 381, 56 112 148 20, tab 3 multi autohs
  edit $te(4), 382, 248 112 148 20, disable tab 3 multi autohs
  edit $te(3), 383, 248 88 148 20, disable tab 3 multi autohs
  edit $te(0).victory, 320, 80 168 320 20, tab 3 multi autohs
  edit $te(1).victory, 321, 80 192 320 20, tab 3 multi autohs
  edit $te(2).victory, 322, 80 216 320 20, tab 3 multi autohs
  edit $te(3).victory, 323, 80 240 320 20, disable tab 3 multi autohs
  edit $te(4).victory, 324, 80 264 320 20, disable tab 3 multi autohs
  check Limit Join Period, 330, 272 32 88 20, tab 3 push
  edit $te(JoinBefore), 335, 272 51 88 20, tab 3
  radio 2 Teams, 28, 44 40 76 20, tab 3
  radio 4 Teams, 29, 140 40 76 20, tab 3
  tab Awards, 4
  box Awards, 79, 10 48 380 152, tab 4
  button Delete, 411, 396 80 48 20, tab 4
  button Add, 412, 396 56 48 20, tab 4
  list 420, 15 64 368 130, tab 4 sort size
  text "* is winner's nick.", 81, 210 257 92 13, tab 4
  text "^ is value of trigger", 82, 312 257 104 13, tab 4
  check Disable, 819, 16 28 76 17, tab 4 push
  combo 137, 68 212 68 100, tab 4 size drop
  edit "", 139, 264 212 68 21, tab 4
  text "Award", 140, 8 272 42 16, tab 4
  edit "", 142, 64 272 364 21, tab 4 multi autohs
  text "Trigger on", 154, 8 212 54 16, tab 4
  combo 159, 184 212 68 100, tab 4 size drop
  text "and", 160, 336 216 22 16, hide tab 4
  edit "", 161, 364 212 68 21, hide tab 4
  text "points", 162, 296 236 34 16, tab 4
  text "Do Action", 163, 8 252 50 16, tab 4
  text "values", 164, 140 212 38 16, tab 4
  combo 166, 64 248 140 100, tab 4 size drop
  tab Status, 5
  text Trivia Script version:, 84, 20 40 150 20, tab 5
  text $strip($msg.trivia.version), 85, 180 40 150 20, tab 5
  text Trivia bot is currently:, 86, 20 62 150 20, tab 5
  text $trivon, 504, 180 62 80 20, tab 5
  text Current mIRC version is:, 87, 20 84 150 20, tab 5
  text $version, 90, 180 84 80 20, tab 5
  text Current Trivia directory exists:, 91, 20 106 150 20, tab 5
  text $trivia.dir, 92, 180 106 80 20, tab 5
  text Currently in Trivia Channel:, 93, 20 128 150 20, tab 5
  text $trivia.chan, 94, 180 128 80 20, tab 5
  text Question file in Directory:, 95, 20 150 150 20, tab 5
  text $trivia.file, 98, 180 150 80 20, tab 5
  text Number of questions:, 103, 20 172 150 20, tab 5
  text $numl, 104, 180 172 78 20, tab 5
  button Delete Scores, 515, 304 100 80 20, tab 5
  button Scores, 519, 304 68 80 20, tab 5
  list 601, 22 202 248 42, tab 5 sort size
  button Unban, 602, 274 224 80 20, tab 5
  button Ban, 603, 274 202 80 20, tab 5
  list 610, 22 248 248 42, tab 5 sort size
  button Add Friend, 611, 274 250 80 20, tab 5
  button Remove, 612, 274 272 80 20, tab 5
  tab Commands, 7
  box Limit On/Off Control, 105, 4 228 164 76, tab 7
  check On, 43, 20 244 48 20, tab 7 push
  combo 66, 76 244 80 76, tab 7 size drop
  check Off, 44, 20 268 48 20, tab 7 push
  combo 67, 76 268 80 76, tab 7 size drop
  check $pre $+ trivia team, 811, 12 92 100 20, tab 7
  check $pre $+ trivia unlimited, 812, 12 68 100 20, tab 7
  check $pre $+ trivia $chr(35), 813, 12 44 100 20, tab 7
  check $pre $+ trivia team $chr(35), 814, 12 116 100 20, tab 7
  check $pre $+ pause/resume, 831, 12 140 100 20, tab 7
  check $pre $+ hof, 807, 120 44 100 20, tab 7
  check $pre $+ hoffast, 809, 120 68 100 20, tab 7
  check $pre $+ hofstreak, 808, 120 92 100 20, tab 7
  check $pre $+ hofwpm, 810, 120 116 100 20, tab 7
  check $pre $+ records, 815, 120 140 100 20, tab 7
  check $pre $+ next, 802, 228 44 100 20, tab 7
  check $pre $+ answer, 820, 228 68 100 20, tab 7
  check $pre $+ ping, 806, 228 92 100 20, tab 7
  check $pre $+ themes, 805, 228 116 100 20, tab 7
  check $pre $+ add/report, 818, 228 140 100 20, tab 7
  check $pre $+ hint, 801, 336 44 100 20, tab 7
  check $pre $+ last, 822, 336 92 100 20, tab 7
  check $pre $+ words, 821, 336 116 100 20, tab 7
  check $pre $+ repeat, 803, 336 140 100 20, tab 7
  check $pre $+ op ban, 825, 228 172 100 20, tab 7
  check $pre $+ vowels, 823, 336 68 100 20, tab 7
  check $pre $+ op, 824, 12 172 100 20, tab 7
  check $pre $+ op find, 829, 120 172 100 20, tab 7
  check $pre $+ op unban, 826, 12 196 100 20, tab 7
  check $pre $+ op ask, 827, 120 196 100 20, tab 7
  check $pre $+ op add, 828, 336 172 100 20, tab 7
  check $pre $+ dis/enable, 804, 228 196 100 20, tab 7
  box Disable, 106, 4 24 441 204, tab 7
  text Command Prefix, 107, 180 240 82 16, tab 7
  edit %command-prefix, 850, 264 236 36 21, tab 7
  text blank = default, 109, 180 256 78 16, tab 7
  button "Build HTML Options", 157, 328 240 107 21, tab 7
  button "Disable", 890, 340 200 95 21, hide tab 7
  button Cancel, 101, 358 298 40 20, cancel
  button OK, 100, 405 298 40 20, ok
  button Apply, 102, 308 298 40 20
  link "Visit Homepage", 518, 220 300 76 16
}
;########################################################
;# DIALOG EVENTS.                                       #
;########################################################
on *:dialog:trivset:init:*:{
  var %i = 1
  while ($getset(chan, %i)) {
    did -a $dname 108 $gettok($getset(chan, %i), 1, 59)
    inc %i
  }
  var %i = $numtok($status.toks, $asc(.))
  while (%i >= 1) {
    if ($getset(status, $gettok($status.toks, %i, $asc(.))) == 1) { did -c $dname $calc(39 + %i) }
    dec %i
  }
  if (!$did(58).state) { did -c $dname 130 }
  if ($getset(trivia,ranks) == 1) { did -c $dname 148 }
  if ($getset(status,naoff) == 1) { did -c $dname 88 }
  if ($getset(status,hintpause) == 1) { did -c $dname 96 }
  if ($getset(status,autostart) == 1) { did -c $dname 49 }
  if ($getset(color,on) == 1) { did -c $dname 116 }
  if ($getset(color,bon) == 1) { did -c $dname 158 }
  if ($getset(color,1-bold) == 1) { did -c $dname 117 }
  if ($getset(color,1-underline) == 1) { did -c $dname 118 }
  if ($getset(color,2-bold) == 1) { did -c $dname 127 }
  if ($getset(color,2-underline) == 1) { did -c $dname 128 }
  if ($getset(trivia,odefault) == Unlimited) { did -c $dname 201 }
  elseif ($getset(trivia,odefault) == Team) { did -c $dname 202 }
  else { did -c $dname 203 }
  if ($getset(team,Joinbeforeon) == 1) { did -c $dname 330 }
  if ($getset(team,4-team) == 1) {
    trivset.teams 1
    did -c $dname 29
  }
  else { did -c $dname 28 }
  var %i = 0
  while (%i < 16) {
    did -a $dname 111,112,113,114 $colorcode(%i)
    inc %i
  }
  did -a $dname 66,67 User
  did -a $dname 66,67 Voice
  did -a $dname 66,67 Half-Op
  did -a $dname 66,67 Op/Friend
  did -a $dname 66,67 Nobody
  did -c $dname 66 $calc($getset(trivia,onlevel) + 1)
  did -c $dname 67 $calc($getset(trivia,offlevel) + 1)
  did -c $dname 111 $calc($did(121) + 1)
  did -c $dname 112 $calc($did(122) + 1)
  did -c $dname 113 $calc($did(123) + 1)
  did -c $dname 114 $calc($did(124) + 1)
  awards.load
  var %i = 1
  while ($setini(banned,%i)) {
    did -a $dname 601 $getset(banned,%i)
    inc %i
  }
  did -a $dname 961 $iif($chr($triv(ch)),$chr($triv(ch)),_)
  disable.load
  trivia.load.friends
  check.toggle.multichan
  check.toggle.ranks
  check.color.toggle
  check.awards.toggle
}
on *:dialog:trivset:sclick:100,102:{
  setset trivia delimiter $did(31)
  setset trivia additions $did(32)
  setset trivia report $did(33)
  setset trivia dir $did(35)
  var %i = $numtok($status.toks, $asc(.))
  while (%i >= 1) {
    setset status $gettok($status.toks, %i, $asc(.)) $did($calc(39 + %i)).state
    dec %i
  }
  setset trivia onlevel $calc($did(66).sel - 1)
  setset trivia offlevel $calc($did(67).sel - 1)
  setset status naoff $did(88).state
  setset trivia naoff $did(89)
  setset status hintpause $did(96).state
  setset trivia hintpause $did(97)
  setset trivia perchint $did(99)
  setset trivia numhint $did(61)
  setset trivia DPH $did(63)
  setset trivia PPQ $did(65)
  setset trivia ranks $did(148).state
  setset color on $did(116).state
  setset color bon $did(158).state
  setset color 1-bold $did(117).state
  setset color 1-underline $did(118).state
  setset color 2-bold $did(127).state
  setset color 2-underline $did(128).state
  setset team JoinBeforeon $did(330).state
  setset team Joinbefore $did(335)
  setset color 1 $int($did(121))
  setset color 2 $int($did(122))
  setset color 3 $int($did(123))
  setset color 4 $int($did(124))
  varcolors
  var %i = 1
  while (%i <= 6) {
    setset lag $gettok(start.answered.timedout.hint.timed.hintallow, %i, $asc(.)) $int($did($calc(125 + (%i * 10))))
    inc %i
  }
  setset trivia default $int($did(205))
  setset trivia odefault
  if ($did(201).state == 1) { setset trivia odefault Unlimited }
  if ($did(202).state == 1) { setset trivia odefault Team }
  setset trivia reset $int($did(215))
  setset trivia dteam $int($did(217))
  setset award
  var %i = 1
  while (%i <= $did(420).lines) {
    setset award %i $did(420,%i)
    inc %i
  }
  setset team 1 $did(380)
  setset team 2 $did(381)
  setset team 3 $did(382)
  setset team 4 $did(383)
  setset team 0victory $did(320)
  setset team 1victory $did(321)
  setset team 2victory $did(322)
  setset team 3victory $did(323)
  setset team 4victory $did(324)
  setset team 4-team $did(29).state
  var %i = 1
  setset trivia ch $asc($right($did(961),1))
  %command-prefix = $left($did(850),1)
  disable.save
}
on *:dialog:trivset:sclick:12:{
  if ((!$did(34).sel) || (!$did(108).sel)) { return }
  var %todel = $did(34).sel
  did -d $dname 34 %todel
  did -c $dname 34 %todel
  save.qs
}
on *:dialog:trivset:sclick:24:{
  var %temp.file = $$sfile($iif($isdir($did(35)),$did(35),$mircdir))
  did -a $dname 34 $nopath(%temp.file)
  did -ra $dname 35 $nofile(%temp.file)
  save.qs
}
on *:dialog:trivset:edit:30:{
  var %temp.num = $did(108).sel
  tchan.set $did(108).sel 1 $did(30)
  did -o $dname 108 $did(108).sel $did(30)
  did -c $dname 108 %temp.num
}
on *:dialog:trivset:sclick:108:{ multichan.load }
on *:dialog:trivset:sclick:115:{ 
  var %toadd = $$?="Add what channel?"
  did -a $dname 108 %toadd
  chan.add %toadd
}
on *:dialog:trivset:sclick:119:{
  var %todel = $did(108).sel
  chan.del %todel
  did -d $dname 108 %todel
  did -c $dname 108 %todel
  did -r $dname 30,34,132
  multichan.load
}
on *:dialog:trivset:edit:132:{ tchan.set $$did(108).sel 4 $$did(132) }
on *:dialog:trivset:sclick:158,116:{ check.color.toggle }
on *:dialog:trivset:sclick:141:{
  did -ra $dname 132 $nopath($$sfile($mircdir $+ *.fil,Choose a scores file.))
  tchan.set $$did(108).sel 4 $did(132)
}
on *:dialog:trivset:sclick:148:{ check.toggle.ranks }
;########################################################
;# MOUSE EVENTS.                                        #
;########################################################
on *:dialog:trivset:mouse:40,41,42,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,88,96,817,830:{ 
  if (%didt == $did) { return }
  if ($did == 40) { exp Echo's the answer so that you can see it after the question is read. }
  if ($did == 60) { exp Uses the American dating style for the $pre $+ stats responce. MM/DD/YY rather than DD/MM/YY. }
  if ($did == 48) { exp Traditional win provides more less clinical information about the correct answer. }
  if ($did == 56) { exp Provides the spacing of the answer directly after the question is read. }
  if ($did == 46) { exp Gives a message to each person who joins the trivia channel, providing information about the bot. }
  if ($did == 50) { exp Rather than providing hidden notice message this makes all message responces to go directly to the channel. }
  if ($did == 53) { exp For scramble questions, this forces the standard scramble category to read Unscramble the Following. }
  if ($did == 57) { exp Rather than accept answers anywhere in a responce, this feature forces the bot to ignore answered contained entirely inside a responce. }
  if ($did == 49) { exp This feature makes the bot start up as soon as you rejoin the trivia channel. }
  if ($did == 42) { exp This allows for champ mode, when a specific score is reached the game resets the score and logs the winner. }
  if ($did == 54) { exp Much like Msg $pre $+ responces this feature only forces hint responces to be displayed in channel. }
  if ($did == 58) { exp Rather than start the hint from left to right it displays random letters in the hint. }
  if ($did == 41) { exp This feature automaticly displays a hint to the channel after a time specified in Defaults. }
  if ($did == 45) { exp This allows people to be told the correct answer after nobody in the room answered correctly. }
  if ($did == 55) { exp When a team game is ends this provides a list of players on each team. }
  if ($did == 59) { exp By default the bot displays the first answer in the answer file as correct. But, with this enabled the matched answer is displayed. }
  if ($did == 88) { exp After a specified number of questions, the bot will turn itself off. }
  if ($did == 96) { exp After a hint is requested this feature blocks the correct answer from being accepted from that person for a given amount of time. }
  if ($did == 47) { exp This allows for unfinished part of a hint to use a specific character to indicate where letters are missing. }
  if ($did == 51) { exp This option limits the number of guesses to the specific value. }
  if ($did == 52) { exp This option makes a round hall of fame displayed along with the win messages throughout a trivia round. }
  if ($did == 817) { exp Turns off the spell correction and only allows exact answers to be accepted. }
  if ($did == 830) { exp Turns off the automatic ? at the end of each question. A - at the end of the question also does this. }
  set -u5 %didt $did 
}
alias exp { did -ra $dname 22 $$1- }
;########################################################
;# Stray.                                               #
;########################################################
on *:dialog:trivset:sclick:20:{ if (!$dialog(trivrank)) dialog -m trivrank trivrank } 
on *:dialog:trivset:sclick:28,29:{
  trivset.teams $iif($did != 28,1)
}
on *:dialog:trivset:sclick:111,112,113,114:{ did -ra $dname $calc($did + 10) $calc($did($did).sel - 1) }
on *:dialog:trivset:sclick:218:{
  var %record = $calc($triv(Record) + 1)
  if (%record == 9) { var %record = 1 }
  did -ra $dname $did $record.type(%record)
  setset Trivia Record %record
}
;########################################################
;# Awards.                                              #
;########################################################
on *:dialog:trivset:sclick:412:{ did -a $dname 420 0 0 0 0 0 Award }
on *:dialog:trivset:sclick:411:{ did -d $dname 420 $$did(420,1).sel | check.awards.toggle }
alias check.awards.toggle { did $iif($did(420).sel,-e,-b) $dname 137,159,166,139,142,161,140,154,160,162,163,164,81,82 }
on *:dialog:trivset:sclick:420:{
  check.awards.toggle
  tokenize 32 $$did(420).seltext
  did -c $dname 137 $calc($1 + 1)
  did -c $dname 159 $calc($2 + 1)
  did -c $dname 166 $calc($3 + 1)
  did -ra $dname 139 $4
  did -ra $dname 161 $5
  did -ra $dname 142 $6-
  check.award.range
}
alias check.award.range {
  did $iif($did(159).seltext == Between,-v,-h) $dname 160,161
}
on *:dialog:trivset:sclick:137,159,166:{ award.modified }
on *:dialog:trivset:edit:139,142,161:{ award.modified }
alias award.modified {
  if (!$did(420).sel) { return }
  var %t.line = $did(420).sel
  did -o $dname 420 $did(420).sel $calc($did(137).sel - 1) $calc($did(159).sel - 1) $calc($did(166).sel - 1) $did(139) $did(161) $did(142)
  did -c $dname 420 %t.line
  check.award.range
}
;########################################################
;# Settings.                                            #
;########################################################
on *:dialog:trivset:sclick:515:{ if ($?!="Are you sure you wish to delete all scores?") { rename $scoresfil $asctime(yymmddhhmmss) $+ .bak } }
on *:dialog:trivset:sclick:518:{ run http://web.dreamsoft.com/tat/trivia.htm }
on *:dialog:trivset:sclick:519:{ dialog -m triviascores triviascores }
on *:dialog:trivset:sclick:602:{ 
  tunban $did(601,1).sel
  did -d $dname 601 $$did(601,1).sel
}
on *:dialog:trivset:sclick:603:{ 
  var %ban = $$?="Ban whom?"
  tban %ban
  did -a $dname 601 %ban
}
on *:dialog:trivset:sclick:611:{
  var %friend.add = $$?"In the format nick!ident@host specify friend to add, note wildcards are permitted."
  did -a $dname 610 %friend.add
  triviafriend.add %friend.add
}
on *:dialog:trivset:sclick:612:{
  triviafriend.del $$did(610).sel
  trivia.load.friends
}
on *:dialog:trivset:sclick:700:{ if (!$dialog(triviatheme)) { dialog -m triviatheme triviatheme } }
on *:dialog:trivset:sclick:157:{ if (!$dialog(trivbuild)) { dialog -m trivbuild trivbuild } }
;########################################################
;# TRIVIA SETUP, alias expanded.                        #
;########################################################
alias save.qs {
  var %i = 1
  tchan.noqs $$did(108).sel
  while (%i <= $did(34).lines) {
    tchan.set $did(108).sel $calc(4 + %i) $did(34,%i)
    inc %i
  }
}
alias status.toks { return echo.autohint.champ.oponlyon.oponlyoff.showanswer.onjoin.cross.tradwin.autostart.informc.oneguess.rrs.sayscramble.msghint.noshowt.answers.nomid.scatter.showmatched.adate }
alias chan.add { tchan.set $calc($setini(chan,0) + 1) 1 $1- }
alias chan.del {
  var %i = $$1, %j = $setini(chan,0)
  while (%i < %j) {
    setset chan %i $getset(chan,$calc(%i + 1))
    inc %i
  }
  setset chan %j
}
alias check.toggle.multichan { did $iif($did(108).sel,-e,-b) $dname 12,24,30,34,132,141 }
alias multichan.load {
  if (!$did(108).sel) { return }
  did -r $dname 34
  did -ra $dname 30 $tchan($did($did).sel)
  did -ra $dname 132 $tchan($did($did).sel,4)
  var %i = 5
  while ($tchan($did(108).sel, %i)) {
    did -a $dname 34 $tchan($did(108).sel,%i)
    inc %i
  }
  check.toggle.multichan
}
alias check.toggle.ranks { did $iif($did(148).state,-e,-b) $dname 20 }
alias awards.load {
  var %i = 1
  did -r $dname 420
  while ($aw(%i)) {
    did -a $dname 420 $aw(%i)
    inc %i
  }
  did -r $dname 137,159,166
  %i = 1
  while ($gettok($award.on.tok, %i, $asc(.))) {
    did -a $dname 137 $gettok($award.on.tok, %i, $asc(.))
    inc %i
  }
  %i = 1
  while ($gettok($award.val.tok, %i, $asc(.))) {
    did -a $dname 159 $gettok($award.val.tok, %i, $asc(.))
    inc %i
  } 
  %i = 1
  while ($gettok($award.do.tok, %i, $asc(.))) {
    did -a $dname 166 $gettok($award.do.tok, %i, $asc(.))
    inc %i
  }
}
alias disable.save {
  var %i = 801
  while (%i <= 831) {
    var %t = %t $+ $did(%i).state
    inc %i
  }
  setset status disables %t
}
alias disable.load {
  var %i = 1
  while (%i <= 31) {
    if ($isdis(%i)) { did -c $dname $calc(%i + 800) }
    inc %i
  }
}
alias -l record.type { return $gettok(hof.streak.time.wpm.champ.web.roundscores.records, $ifd($1, 8), $asc(.)) }
alias -l trivset.teams { did $iif($1, -e, -b) $dname 308,309,303,304,382,383,323,324 }
alias isdis { if ($mid($getset(status, disables), $1, 1) == 1) { return $true } }
alias check.color.toggle {
  did $iif($did(116).state,-e,-b) $dname 23,25,120,110,121,122,123,124,117,118,127,128,111,112,113,114
  if (!$did(158).state) did -b $dname 25,123,124,113,114
}
alias triviafriend.del {
  var %i = $$1, %j = $setini(friend,0)
  while (%i < %j) {
    setset friend %i $getset(friend,$calc(%i + 1))
    inc %i
  }
  setset friend %j
}
alias triviafriend.add {
  var %i = 1
  while ($getset(friend, %i)) { inc %i }
  setset friend %i $1- 
}
alias triviafriend.clear { setset friend }
alias trivia.load.friends {
  did -r $dname 610
  var %i = 1
  while ($getset(friend, %i)) {
    did -a $dname 610 $getset(friend, %i)
    inc %i
  }
}
;########################################################
;# TRIVIA RANKS DIALOG.                                 #
;########################################################
dialog trivrank {
  title "Trivia Ranks"
  size -1 -1 138 88
  option dbu
  list 1, 2 4 110 58, size
  text "Rank Name", 11, 4 66 31 8
  edit "", 2, 46 64 66 10, multi autohs
  text "Points Required", 10, 4 76 39 8
  edit "", 3, 46 76 36 10, multi autohs read
  button "Add", 4, 114 8 21 8
  button "Del", 5, 114 20 21 8
  button "Ok", 999, 114 78 17 8, ok
}
;########################################################
;# DIALOG EVENTS.                                       #
;########################################################
on *:dialog:trivrank:init:*:{
  var %i = $setini(ranks,0), %j = 1
  while (%j <= %i) {
    did -a $dname 1 $setini(ranks,%j) : $getset(ranks, $setini(ranks,%j)) 
    inc %j
  }
}
on *:dialog:trivrank:sclick:1:{
  did -ra $dname 3 $setini(ranks, $did(1).sel)
  did -ra $dname 2 $getset(ranks, $setini(ranks, $did(1).sel))
}
on *:dialog:trivrank:edit:2:{
  if (!$did(1).sel) return
  setset ranks $$did(3) $$did(2)
  var %p = $did(1).sel
  did -o $dname 1 %p $did(3) : $did(2)
  did -c $dname 1 %p
}
on *:dialog:trivrank:sclick:4:{
  var %r = $$?="What is the minimum amount points for this rank?"
  if ((%r !isnum) || ($getset(ranks,%r))) return
  var %n = $$?="What is this rank called?"
  setset ranks %r %n
  did -a $dname 1 %r : %n
}
on *:dialog:trivrank:sclick:5:{
  var %p = $$did(1).sel
  setset ranks $$setini(ranks, %p)
  did -d $dname 1 %p
  did -r $dname 2,3
}
;########################################################
;# TRIVIA BUILD DIALOG.                                 #
;########################################################
dialog trivbuild {
  title "Build Html"
  size -1 -1 280 104
  option dbu
  check Auto Update, 1, 180 4 50 10
  edit "", 2, 2 12 86 88, multi autovs autohs
  button Ok, 99, 240 92 23 10, ok
  radio Write All Scores, 3, 184 64 50 10
  radio Write Top, 4, 184 76 34 10
  edit 25, 5, 240 72 20 10
  box Scores Out, 57, 180 56 86 31
  text Password, 54, 96 52 25 8
  box Ftp Batch Creator, 55, 92 4 84 96
  text Username, 53, 96 40 25 8
  text Ftp Site, 51, 96 16 25 8
  edit "", 6, 128 16 46 10, multi autohs
  text Port, 52, 96 28 25 8
  edit "", 7, 128 28 46 10, multi autohs
  edit "", 8, 128 40 46 10, multi autohs
  edit "", 9, 128 52 46 10, multi autohs
  button "Generate", 10, 136 88 37 8
  edit "triv.htm", 11, 128 76 46 10, multi autohs
  text Filename, 56, 96 76 23 6
  text Every, 58, 212 44 17 6
  edit "", 13, 228 44 22 10, multi autohs
  text Points, 14, 252 44 17 6
  check Auto-Build, 15, 180 44 28 8, push
  button "Cancel", 12, 212 92 23 10, cancel
  text "Directory", 50, 96 64 25 8
  edit "", 16, 128 64 46 10
  check "Announce Update", 17, 180 16 54 10
  edit "", 18, 192 28 86 10, multi autohs
  text "URL", 20, 180 28 10 7
  text "Batch File", 21, 4 4 29 8
}
;########################################################
;# TRIVIA BUILD EVENTS.                                 #
;########################################################
on *:dialog:trivbuild:sclick:15:{ did $iif($did(15).state,-e,-b) $dname 13 }
on *:dialog:trivbuild:sclick:4:{ did -e $dname 5 }
on *:dialog:trivbuild:sclick:3:{ did -b $dname 5 }
on *:dialog:trivbuild:init:*:{
  if ($getset(build,auto)) { did -c $dname 1 }
  if ($getset(build,web)) {
    did -c $dname 17
    did -rea $dname 18 $getset(build,web)
  }
  if ($getset(build,instabuild)) {
    did -c $dname 15
    did -rea $dname 13 $getset(build,instabuild)
  }
  else { did -b $dname 13 }
  if ($getset(build,top)) {
    did -u $dname 3
    did -c $dname 4
    did -rea $dname 5 $getset(build,top)
  }
  else {
    did -c $dname 3
    did -u $dname 4
    did -rb $dname 5
  }
  if (!$exists($+(",$triv(dir),\,ftpbatch.txt,"))) { return }
  filter -fo $+(",$triv(dir),\,ftpbatch.txt,") $dname 2 *
  var %i = 1
  while ($did(2,%i)) {
    tokenize 32 $did(2,%i)
    if ($1 == open) { var %go = $true }
    elseif ((!$did(6)) && (%go)) {
      did -ra $dname 6 $1
      did -ra $dname 7 $2
    }
    elseif ((!$did(8)) && (%go)) { did -ra $dname 8 $1 }
    elseif ((!$did(9)) && (%go)) { did -ra $dname 9 $1 }
    elseif (($1 == cd) && (%go)) { did -ra $dname 16 $2 }
    elseif (($1 == put) && (%go)) { did -ra $dname 11 $nopath($2-) }
    inc %i
  }
}
on *:dialog:trivbuild:sclick:10:{
  if ((!$did(6)) || (!$did(8)) || (!$did(9)) || (!$did(11))) { return $input(You are missing vital data to generate batch.) }
  did -r $dname 2
  did -i $dname 2 $did(2).lines open
  did -i $dname 2 $did(2).lines $did(6) $did(7)
  did -i $dname 2 $did(2).lines $did(8)
  did -i $dname 2 $did(2).lines $did(9)
  if ($did(16)) { did -i $dname 2 $did(2).lines cd $did(16) }
  did -i $dname 2 $did(2).lines put $shortfn($mircdir $+ $did(11))
  did -i $dname 2 $did(2).lines bye
}
on *:dialog:trivbuild:sclick:99:{ 
  setset build auto $did(1).state
  setset build instabuild $iif($did(15).state, $did(13))
  setset build web $iif($did(17).state, $did(18))
  setset build top $iif((($did(4).state) && ($did(5))), $did(5))
  setset build html $did(11)
  if ($did(2)) { filter -ifc $dname 2 $+(",$triv(dir),\,ftpbatch.txt,") * }
}
;########################################################
;# TRIVIA THEMES DIALOG.                                #
;########################################################
dialog triviatheme {
  title Trivia Themes
  size -1 -1 500 360
  option pixels
  list 1, 26 12 300 116, sort hsbar
  button Add, 2, 346 12 50 20
  button Remove, 3, 346 42 50 20
  text Name:, 30, 26 146 100 20
  text File:, 31, 26 168 100 20
  text #Question: , 32, 26 190 100 20
  text Points per Question:, 33, 26 212 100 20
  text Hint-Point Decrease:, 34, 26 234 100 20
  edit , 11, 134 146 120 20, multi autohs
  edit , 12, 134 168 120 20, multi autohs
  edit , 13, 134 190 120 20, multi autohs
  edit , 14, 134 212 120 20, multi autohs
  edit , 15, 134 234 120 20, multi autohs
  check Team Game, 16, 22 274 100 20, push
  check One Guess, 17, 22 296 100 20, push
  check Roundscores, 18, 22 318 100 20, push
  box Lag, 35, 272 134 228 200
  text Before Start, 26, 282 154 96 20
  text Between Questions (Answered), 37, 282 184 96 28
  text Given to Answer, 38, 282 214 96 20
  text Before Auto-Hint, 39, 282 244 88 20
  text Between Question (Timed Out), 40, 282 274 88 28
  text Before ' $+ $pre $+ hint' allowed, 41, 282 304 104 20
  edit , 19, 404 154 80 20
  edit , 20, 404 184 80 20
  edit , 21, 404 214 80 20
  edit , 22, 404 244 80 20
  edit , 23, 404 274 80 20
  edit , 24, 404 304 80 20
  button OK, 999, 454 338 40 20, ok
}
;########################################################
;# TRIVIA THEMES EVENTS.                                #
;########################################################
on *:dialog:triviatheme:init:*:{
  var %i = 1
  while ($getset(triviamode $+ %i, name)) {
    did -a triviatheme 1 $+($getset(triviamode $+ %i, name),;,$getset(triviamode $+ %i, file),;,$getset(triviamode $+ %i, max),;,$getset(triviamode $+ %i, PPQ),;,$getset(triviamode $+ %i, DPH),;,$getset(triviamode $+ %i, team),;,$getset(triviamode $+ %i, guess),;,$getset(triviamode $+ %i, rrs),;,$getset(triviamode $+ %i, lagstart),;,$getset(triviamode $+ %i, laganswered),;,$getset(triviamode $+ %i, lagtimedout),;,$getset(triviamode $+ %i, laghint),;,$getset(triviamode $+ %i, lagtimed),;,$getset(triviamode $+ %i, laghintallow))
    inc %i
  }
}
on *:dialog:triviatheme:sclick:1:{
  did -ra triviatheme 11 $gettok($did(1).seltext, 1, $asc(;))
  did -ra triviatheme 12 $gettok($did(1).seltext, 2, $asc(;))
  did -ra triviatheme 13 $gettok($did(1).seltext, 3, $asc(;))
  did -ra triviatheme 14 $gettok($did(1).seltext, 4, $asc(;))
  did -ra triviatheme 15 $gettok($did(1).seltext, 5, $asc(;))
  did -u triviatheme 16,17,18
  if ($gettok($did(1).seltext, 6, $asc(;))) { did -c triviatheme 16 }
  if ($gettok($did(1).seltext, 7, $asc(;))) { did -c triviatheme 17 }
  if ($gettok($did(1).seltext, 8, $asc(;))) { did -c triviatheme 18 }
  did -ra triviatheme 19 $ifd($gettok($did(1).seltext, 9, $asc(;)),$slag(start))
  did -ra triviatheme 20 $ifd($gettok($did(1).seltext, 10, $asc(;)),$slag(answered))
  did -ra triviatheme 21 $ifd($gettok($did(1).seltext, 11, $asc(;)),$slag(timedout))
  did -ra triviatheme 22 $ifd($gettok($did(1).seltext, 12, $asc(;)),$slag(hint))
  did -ra triviatheme 23 $ifd($gettok($did(1).seltext, 13, $asc(;)),$slag(timed))
  did -ra triviatheme 24 $ifd($gettok($did(1).seltext, 14, $asc(;)),$slag(hintallow))
}
on *:dialog:triviatheme:sclick:2:{ did -a triviatheme 1 $+(Themename,;,questions.txt,;,10,;,1,;,0,;,0,;,0,;,0,;,$slag(start),;,$slag(answered),;,$slag(timedout),;,$slag(hint),;,$slag(timed),;,$slag(hintallow)) }
on *:dialog:triviatheme:sclick:3:{ did -d triviatheme 1 $did(1).sel }
on *:dialog:triviatheme:edit:11,12,13,14,15,19,20,21,22,23,24:{ triviatheme.update }
on *:dialog:triviatheme:sclick:16,17,18:{ triviatheme.update }
alias triviatheme.update { if ($did(1).sel) { did -oc triviatheme 1 $did(1).sel $+($did(11),;,$did(12),;,$did(13),;,$did(14),;,$did(15),;,$did(16).state,;,$did(17).state,;,$did(18).state,;,$did(19),;,$did(20),;,$did(21),;,$did(22),;,$did(23),;,$did(14)) } }
on *:dialog:triviatheme:sclick:999:{
  setset triviamode
  var %i = 1
  while ($did(1,%i).text) {
    setset triviamode $+ %i name $gettok($did(1, %i).text,1,59)
    setset triviamode $+ %i file $gettok($did(1, %i).text,2,59)
    setset triviamode $+ %i max $gettok($did(1, %i).text,3,59)
    setset triviamode $+ %i ppq $gettok($did(1, %i).text,4,59)
    setset triviamode $+ %i dph $gettok($did(1, %i).text,5,59)
    setset triviamode $+ %i team $gettok($did(1, %i).text,6,59)
    setset triviamode $+ %i guess $gettok($did(1, %i).text,7,59)
    setset triviamode $+ %i rrs $gettok($did(1, %i).text,8,59)
    setset triviamode $+ %i lagstart $gettok($did(1, %i).text,9,59)
    setset triviamode $+ %i laganswered $gettok($did(1, %i).text,10,59)
    setset triviamode $+ %i lagtimedout $gettok($did(1, %i).text,11,59)
    setset triviamode $+ %i laghint $gettok($did(1, %i).text,12,59)
    setset triviamode $+ %i lagtimed $gettok($did(1, %i).text,13,59)
    setset triviamode $+ %i laghintallow $gettok($did(1, %i).text,14,59)
    inc %i
  }
}
;########################################################
;# TRIVIA SCORES DIALOG.                                #
;########################################################
dialog triviascores {
  title Trivia Scores
  size -1 -1 500 300
  list                     1,   5  20 100 200, vsbar
  list                     2, 115  20  75 200, vsbar
  list                     3, 200  20  75 200, vsbar
  list                     4, 285  20  75 200, vsbar
  list                     5, 370  20  75 200, vsbar
  button Delete,        10,   5 225  75  20
  button Reset Score,   11, 115 225  75  20
  button Reset Streak,  12, 200 225  75  20
  button Reset Time,    13, 285 225  75  20
  button Reset WPM,     14, 370 225  75  20
  button Name,          20,   5   5  50  15
  button Score,         21, 115   5  50  15
  button Streak,        22, 200   5  50  15
  button Time,          23, 285   5  50  15
  button WPM,           24, 370   5  50  15
  button Ok,           100, 350 250  45  20,ok
}
;########################################################
;# TRIVIA SCORES EVENTS.                                #
;########################################################
on 1:dialog:triviascores:init:*: { sortscores score }
alias -l sortscores { 
  sort $1
  loaddata.triviascores
}
alias -l loaddata.triviascores {
  did -r $dname 1,2,3,4,5
  var %i = 1
  while ($hof(%i,1)) {
    did -a $dname 1 $hof(%i,1)
    did -a $dname 2 $hof(%i,2)
    did -a $dname 3 $hof(%i,4)
    did -a $dname 4 $hof(%i,3)
    did -a $dname 5 $hof(%i,5)
    inc %i
  }
}
on 1:dialog:triviascores:sclick:1,2,3,4,5:{ did -c $dname 1,2,3,4,5 $did($did).sel }
on 1:dialog:triviascores:sclick:20,21,22,23,24: { sortscores $gettok(name.score.streak.time.wpm, $calc($did - 19), $asc(.)) }
on 1:dialog:triviascores:sclick:10: {
  deleteplayer $did(1).seltext
  if ($did(1).sel) { did -d triviascores 1,2,3,4,5 $did(1).sel }
}
on 1:dialog:triviascores:sclick:11,12,13,14: {
  setvar $did(1).seltext $gettok(score.streak.time.wpm, $calc($did - 10), 46) $iif($did == 13, 9999, 0)
  if ($did(1).sel) { did -o triviascores $calc($did - 9) $did(1).sel 0 }
}