Advertisement
Guest User

Untitled

a guest
Jul 27th, 2010
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
mIRC 145.99 KB | None | 0 0
  1. ;For newer versions or contact info check http://nsfhost.tatarize.com
  2.  
  3. ;I assert no copyright, patent, trademark, or trade secret with regard document/script.
  4. ;Please alter, modify, butcher, edit, republish, or use this script in any way you see fit.
  5. ;With or without this text, in part or in full, without need for permission beforehand.
  6.  
  7. alias trivia.version { return 3.58 }
  8. alias trivia.name { return Tat's Trivia Bot }
  9. alias trivia.web { return http://tatarize.nfshost.com/ }
  10. ;########################################################
  11. ;# Direct IRC interactions.                             #
  12. ;########################################################
  13. on *:START: { trivia.init }
  14. on *:LOAD: {
  15.   var %v = 6.01
  16.   if ($version < %v) {
  17.     echo Please use mIRC %v or later.
  18.     if ($input(Not using mirc %v or later, would you like to use the script anyway?,8,Override?)) { init.load }
  19.     else { unload -rs $script }
  20.   }
  21.   else { init.load }
  22. }
  23. on *:INVITE:*: {
  24.   if ($trivia.turnedoff) { return }
  25.   if ($trivchan) { join $chan }
  26. }
  27. on *:JOIN:*: {
  28.   if ($trivia.turnedoff) { return }
  29.   inc -u5 %trivia.netsplit
  30.   set -u3 %ident $chan
  31.   if ((%trivia.netsplit >= 3) || (!$trivchan) || (!$getset(status,bot))) { return }
  32.   if (($nick != $me) && (!$isdis(31))) { if ($getset(status,onjoin)) { inform $msg.trivia.onjoin } }
  33.   elseif ($getset(status,autostart) == 1) { trivia }
  34.   award join $nick
  35. }
  36. on *:INPUT:#: {
  37.   if ($trivia.turnedoff) { return }
  38.   if ((!$trivchan) || (/* iswm $1-)) { return }
  39.   set -u3 %ident $chan
  40.   if ($pre $+ * iswm $strip($1-)) { processcommand $strip($1-) }
  41.   elseif ($question.on) { processguess $1- }
  42. }
  43. on *:ctcpreply:ping*:{
  44.   if ($trivia.turnedoff) { return }
  45.   if ($isdis(17)) return
  46.   if (($eval(% $+ ping. $+ $nick,2)) && ($2 isnum)) {
  47.     set -u3 %ident $eval(% $+ pingchan. $+ $nick,2)
  48.     scid $eval(% $+ pingcid. $+ $nick,2) inform $msg.ping.reply
  49.     unset % $+ ping. $+ $nick
  50.     unset % $+ pingchan. $+ $nick
  51.     unset % $+ pingcid. $+ $nick
  52.     $eval(set -u $+ $slag(ping) % $+ pingantispam. $+ $nick 1,2)
  53.   }
  54. }
  55. on *:TEXT:*:#:{
  56.   if ($trivia.turnedoff) { return }
  57.   set -u3 %ident $chan
  58.   if (!$trivchan) return
  59.   if ($pre $+ * iswm $strip($1-)) { processcommand $strip($1-) }
  60.   else if (($question.on) && ($left($1,1) != /)) { processguess $1- }
  61. }
  62. on *:TEXT:*:?: {
  63.   if ($trivia.turnedoff) { return }
  64.   set -u3 %ident $chan
  65.   if (($pre $+ $gtok(29) $+ * iswm $strip($1-)) || ($pre $+ $gtok(30) $+ * iswm $strip($1-))) { processcommand $strip($1-) }
  66. }
  67. ;########################################################
  68. ;# Channel setup and related checks.                    #
  69. ;########################################################
  70. alias trivchan {
  71.   var %i = 1
  72.   while ($tchan(%i)) {
  73.     if (($tchan(%i,3) iswm $me) && ($tchan(%i,2) iswm $ifd($network,irc))) {
  74.       if (($tchan(%i) iswm $chan) || ((!$chan) && ($me ison $tchan(%i)))) {
  75.         if ($1) return $tchan(%i)
  76.         return %i
  77.       }
  78.     }
  79.     inc %i
  80.   }
  81. }
  82. alias tchan { return $ifd($gettok($getset(chan,$1), $ifd($2,1), 59),$iif($2 isnum 2-3, *)) }
  83. ;########################################################
  84. ;# Menubar and submenu functions.                       #
  85. ;########################################################
  86. menu channel,menubar {
  87.   Trivia
  88.   .$showon(Trivia Options):{ if (!$dialog(trivset)) { dialog -m trivset trivset } }
  89.   .$showon(Start Trivia)
  90.   ..$showon(Standard):{ $trivia }
  91.   ..$showon(Unlimited Game):{ $trivia(unlimited) }
  92.   ..$showon(Team Game):{ $trivia(team) }
  93.   ..$showon(Theme Game)
  94.   ...$submenu($theme.submenu($1))
  95.   ..$showon(Specify round):{ $trivia($$?="How many question in the trivia round?") }
  96.   .$showon(Stop Trivia):{ strivia }
  97.   .$showon(Set Channel):{ chan.add $$chan }
  98.   .$showon(-)
  99.   .$showon(Features)
  100.   ..$showon(Build Scores HTML):{ htmlbuild }
  101.   ..$showon(Process HTML Commands):{ htmltrigger }
  102.   ..$showon(HTML Options):{  if (!$dialog(trivbuild)) { dialog -m trivbuild trivbuild } }
  103.   ..$showon(Themes Setup): {  if (!$dialog(triviatheme)) { dialog -m triviatheme triviatheme } }
  104.   ..$showon(Ranks Setup): {  if (!$dialog(trivrank)) { dialog -m trivrank trivrank } }
  105. }
  106. alias theme.submenu {
  107.   if (($1 == begin) || ($1 == end)) return -
  108.   if ($getset(triviamode $+ $1, name)) return $getset(triviamode $+ $1, name) $+ : /trivia $getset(triviamode $+ $1, name)
  109. }
  110. menu menubar {
  111.   Trivia
  112.   .$showon(Force Question):{ ask }
  113.   .$showon(Scores)
  114.   ..$showon(Scores):{ if (!$dialog(triviascores)) { dialog -m triviascores triviascores } }
  115.   ..$showon(Give Points): { trivia.credit $$?="Credit whom?" $$?="How many points do you wish to give, -# to remove score" }
  116.   .$showon(Echo)
  117.   ..$showon(Records):{ tsay $msg.trivia.records }
  118.   ..$showon(HoF):{ tsay $msg.trivia.hof }
  119.   ..$showon(Repeat):{ tsay $msg.question.current }
  120.   ..$showon(Hint):{ tsay $msg.hint.hint }
  121.   .$showon(Open)
  122.   ..$showon(Questions):{ if $isfile($qfile(1)) { run $qfile(1) } }
  123.   ..$showon(Additions):{ if $isfile(" $+ $triv(dir) $+ / $+ $triv(additions) $+ ") { run " $+ $triv(dir) $+ / $+ $triv(additions) $+ " } }
  124.   ..$showon(Report):{ if $isfile(" $+ $triv(dir) $+ / $+ $triv(report) $+ ") { run " $+ $triv(dir) $+ / $+ $triv(report) $+ " } }
  125.   .$showon(-)
  126.   .Trivia Bot is [ $trivon ]
  127.   ..$showon([ $trivdisflip ]) $+ :{ setset status bot $iif($getset(status,bot) == 1,0,1) }
  128.   ..[ $trivoffflip ] $+ :{ setset status botstate $iif($getset(status,botstate) == 1,0,1) }
  129.   .-
  130.   .Trivia Unload:{ if ($?!="Really Unload?") { unload -rs $script } }
  131. }
  132. menu nicklist {
  133.   $showon(Trivia)
  134.   .$showon(Control)
  135.   ..$showon(Ban):{ tban $$1 }
  136.   ..$showon(Unban):{ tunban $$1 }
  137.   .$showon(Add as Friend): { triviafriend.add $address($$1,7) }
  138.   .$showon(Credit)
  139.   ..$showon(Award)
  140.   ...$showon(1): { trivia.credit $$1 1 }
  141.   ...$showon(5): { trivia.credit $$1 5 }
  142.   ...$showon(10): { trivia.credit $$1 10 }
  143.   ..$showon(Deduct)
  144.   ...$showon(1): { trivia.credit $$1 -1 }
  145.   ...$showon(5): { trivia.credit $$1 -5 }
  146.   ...$showon(10): { trivia.credit $$1 -10 }
  147.   ..$showon(Input Amount): { trivia.credit $$1 $$?="How many points do you wish to give, -# to remove score" }
  148. }
  149. alias showon { if ($getset(status,botstate) != 1) return $1- }
  150. alias trivia.turnedoff { if ($getset(status,botstate) == 1) return $true }
  151. ;########################################################
  152. ;# Menubar related, aliases.                            #
  153. ;########################################################
  154. alias trivia.credit {
  155.   if ($2 isnum) {
  156.     setvar $1 score $calc($getvar($1,score) + $2)
  157.     process.scores.time $1 $2
  158.     tsay $iif($2 >= 0,$msg.trivia.awarded($1,$2),$msg.trivia.deducted($1,$2))
  159.   }
  160. }
  161. alias -l trivon { return $iif($getset(status,botstate),Off,$iif($getset(status,bot),$iif($trivia.paused,Paused,Enabled), Disabled)) }
  162. alias -l trivdisflip { return $iif($getset(status,bot),Disable,Enable) }
  163. alias -l trivoffflip { return $iif($getset(status,botstate),On,Off) }
  164. alias -l trivia.chan { return $iif($trivchan, Yes, No) }
  165. alias -l trivia.dir { return $iif($isdir(" $+ $triv(dir) $+ "), Yes, No) }
  166. alias -l trivia.file { return $iif($isfile($qfile(1)), Yes, No) }
  167. alias -l trivia.onoff { return $iif($trivia.on, On, Off) }
  168. alias -l team.onoff { return $iif($team, On, Off) }
  169. ;########################################################
  170. ;# Init aliases.                                        #
  171. ;########################################################
  172. alias -l nset { if ($getset($1, $2) == $null) { setset $1- } }
  173. alias -l init.load {
  174.   convertscores
  175.   convertscores $tempini
  176.   nset award 1 1 1 1 50 0  gives * a high five for getting ^ wins! Way to go * !
  177.   nset award 2 1 1 1 100 0 gives * a large pizza for getting ^ wins! Way to go * !
  178.   nset award 3 1 1 1 150 0 ^ wins... I am not worthy...
  179.   nset award 4 2 1 1 3 0 hands * a cold beer for getting the last ^ questions!
  180.   nset award 5 2 1 1 5 0 hands * 6-pack of icy beers for getting the last ^ questions!
  181.   nset award 6 2 1 1 10 0 gives * keg of beer for kicking everybodies asses! ^ questions!
  182.   nset award 7 2 1 1 15 0 bows before * a trivia god...
  183.   nset award 8 2 2 2 3 5 You're on fire!
  184.   nset award 9 3 4 5 1.5 0 Autoban based on speed.
  185.   nset award 10 4 3 5 120 0 Autoban based on Words per minute.
  186.   nset award 11 7 0 2 0 0 * has moved up in rank: ^
  187.   nset award 12 8 0 2 0 0 *, congratulations on your promotion to: ^
  188. }
  189. alias -l trivia.init {
  190.   nset status bot 1 | nset status echo 0 | nset status autohint 1 | nset status showanswer 1 | nset status cross 1
  191.   nset status number 30 | nset status hintpause 1 | nset trivia additions additions.txt
  192.   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
  193.   nset trivia delimiter * | nset trivia tnaoff 5 | nset trivia hintpause 5 | nset trivia perchint 30 | nset trivia numhint 1
  194.   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 ping 10
  195.   nset lag betweenhint 10 | nset lag timedout 60 | nset lag hintallow 10 | nset trivia dir $ifd($nofile($findfile($mircdir,$triv(questions), 1)),$mircdir)
  196.   nset trivia report report.txt | nset trivia reset 1000 | nset team 0victory The *t1 and the *t2 tied | nset team 1 'Team 1's
  197.   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
  198.   nset team JoinBeforeOn 1 | nset status nodecheater 1
  199.   varcolors
  200. }
  201. alias -l trivia.fail {
  202.   if ($version < 5.91) { echo Please use mIRC 5.91 or later. }
  203.   if (!$server) { echo Please connect to a server before attempting to use $msg.trivia.version }
  204.   if ($getset(status,bot) == 0) { echo The trivia bot is off. Commands, Trivia, Disabled to reenable. }
  205.   if ($isdir(" $+ $triv(dir) $+ ") == $false) { echo The trivia directory, $triv(dir) $+ , is invalid. }
  206.   if ($triv(dir) == $null) { echo The trivia directory setting is blank, please set it to the desired directory. }
  207.   if ($numl <= 0) { echo There appears to be no questions within the question file(s). }
  208. }
  209. alias get.find { if ($qfind($1-)) return $qfind($1-) }
  210. ;########################################################
  211. ;# Trivia command, related aliases.                     #
  212. ;########################################################
  213. alias -l ifd { return $iif($1, $1, $2) }
  214. ;########################################################
  215. ;# Command processing.                                  #
  216. ;########################################################
  217. alias pre { return $ifd(%command-prefix, !) }
  218. alias commandtokens { return state;disable;enable;op;trivia;strivia;pause;resume;theme;themes;stats;stat;won;hof;top10;hofstreak;row;streak;hoftime;hoffast;hofwpm;wpm;server;record;records;champ;version;web;add;report;ping;triviaping;help;join;showteams;roundscores;answer;next;hint;!hint;words;last;vowels;repeat;hofscoreday;hoftimeday;hofstreakday;hofwpmday;hofscoreweek;hoftimeweek;hofstreakweek;hofwpmweek;hofscoremonth;hoftimemonth;hofstreakmonth;hofwpmmonth;hofscoreyear;hoftimeyear;hofstreakyear;hofwpmyear;rank;promotion }
  219. alias optokens { return enable;disable;ban;unban;banned;ask;add;find }
  220. alias stattokens { return score;time;streak;wpm }
  221. alias timetokens { return day;week;month;year;total }
  222. alias starttokens { return Unlimited;team }
  223. alias ctok { return $findtok($eval($ $+ $gettok(commandtokens;optokens;stattokens;timetokens;starttokens,$ifd($2,1),59),2),$untrans($1),1,59) }
  224. alias gtok { return $trivtran($gettok($eval($ $+ $gettok(commandtokens;optokens;stattokens;timetokens;starttokens,$ifd($2,1),59),2),$1,59)) }
  225. alias rtok { return $gettok($eval($ $+ $gettok(commandtokens;optokens;stattokens;timetokens;starttokens,$ifd($2,1),59),2),$1,59) }
  226. alias -l processcommand {
  227.   var %command = $right($1,$calc(-1 * $len($pre)))
  228.   var %ctok = $ctok(%command)
  229.   award command %command $2-
  230.  
  231.   if (!%ctok) { return }
  232.   if (%ctok == 1) { inform $msg.trivia.state }
  233.   if (%ctok == 2) { opcommand disable $2- }
  234.   if (%ctok == 3) { opcommand enable $2- }
  235.   if (%ctok == 4) { opcommand $2- }
  236.   if (($getset(status,bot) == 0) || ($trivia.banned)) { return }
  237.   if (%ctok == 5) { if (!$isdis(28)) { trivia $2- } }
  238.   if (%ctok == 6) { if ((!$isdis(29)) && ($trivia.on) && ((!$team) || ($nick isop $iden))) { strivia $iden $nick } }
  239.   if (%ctok == 8) { if (!$isdis(5)) { trivia.pause 1 } }
  240.   if (%ctok == 7) { if ((!$trivia.paused) && (!$isdis(5))) { trivia.pause } }
  241.   if (%ctok isnum 9-10) { if (!$isdis(18)) { inform $msg.trivia.themes } }
  242.   if (%ctok isnum 11-13) { processcommand.stats $ifd($2,$nick) $ifd($3,$unit.default) }
  243.   if (%ctok isnum 14-15) { if (!$isdis(8)) { processcommand.hof $ifd($2,score) $ifd($3,$unit.default) } }
  244.   if (%ctok isnum 16-18) { if (!$isdis(10)) { processcommand.hof streak $unit.default } }
  245.   if (%ctok isnum 19-20) { if (!$isdis(9)) { processcommand.hof time $unit.default } }
  246.   if (%ctok isnum 21-22) { if (!$isdis(11)) { processcommand.hof wpm $unit.default } }
  247.   if (%ctok isnum 45-60) {
  248.     var %regmatch = / $+ (?: $+ $gtok(14) $+ $chr(124) $+ $rtok(14) $+ ) $+ \s?( $+ $gtok(1,3) $+ $chr(124) $+ $gtok(2,3) $+ $chr(124) $+ $gtok(3,3) $+ $chr(124) $+ $gtok(4,3) $+ $chr(124) $+ $rtok(1,3) $+ $chr(124) $+ $rtok(2,3) $+ $chr(124) $+ $rtok(3,3) $+ $chr(124) $+ $rtok(4,3) $+ )\s?( $+ $gtok(1,4) $+ $chr(124) $+ $gtok(2,4) $+ $chr(124) $+ $gtok(3,4) $+ $chr(124) $+ $gtok(4,4) $+ $chr(124) $+ $rtok(1,4) $+ $chr(124) $+ $rtok(2,4) $+ $chr(124) $+ $rtok(3,4) $+ $chr(124) $+ $rtok(4,4) $+ )/
  249.     if ($regex(%command, %regmatch)) processcommand.hof $iif($regml(1),score) $ifd($regml(2),$unit.default)
  250.   }
  251.   if (%ctok isnum 61-62) { if (!$isdis(30)) inform $msg.trivia.rank($ifd($2,$nick)) }
  252.   if (%ctok == 23) { inform $server }
  253.   if (%ctok isnum 24-25) { if (!$isdis(12)) { inform $msg.trivia.records } }
  254.   if (%ctok == 26) { inform $msg.trivia.champ }
  255.   if (%ctok == 27) { inform $msg.trivia.version }
  256.   if (%ctok == 28) { inform $msg.trivia.web }
  257.   if (%ctok isnum 29-30) { if (!$isdis(19)) { trivia.report %ctok $2- } }
  258.   if (%ctok isnum 31-32) { if (!$isdis(17))  { do.ping } }
  259.   if (%ctok == 33) { givehelp $2- }
  260.   if (%ctok == 34) { if ($team) { $setteam($nick, $2) } }
  261.   if (%ctok == 35) { if ($team) { inform $msg.trivia.showteams } }
  262.   if (%ctok == 36) { inform $msg.trivia.roundscores }
  263.   if (%ctok == 37) { if (($thget(answer)) && (!$isdis(16))) { inform $msg.question.answer } }
  264.   if ((!$question.on) || ($trivia.paused)) { return }
  265.   if (%ctok == 38) { if (($calc($question.time * 2) >= $lag(timedout)) && (!$isdis(15))) { trivx $chan } }
  266.   if (%ctok isnum 39-43) {
  267.     if (($question.time >= $lag(hintallow))) {
  268.       if (($getset(trivia, hintpause)) && ($getset(status, hintpause))) { hadd -u $+ $triv(hintpause) Trivia $+ $idenn Temp. $+ hinted. $+ $nick 1 }
  269.       if (%ctok isnum 39-40) { if (!$isdis(22)) { give.hint $iden } }
  270.       if (%ctok == 41) { if (!$isdis(25)) { inform $msg.hint.words } }
  271.       if (%ctok == 42) { if (!$isdis(24)) { inform $msg.hint.last } }
  272.       if (%ctok == 43) { if (!$isdis(23)) { inform $msg.hint.vowels } }
  273.     }
  274.   }
  275.   if (%ctok == 44) { if (!$isdis(26)) { inform $$thget(trivq.say) } }
  276. }
  277. alias processcommand.hof {
  278.   if (!$2) { var %unit = 5 }
  279.   else { var %unit = $ctok($2,4) }
  280.   var %by = $ctok($1,3)
  281.   if ($getset(hide,$rtok(%by,3))) { return }
  282.   if ((!%by) || (!%unit)) { inform $msg.trivia.hof.error | return }
  283.   inform $msg.trivia.topstats($rtok(%by,3),$rtok(%unit,4))
  284. }
  285. alias -l processcommand.stats {
  286.   if (!$2) { var %unit = 5 }
  287.   else { var %unit = $ctok($2,4) }
  288.   if (!%unit) { inform $msg.trivia.stats.error | return }
  289.   if ($1 isnum) { sort score $unit.set(%unit) }
  290.   if ($1 isnum 1 - $hof.size) { inform $msg.trivia.stats($hof($1,1),$unit.set(%unit)) }
  291.   else { inform $msg.trivia.stats($iif($1,$1,$nick),$unit.set(%unit)) }
  292. }
  293. alias unit.default { return $rtok($ifd($getset(status,scoreby),5),4) }
  294. alias unit.set { return $iif($rtok($1,4) != total,$rtok($1,4)) }
  295. alias unit.prefix { return $iif($ifd($1,$unit.default) != total, $ifd($1,$unit.default)) }
  296. ;########################################################
  297. ;# !Op command structure.                               #
  298. ;########################################################
  299. alias -l opcommand {
  300.   var %otok = $ctok($1,2)
  301.   if ($isdis(6)) { return }
  302.   if ((%otok == 1) && (!$isdis(21)) && ($getset(status,bot) == 0) && ((!$2) || ($2 == $me))) {
  303.     setset status bot 1
  304.     tsay $msg.trivia.enabled
  305.   }
  306.   if ((%otok == 2) && (!$isdis(21)) && ($getset(status,bot) == 1)  && ((!$2) || ($2 == $me))) {
  307.     setset status bot 0
  308.     tsay $msg.trivia.disabled
  309.     strivia $iden $nick
  310.   }
  311.   if ((%otok == 3) && (!$isdis(20))) {
  312.     if (!$2) { inform $msg.trivia.error.ban }
  313.     else {
  314.       tban $2
  315.       inform $msg.trivia.op.ban
  316.     }
  317.   }
  318.   if ((%otok == 4) && (!$isdis(7))) {
  319.     if (!$2) { inform $msg.trivia.error.unban }
  320.     else {
  321.       tunban $2
  322.       inform $msg.trivia.op.unban
  323.     }
  324.   }
  325.   if (%otok == 5) { inform $msg.trivia.banlist }
  326.   if ((%otok == 6) && (!$isdis(14))) {
  327.     if ($2 !isnum) { inform $msg.trivia.error.badnum }
  328.     else {
  329.       ask $2
  330.       inform $msg.trivia.op.ask
  331.     }
  332.   }
  333.   if ((%otok == 7) && (!$isdis(27))) {
  334.     if (!$2) { inform $msg.trivia.error.noquestion }
  335.     elseif ($triv(delimiter) !isin $2-) { inform $msg.trivia.error.nodelim }
  336.     else {
  337.       add $2-
  338.       inform $msg.trivia.op.added
  339.     }
  340.   }
  341.   if ((%otok == 8) && (!$isdis(13))) {
  342.     if (!$2) { inform $msg.trivia.error.nosearch }
  343.     else inform $msg.trivia.op.find($2-)
  344.   }
  345. }
  346. ;########################################################
  347. ;# Trivia ON.                                           #
  348. ;########################################################
  349. alias trivia {
  350.   if (($trivia.banned) || ($trivia.on) || (!$trivchan)) { return }
  351.   if ($trivia.paused) {
  352.     tsay $msg.trivia.pause
  353.     return
  354.   }
  355.   trivia.flush
  356.   if ($trivia.fail) return
  357.   if ($hget(Trivia $+ $idenn)) { hfree Trivia $+ $idenn }
  358.   hmake Trivia $+ $idenn 20
  359.   if (($hget(Asked $+ $idenn)) && ($getset(status,keepask))) { hfree Asked $+ $idenn }
  360.   if (!$hget(Asked $+ $idenn)) hmake Asked $+ $idenn 50
  361.   trivia.defaultgame
  362.   thset STime $time $date
  363.   thset SUser $iif($nick,$nick,$me)
  364.   if (($getset(Trivia,odefault) == unlimited) || (($ctok($1,5) == 1) && (!$isdis(2))) ) { thset Max Unlimited }
  365.   if (($getset(Trivia,odefault) == team) || (($ctok($1,5) == 2) && (!$isdis(3)))) { thset team 1 }
  366.   if (($1 isnum 1 - $numl) && (!$isdis(1))) { thset Max $int($1) }
  367.   if ($1 == pi) { thset Max 3.14159265358979323846 }
  368.   if ($1 == e) { thset Max 2.718281828459045 }
  369.   if (!$isdis(18)) { trivia.themecheck $1- }
  370.   if ($thget(team)) { trivia.teammode $2 }
  371.   tsay $msg.trivia.started
  372.   .timerq $+ $idenn 1 $ifd($lag(start),0) trivq $chan
  373.   award roundstart $thget(Max)
  374. }
  375. ;########################################################
  376. ;# Trivia OFF.                                          #
  377. ;########################################################
  378. alias strivia {
  379.   set -u3 %ident $1
  380.   if ($team) { strivia.teammode }
  381.   else if ($getset(status,bot)) {
  382.     if ($getset(Var $+ $idenn, Lastwinner) == $2) { setset Var $+ $idenn Row 0 }
  383.     tsay $msg.trivia.stopped
  384.     if ($thget(Current) >= 10) { tsay $strivia.end($triv(Record)) }
  385.     award RoundStop $thget(Current)
  386.   }
  387.   trivia.flush
  388. }
  389. alias strivia.end {
  390.   if ($1 == 1) { return $msg.trivia.hof }
  391.   elseif ($1 == 2) { return $msg.trivia.topstats(streak) }
  392.   elseif ($1 == 3) { return $msg.trivia.topstats(time) }
  393.   elseif ($1 == 4) { return $msg.trivia.topstats(wpm) }
  394.   elseif ($1 == 5) { return $msg.trivia.champ }
  395.   elseif ($1 == 6) { return $msg.trivia.web }
  396.   elseif ($1 == 7) { return $msg.trivia.roundscores }
  397.   return $msg.trivia.records
  398. }
  399. ;########################################################
  400. ;# STATUS CLEARING.                                     #
  401. ;########################################################
  402. alias -l trivia.flush {
  403.   if (!$getset(status,keepask)) if ($hget(Asked $+ $idenn)) { hfree Asked $+ $idenn }
  404.   if ($hget(Trivia $+ $idenn)) { hfree Trivia $+ $idenn }
  405.   trivia.timersoff
  406.   unset %cache.nick
  407.   unset %cache.line
  408. }
  409. alias -l trivia.timersoff {
  410.   .timer* $+ $idenn off
  411. }
  412. ;########################################################
  413. ;# DEFAULT setup.                                       #
  414. ;########################################################
  415. alias trivia.defaultgame {
  416.   thset File questions.txt
  417.   thset Scores $scoresfil
  418.   if ($tchan($trivchan, 4)) { thset Scores $tchan($trivchan, 4) }
  419.   if ($tchan($trivchan, 5)) {
  420.     thset File
  421.     var %i = 5
  422.     while ($tchan($trivchan, %i)) {
  423.       thset File $thget(file) $+ ; $+ $tchan($trivchan, %i)
  424.       inc %i
  425.     }
  426.   }
  427.   thset Max $triv(default)
  428.   thset PPQ $iif($getset(Trivia,PPQ) != $null,$getset(Trivia,PPQ),1)
  429.   thset DPH $iif($getset(Trivia,DPH) != $null,$getset(Trivia,DPH),0)
  430.   thset RRS $iif($getset(Status,RRS) != $null,$getset(Status,RRS),0)
  431.   thset guess $iif($getset(trivia,limitguess) != $null,$getset(trivia,limitguess),0)
  432.   thset lagstart $iif($getset(lag, start) != $null, $getset(lag, start), 0)
  433.   thset laganswered $iif($getset(lag, answered) != $null, $getset(lag, answered), 0)
  434.   thset lagtimedout $iif($getset(lag, timedout) != $null, $getset(lag, timedout), 0)
  435.   thset laghint $iif($getset(lag, hint) != $null, $getset(lag, hint), 0)
  436.   thset lagtimed $iif($getset(lag, timed) != $null, $getset(lag, timed), 0)
  437.   thset laghintallow $iif($getset(lag, hintallow) != $null, $getset(lag, hintallow), 0)
  438.   thset lagbetweenhint $iif($getset(lag, betweenhint) != $null, $getset(lag, betweenhint), 0)
  439. }
  440. ;########################################################
  441. ;# THEMED start.                                        #
  442. ;########################################################
  443. alias trivia.themecheck {
  444.   var %i = 1
  445.   while ($getset(triviamode $+ %i, Name)) {
  446.     if ($1 == $getset(triviamode $+ %i, Name)) {
  447.       trivia.themestart %i
  448.       if (($2 isnum) && ($2 <= $numq) && ($2 > 0) && (!$isdis(4))) { thset Max $int($2) }
  449.       return
  450.     }
  451.     inc %i
  452.   }
  453. }
  454. alias trivia.themestart {
  455.   var %j = $setini(triviamode $+ $1,0)
  456.   while (%j >= 1) {
  457.     var %mode = $setini(triviamode $+ $1, %j)
  458.     thset %mode $getset(triviamode $+ $1, %mode)
  459.     dec %j
  460.   }
  461. }
  462. ;########################################################
  463. ;# TEAM setup.                                          #
  464. ;########################################################
  465. alias -l trivia.teammode {
  466.   thset Score1 0
  467.   thset Score2 0
  468.   thset Score3 0
  469.   thset Score4 0
  470.   if ($1 isnum 1 - $numq) { thset Max $int($1) }
  471.   else { thset Max $triv(dteam) }
  472.   tsay $msg.team.start
  473. }
  474. alias -l strivia.teammode {
  475.   var %s1 = $thget(Score1)
  476.   var %s2 = $thget(Score2)
  477.   var %s3 = $thget(Score3)
  478.   var %s4 = $thget(Score4)
  479.   if ($getset(team,4-team)) {
  480.     if ((%s1 > %s2) && (%s1 > %s3) && (%s1 > %s3)) { tsay $msg.team.over($te(1).victory) }
  481.     elseif ((%s2 > %s1) && (%s2 > %s3) && (%s2 > %s4)) { tsay $msg.team.over($te(2).victory) }
  482.     elseif ((%s3 > %s1) && (%s3 > %s2) && (%s3 > %s4)) { tsay $msg.team.over($te(3).victory) }
  483.     elseif ((%s4 > %s1) && (%s4 > %s2) && (%s4 > %s3)) { tsay $msg.team.over($te(4).victory) }
  484.     else { tsay $msg.team.over($te(0).victory) }
  485.   }
  486.   else {
  487.     if (%s1 > %s2) { tsay $msg.team.over($te(1).victory) }
  488.     elseif (%s1 < %s2) { tsay $msg.team.over($te(2).victory) }
  489.     else { tsay $msg.team.over($te(0).victory) }
  490.   }
  491.   if ($getset(status, noshowt)) { tsay $msg.trivia.showteams }
  492. }
  493. alias -l setteam {
  494.   if (($thget(Current) >= $getset(Team, JoinBefore)) && ($getset(Team, JoinBeforeOn) == 1)) {
  495.     inform $msg.team.joinover
  496.     return
  497.   }
  498.   if ($2 isnum 1 - 4) {
  499.     if ($thget(Team. $+ $nick) == $2) { inform $msg.team.alreadyon }
  500.     else { tsay $msg.team.add($getset(team,$2), $nick) }
  501.     thset $eval(Team. $+ $nick,1) $2
  502.   }
  503. }
  504. ;########################################################
  505. ;# Trivia QUESTION.                                     #
  506. ;########################################################
  507. alias trivq {
  508.   set -u3 %ident $1
  509.   if (!$hget(Trivia $+ $idenn)) { return }
  510.   if ($trivia.fail) return
  511.   thset Current $calc($thget(Current) + 1)
  512.   if (($team) && ($thget(Current) == $getset(Team, JoinBefore)) && ($getset(Team, JoinBeforeOn) == 1)) { tsay $msg.team.joinbefore }
  513.   create.question
  514.   .timerend $+ $idenn 1 $lag(timedout) trivx $iden
  515.   trivia.startautohint
  516.   setset Var $+ $idenn Asked $calc($getset(Var $+ $idenn,Asked) + 1)
  517.   thset Start $ticks
  518.   trivia.sayquestion $right($thget(catq),-1)
  519.   if ($getset(status,echo) == 1) { echo $iden $msg.trivia.echoanswer }
  520.   if ($getset(status,answers)) { tsay $msg.hint.space }
  521.   award Question $lag(timedout)
  522. }
  523. alias -l create.question {
  524.   while ($thget(Ask1)) {
  525.     var %qread = $qread($thget(Ask1))
  526.     ask.deleteitem 1
  527.     thset Catq
  528.     if (%qread) return
  529.   }
  530.   var %temp.ask = $trivia.getq
  531.   thset Catq $qcat(%temp.ask)
  532.   hadd Asked $+ $idenn %temp.ask %temp.ask
  533. }
  534. alias -l trivia.getq {
  535.   unset %ask
  536.   while ((!%ask) || ($hget(Asked $+ $idenn, %ask))) {
  537.     if ($hget(Asked $+ $idenn,0).item >= $numq) { hdel -w Asked $+ $idenn * }
  538.     var %ask = $rand(1, $numq)
  539.     if (!$qread(%ask)) { hadd Asked $+ $idenn %ask NA }
  540.   }
  541.   thset Asking %ask
  542.   return %ask
  543. }
  544. ;########################################################
  545. ;# QUESTION MISC.                                       #
  546. ;########################################################
  547. alias qfile {
  548.   if (($1 !isnum) || ($1 < 1)) return
  549.   if (($thget(File)) && ($gettok($thget(File),$1,$asc(;)))) return $shortfn(" $+ $triv(dir) $+ \ $+ $gettok($thget(File),$1,$asc(;)) $+ ")
  550.   if ($tchan($ifd($trivchan,1),$calc(4 + $1))) return $shortfn(" $+ $triv(dir) $+ \ $+ $tchan($ifd($trivchan,1),$calc(4 + $1)) $+ ")
  551. }
  552.  
  553. alias numl { return $calc($numq - $numnonq) }
  554. alias numq {
  555.   if ($1 isnum) { return $lines($qfile($1)) }
  556.   var %i = 0, %j = 1
  557.   while ($qfile(%j)) {
  558.     if (!$eval(% $+ numq $+ $qfile(%j),2)) { set -u600 % $+ numq $+ $qfile(%j) $lines($qfile(%j)) }
  559.     %i = $calc(%i + $eval(% $+ numq $+ $qfile(%j),2))
  560.     inc %j
  561.   }
  562.   return %i
  563. }
  564. alias qcat {
  565.   if ($getset(status,nocat) == 1) return
  566.   var %nf = $numfile($1)
  567.   return $read($gettok(%nf,1,$asc(;)), wnt, #*, $gettok(%nf,2,$asc(;)))
  568. }
  569. alias numnonq {
  570.   window -h @numnonq
  571.   var %j = 1, %nonqcount = 0
  572.   while ($qfile(%j)) {
  573.     if ($eval(% $+ nonq $+ $qfile(%j),2)) { var %nonqcount = $calc(%numqcount + $eval(% $+ nonq $+ $qfile(%j),2)) }
  574.     else {
  575.       if ($exists($qfile(%j))) {
  576.         filter -fwgx $qfile(%j) @numnonq /\ $+ $triv(delimiter) $+ /
  577.         var %nonqcount = $calc(%nonqcount + $filtered)
  578.         set -u600 % $+ nonq $+ $qfile(%j) $filtered
  579.       }
  580.     }
  581.     inc %j
  582.   }
  583.   window -c @numnonq
  584.   return %nonqcount
  585. }
  586. alias numcat {
  587.   if ($window(@categories)) { window -c @categories }
  588.   window -eh @categories
  589.   var %j = 1
  590.   while ($qfile(%j)) {
  591.     if ($exists($qfile(%j))) filter -fw $qfile(%j) @categories #*
  592.     inc %j
  593.   }
  594.   .timer 1 0 window -c @categories
  595.   return $line(@categories,0)
  596. }
  597. alias numfile {
  598.   var %i = 0, %j = 1, %l
  599.   while ($qfile(%j)) {
  600.     %l = %i
  601.     inc %i $numq(%j)
  602.     if ($1 isnum %l - %i) { return $qfile(%j) $+ ; $+ $calc($1 - %l) }
  603.     if (($1 !isnum) && ($read($qfile(%j), nwt, $+(*,$1-,*), 1))) return $qfile(%j) $+ ; $+ $readn
  604.     inc %j
  605.   }
  606. }
  607. alias -l qfind {
  608.   var %i = 0, %j = 1, %l
  609.   if ($1 == $null) { return }
  610.   while ($qfile(%j)) {
  611.     if ($read($qfile(%j), nwt, $+(*,$1-,*), 1)) return $read($qfile(%j),$readn) - $qfile(%j) - $readn
  612.     inc %j
  613.   }
  614. }
  615. alias qread {
  616.   var %nf = $numfile($1)
  617.   var %delim = \ $+ $triv(delimiter)
  618.   if ($regex($iif($1 isnum,$read($gettok(%nf,1,$asc(;)), nt, $gettok(%nf,2,$asc(;))),$1-),/^([^ $+ %delim $+ ]+)([ $+ %delim $+ ].*)$/)) {
  619.     thset tok1 $regml(1)
  620.     if ($regex($regml(2), /[ $+ %delim $+ ]([^ $+ %delim $+ ]+)/g)) {
  621.       thset numfile %nf
  622.       thset tokq $calc($regml(0) + 1)
  623.       var %i = 1
  624.       while (%i <= $regml(0)) {
  625.         thset tok $+ $calc(%i + 1) $regml(%i)
  626.         inc %i
  627.       }
  628.     }
  629.   }
  630.   else {
  631.     if ($1 == scramble) { thset temp.bonus S }
  632.     if ($1 == reverse) { thset temp.bonus R }
  633.     if ($1 == shotgun) { thset temp.bonus G }
  634.     return $false
  635.   }
  636.   return $true
  637. }
  638. alias -l ask.deleteitem {
  639.   hdel Trivia $+ $idenn Ask $+ $$1
  640.   var %i = $1
  641.   while ($thget(Ask $+ $calc(%i + 1))) {
  642.     thset Ask $+ %i $thget(Ask $+ $calc(%i + 1))
  643.     inc %i
  644.   }
  645.   if ($thget(Ask $+ %i)) { hdel Trivia $+ $idenn Ask $+ %i }
  646. }
  647. alias -l trivia.startautohint { if ($getset(status,autohint) == 1) { .timerhint $+ $idenn 1 $lag(hint) trivia.autohint $iden } }
  648. alias -l trivia.autohint {
  649.   give.hint $1
  650.   if ($triv(numhint) > 1) { .timerhint $+ $idenn $calc($triv(numhint) - 1) $lag(betweenhint) give.hint $1 }
  651. }
  652. alias decheater {
  653.   if ($getset(status,nodecheater) == 1) return $1-
  654.   var %t.rt = $1-, %i = $count($1-,$chr(32)), %t.ps
  655.   while (%i > 0) {
  656.     if ($rand(1,2) == 1) {
  657.       %t.ps = $pos($1-,$chr(32),%i)
  658.       %t.rt = $+($left(%t.rt, $calc(%t.ps - 1)), $chr(160),$right(%t.rt,$calc((%t.ps) * -1)))
  659.     }
  660.     dec %i
  661.   }
  662.   return %t.rt
  663. }
  664. ;########################################################
  665. ;#  QUESTION over.                                      #
  666. ;########################################################
  667. alias trivx {
  668.   set -u3 %ident $1
  669.   if (!$hget(Trivia $+ $idenn)) { return }
  670.   if (!$2) {
  671.     if (($getset(status,showanswer)) && (!$getset(status,shownone))) { tsay $iif($thget(temp.type) == T, $msg.answer.timeout.total, $iif($thget(temp.type) == P, $msg.answer.timeout.pick, $msg.answer.timeout)) }
  672.     else { tsay $msg.answer.timeout2 }
  673.     setset Var $+ $idenn Row 0
  674.     thset Unanswered $calc($thget(Unanswered) + 1)
  675.     award NoAnswer $trivq.answer
  676.   }
  677.   trivia.timersoff
  678.   if ($window($total.win)) { window -c $total.win }
  679.   thset Answer $trivq.answer
  680.   if ($hget(Trivia $+ $idenn)) hdel -w Trivia $+ $idenn Temp.*
  681.   if ($hget(Trivia $+ $idenn)) hdel -w Trivia $+ $idenn tok*
  682.   if (($nick) && ($getvar($nick,score) >= $triv(reset)) && ($getset(status,champ) == 1)) { trivia.newchamp }
  683.   if ((($team) && ($thget(Score $+ $isteam($nick)) > $calc($thget(Max)/2))) || (($getset(status,emptyoff)) && ($nick($iden,0) <= 1)) || (($getset(status, naoff) == 1) && ($thget(unanswered) >= $triv(naoff))) || (($thget(Max) != unlimited) && ($thget(Current) >= $thget(Max)))) {
  684.     strivia $1
  685.     if (($getset(status, emptyoff) == 1) && ($nick($iden,0) <= 1)) tsay $msg.trivia.emptyoff
  686.     if (($getset(status, naoff) == 1) && ($thget(Unanswered) >= $triv(naoff))) tsay $msg.trivia.unactive
  687.     return
  688.   }
  689.   .timerq $+ $idenn 1 $iif($1, $lag(answered), $lag(timed)) trivq $iden
  690. }
  691. alias -l trivia.processscore {
  692.   if ($getset(Var $+ $idenn, Lastwinner) == $nick) { setset Var $+ $idenn Row $calc($getset(Var $+ $idenn, Row) + $ifd($2,1)) }
  693.   else { setset Var $+ $idenn Row $ifd($2,1) }
  694.   setset Var $+ $idenn Wins $calc($getset(Var $+ $idenn,Wins) + $ifd($2,1))
  695.   setset Var $+ $idenn Lastwinner $nick
  696.   setvar $nick Lastwin $date
  697.   thset WPM $calc(($len($1) * 60) / ($thget(Time) * 5))
  698.   if (($thget(WPM) > $realvar($nick,wpm)) || (!$realvar($nick,wpm))) { setvar $nick wpm $thget(WPM) }
  699.   if (($getset(Var $+ $idenn, Row) > $realvar($nick,streak)) || (!$realvar($nick,streak))) { setvar $nick Streak $getset(Var $+ $idenn, Row) }
  700.   if (($thget(Time) < $realvar($nick,time)) || (!$realvar($nick,time))) { setvar $nick Time $thget(Time) }
  701.   thset temp.cng $calc(($thget(PPQ) * $ifd($2,1)) - ($thget(DPH) * $max.hinted))
  702.   if ($thget(temp.points) != $null) { thset temp.cng $calc(($thget(temp.points) - ($max.hinted * $thget(temp.hintreduction))) * $ifd($2,1)) }
  703.   thset temp.mrank $getmrank($nick)
  704.   thset temp.rank $getrank($nick,$unit.default,$thget(temp.cng))
  705.   thset temp.newrank $calc($thget(temp.rank) - %uprank)
  706.   setvar $nick Score $calc($realvar($nick, Score) + $thget(temp.cng))
  707.   setvar $nick Answered $calc($realvar($nick, Answered) + $iif($2 > 0,$2,1))
  708.   thset $eval(Score. $+ $nick,1) $calc($thget($eval(Score. $+ $nick,1)) + $thget(temp.cng))
  709.   process.scores.time $nick $thget(temp.cng) $getset(Var $+ $idenn, Row) $thget(Time) $thget(WPM)
  710. }
  711. alias trivia.processawards {
  712.   if (%uprank) award uprank $tranord($thget(temp.newrank))
  713.   if ($getmrank($nick) != $thget(temp.mrank)) award promotion $getmrank($nick)
  714.   award score $user.score($nick)
  715.   award row $getset(Var $+ $idenn, Row)
  716.   award time $thget(Time)
  717.   award wpm $thget(WPM)
  718.   award answered $thget(Time)
  719. }
  720. alias -l answered {
  721.   thset Time $question.time
  722.   if (($1 == $null) || ($trivia.banned) || ($trivia.negationcheck) || (($team) && (!$isteam($nick)))) { return }
  723.   $trivia.processscore($1,$2)
  724.   if (($getset(build,instabuild)) && ($getset(build,instabuild) // $getset(Var $+ $idenn,Wins))) { htmltrigger $iden }
  725.   tsay $msg.answer.correct($getset(status,tradwin),$thget(WPM),$thget(temp.newrank),$iif(%uprank,$thget(temp.rank)))
  726.   if ($team) {
  727.     thset Score $+ $isteam($nick) $calc($thget( Score $+ $isteam($nick)) + 1)
  728.     tsay $msg.team.score
  729.   }
  730.   trivia.processawards
  731.   if ($thget(RRS)) { tsay $msg.trivia.roundscores }
  732.   hdel Trivia $+ $idenn Unanswered
  733.   if ($total.over) { tsay $msg.trivia.totalover }
  734.   if (($thget(temp.type) != T) || ($total.over)) { trivx $chan $true }
  735. }
  736. alias -l trivq.answer { return $iif(((($thget(temp.type) == T) || ($getset(status,showmatched))) && ($thget(temp.matched))), $thget(temp.matched),$tok(2)) }
  737. ;########################################################
  738. ;# QUESTION Typing.                                     #
  739. ;########################################################
  740. alias -l trivia.sayquestion {
  741.   if ($regex($tok(1), /^([^:]+):\s?(.+)|((?i)Scramble|Uword)$/)) {
  742.     thset temp.mode $regml(1)
  743.     thset temp.rest $regml(2)
  744.     if (($gettok($thget(temp.mode),1,44) isnum) && ($getset(status,nobonus) != 1)) {
  745.       thset temp.points $gettok($thget(temp.mode),1,44)
  746.       if ($gettok($thget(temp.mode),2,44) isnum) { thset temp.hintreduction $gettok($thget(temp.mode),2,44) }
  747.       var %tq $msg.question.points($1-,$thget(temp.rest))
  748.     }
  749.     elseif ($regex($lower($thget(temp.mode)), /pick\s(\d+)/)) {
  750.       var %tq $msg.question.standard($1-,$thget(temp.rest))
  751.       thset temp.type P
  752.       thset temp.pick $regml(1)
  753.     }
  754.     elseif (Multi == $thget(temp.mode)) {
  755.       var %tq $msg.question.multi($1-)
  756.       thset temp.type M
  757.     }
  758.     elseif (Total == $thget(temp.mode)) {
  759.       var %tq $msg.question.total($1-)
  760.       thset temp.type T
  761.       total.init
  762.     }
  763.     elseif (Scramble == $thget(temp.mode)) || (UWord == $thget(temp.mode)) {
  764.       var %tq $msg.question.scramble($1-,$thget(temp.rest))
  765.       thset temp.type S
  766.     }
  767.   }
  768.   if (!%tq) { var %tq $msg.question.standard($1-) }
  769.   thset trivq.say $iif($getset(status,nosaycurrent) != 1, $e1($thget(Current)) $+ $e2(.)) $decheater(%tq)
  770.   tsay $thget(trivq.say)
  771. }
  772. ;########################################################
  773. ;# TOTAL question type, control.                        #
  774. ;########################################################
  775. alias unfix {
  776.   var %i = 2
  777.   while (%i <= $tokq) {
  778.     if ($1- == $fix($tok(%i))) { return $tok(%i) }
  779.     inc %i
  780.   }
  781. }
  782. alias total.win { return @total $+ $idenn }
  783. alias total.init {
  784.   var %i = 2
  785.   if ($window($total.win)) { window -c $total.win }
  786.   window -h $total.win
  787.   while (%i <= $tokq) {
  788.     aline -n $total.win $tok(%i)
  789.     inc %i
  790.   }
  791. }
  792. alias total.left { return $line($total.win,0) }
  793. alias total.is { return $fline($total.win,$1-,1) }
  794. alias total.rem { dline $total.win $total.is($1-) }
  795. alias total.over { return $iif(!$line($total.win,0) && ($thget(temp.type) == T), 1) }
  796. alias gettotalremain {
  797.   var %i = 1, %totalremain
  798.   while (%i <= $line($total.win,0)) {
  799.     %totalremain = $left(%totalremain,850) $+ $iif(%totalremain != $null,$chr(44)) $line($total.win,%i)
  800.     inc %i
  801.   }
  802.   return %totalremain
  803. }
  804. ;########################################################
  805. ;# Trivia block answer.                                 #
  806. ;########################################################
  807. alias -l trivia.negationcheck {
  808.   if ($thuser(Hinted)) {
  809.     inform $msg.trivia.hintpaused
  810.     return $true
  811.   }
  812.   if (($getset(status,limitguess)) && ($thget(temp.type) != T) && ($ifd($thuser(Guess),0) >= $thget(guess))) {
  813.     inform $msg.trivia.guessed($thuser(guess))
  814.     return $true
  815.   }  
  816. }
  817. ;########################################################
  818. ;# Guess processing.                                    #
  819. ;########################################################
  820. alias -l processguess {
  821.   if ($trivia.paused) { return }
  822.   var %pick = $regex($lower($fix($1-)), $trivia.pattern)
  823.   thuset Guess $calc($thuser(guess) + 1)
  824.   if (%pick == 0) { return }
  825.   var %answered, %matched = $regml(1), %i = 1
  826.   thset temp.match $regml(0)
  827.   while ($thget(temp.match) >= %i) {
  828.     thset temp.match. $+ %i $regml(%i)
  829.     inc %i
  830.   }
  831.   if (($thget(temp.type) == P) || ($thget(temp.type) == T)) {
  832.     var %j = 1, %k, %f, %numb.correct = 0
  833.     while (%j <= $thget(temp.match)) {
  834.       var %k = %j, %f = $true
  835.       while (%k >= 1) {
  836.         if ((%j != %k) && ($thget(temp.match. $+ %j) == $thget(temp.match. $+ %k))) { %f = $false }
  837.         dec %k
  838.       }
  839.       if ($thget(temp.type) == T) {
  840.         if ($total.is($unfix($thget(temp.match. $+ %j)))) {
  841.           total.rem $unfix($thget(temp.match. $+ %j))
  842.           inc %numb.correct
  843.         }
  844.         else { %f = $false }
  845.       }
  846.       if (%f) %answered = %answered $unfix($thget(temp.match. $+ %j))
  847.       else { dec %pick }
  848.       inc %j
  849.     }
  850.     if (($thget(temp.type) == P) && (%pick < $thget(temp.pick))) return
  851.     if (($thget(temp.type) == T) && (%numb.correct == 0)) return
  852.   }
  853.   else { var %answered = $unfix($thget(temp.match. $+ 1)) }
  854.   thset temp.matched %answered
  855.   $answered(%answered,%numb.correct)
  856. }
  857. alias fix {
  858.   if ($getset(status,nospellfix)) { return $lower($strip($1-)) }
  859.   var %temp.fix = $lower($strip($1-))
  860.   .echo -q $regsub(%temp.fix,/([^\s]+)s(?=(\s|$))/g, \1, %temp.fix)
  861.   .echo -q $regsub(%temp.fix,/(?<=^|\s)(?:the|an|a)\s([^\s]+)/g, \1, %temp.fix)
  862.   %temp.fix = $remove(%temp.fix,',-,!,`,.,’,´,?,%,$chr(36),$chr(44))
  863.   %temp.fix = $replace(%temp.fix,À,A,Á,A,Â,A,Ã,A,Ä,A,Å,A,Æ,AE,Ç,C,È,E,É,E,Ê,E,Ë,E,Ì,I,Í,I,Î,I,Ï,I,Ð,D,Ñ,N,Ò,O,Ó,O,Ô,O,Õ,O,Ö,O,Ø,O,Ù,U,Ú,U,Û,U,Ü,U,Ý,Y)
  864.   %temp.fix = $replace(%temp.fix,ß,B,à,a,á,a,â,a,ã,a,ä,a,å,a,æ,ae,ç,c,è,e,é,e,ê,e,ë,e,ì,i,í,i,î,i,ï,i,ð,o,ñ,n,ò,o,ó,o,ô,o,õ,o,ö,o,ù,u,ú,u,û,u,ü,u,ý,y,ÿ,y)
  865.   return $replace(%temp.fix,kn,n,y,i,k,c,x,c,q,c,e,a,ah,a,u,o,ph,f,m,n,ll,l,aa,a,oo,o,cc,c,z,s)
  866. }
  867. alias trivia.pattern {
  868.   if ($thget(temp.pattern)) { return $thget(temp.pattern) }
  869.   var %i 2, %max = $iif($thget(temp.type) == M, 2, $tokq), %pattern = $chr(40)
  870.   while (%i <= %max) {
  871.     if (%i != 2) { %pattern = %pattern $+ $chr(124) }
  872.     %pattern = %pattern $+ $lower($fix($tok(%i)))
  873.     inc %i
  874.   }
  875.   %pattern = %pattern $+ $chr(41)
  876.   if (($thget(temp.type) != P) && ($thget(temp.type) != T)) {
  877.     if ($getset(status, exactmatch)) { %pattern = ^ $+ %pattern $+ $ }
  878.     elseif ($getset(status, nomid)) { %pattern = ^ $+ %pattern $+ (?=\s|$) $+ $chr(124) $+ (?:^|\s) $+ %pattern $+ $ }
  879.     else { %pattern = (?:^|\s) $+ %pattern $+ (?=\s|$) }
  880.   }
  881.   else { %pattern = (?:^|\s) $+ %pattern $+ (?=\s|$) }
  882.   %pattern = / $+ %pattern $+ /g
  883.   thset temp.pattern %pattern
  884.   return %pattern
  885. }
  886. ;########################################################
  887. ;# PAUSE/RESUME processing.                             #
  888. ;########################################################
  889. alias trivia.paused { if (($thget(paused)) && ($hget(Trivia $+ $idenn))) { return $true } }
  890. alias trivia.pause {
  891.   if ($1) {
  892.     if ($trivia.paused) {
  893.       .timerq $+ $idenn -r
  894.       .timerend $+ $idenn -r
  895.       .timerhint $+ $idenn -r
  896.       thset paused 0
  897.       tsay $msg.trivia.resume
  898.     }
  899.     else if (($thget(paused) != 1) && (!$timer(q $+ $idenn)) && (!$timer(end $+ $idenn)) && (!$timer(hint $+ $idenn)) && ($hget(Trivia $+ $idenn))) trivx
  900.   }
  901.   else {
  902.     .timerq $+ $idenn -p
  903.     .timerend $+ $idenn -p
  904.     .timerhint $+ $idenn -p
  905.     thset paused 1
  906.     tsay $msg.trivia.pause
  907.   }
  908. }
  909. ;########################################################
  910. ;# Hint setup.                                          #
  911. ;########################################################
  912. alias -l give.hint {
  913.   set -u3 %ident $1
  914.   if ((!$hget(Trivia $+ $idenn)) || ($max.hinted >= $triv(numhint))) { return }
  915.   if (!$nick) {
  916.     thset Temp.Hints $calc($thget(Temp.Hints) + 1)
  917.     var %hintpercent = $calc($triv(perchint) * $thget(Temp.Hints))
  918.     var %nexthintpercent = $calc($triv(perchint) * ($thget(Temp.Hints) + 1))
  919.     if ($thget(Temp.Skip.Hint $+ $thget(Temp.Hints)) == 1) { return }
  920.     if ($hintrepnum(%hintpercent) == $hintrepnum(%nexthintpercent)) thset Temp.Skip.Hint $+ $calc($thget(Temp.Hints) + 1) 1
  921.     if ($thget(Temp.Hints) == 1) tsay $eval($ $+ msg.hint. $+ $hintfirst $+ ( %hintpercent ),2)
  922.     else tsay $msg.hint.hint(%hintpercent)
  923.   }
  924.   else {
  925.     thuset Hint $calc($iif($calc($thget(Temp.Hints) + 0) > $calc($thuser(hint) + 0),$thget(Temp.Hints),$thuser(hint)) + 1)
  926.     if ($thget(Temp.Skip.Hint $+ $thuser(hint)) == 1) { return }
  927.     var %sayhint = $msg.hint.hint($calc($triv(perchint) * $thuser(hint)))
  928.     if (msg * iswm %respond) {
  929.       tsay %sayhint
  930.       thset Temp.Skip.Hint $+ $thuser(hint) 1
  931.     }
  932.     else inform %sayhint
  933.   }
  934.   award Hint $thget(Temp.Hints)
  935. }
  936. alias -l hintfirst {
  937.   var %hintfirst = $getset(trivia, firsthint)
  938.   if (!%hintfirst) return hint
  939.   if (%hintfirst == 1) return last
  940.   if (%hintfirst == 2) return vowels
  941.   if (%hintfirst == 3) return $gettok(hint.last.vowels.space.scramble, $rand(1,5), $asc(.))
  942. }
  943. alias -l get.hint {
  944.   if (($thget(temp.type) == T) || ($thget(Temp.type) == M)) { return }
  945.   if (($thget(temp.rhint. $+ $2)) && ($1 == hint)) { return $thget(temp.rhint. $+ $2) }
  946.   var %perhint = $iif($2,$2,$triv(perchint)), %hintc
  947.   if ($1 == words) { return $numtok($trivq.answer,32) }
  948.   if ($1 == space) { return $deletter($trivq.answer) }
  949.   if ($1 == last) { return $right($trivq.answer,1) }
  950.   if ($1 == vowels) { return $iif($regsub($trivq.answer, /([^aeiouAEIOU\s])/g, $trivchar, %hintc), %hintc, $trivq.answer) }
  951.   if ($1 == scramble) { return $scramble($trivq.answer) }
  952.   if ($getset(status, plot)) { return $plot(%perhint, $trivq.answer)) }
  953.   if ($getset(status, scatter)) {
  954.     thset temp.rhint. $+ $2 $scatter(%perhint, $trivq.answer)
  955.     return $thget(temp.rhint. $+ $2)
  956.   }
  957.   else { return $standard(%perhint, $trivq.answer) }
  958. }
  959. alias -l trivchar { return $iif($chr($triv(ch)),$chr($triv(ch)),_) }
  960. alias -l nonpunct { return /([^';:"\s\xA0\,\?\<\>\|\\\/\[\]\!\@\#\$\%\^\&\*\(\)\{\}\-])/g }
  961. alias -l deletter {
  962.   var %hintc
  963.   .echo -q $regsub($1-, $nonpunct, $trivchar, %hintc)
  964.   return %hintc
  965. }
  966. alias -l hintrepnum { return $int($calc(($len($trivq.answer) / 100) * $1 + 1)) }
  967. alias -l standard {
  968.   var %in = $replace($2-, $chr(32), $chr(160)), %break = $hintrepnum($1)
  969.   return $replace($left(%in, %break) $+ $iif($getset(status,cross) == 1, $deletter($right(%in, $calc(-1 * %break)))), $chr(160), $chr(32))
  970. }
  971. alias -l scramble {
  972.   tokenize 32 $1-
  973.   var %i = 1, %temp.smbl
  974.   while (%i <= $0) {
  975.     var %word = $eval($+($,%i),2)
  976.     while (%word != $null) { 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)) }
  977.     %temp.smbl = %temp.smbl $+ ;
  978.     inc %i
  979.   }
  980.   return $lower($replace(%temp.smbl,;,$chr(32)))
  981. }
  982. alias -l reverse {
  983.   var %i = $len($1-),%reversed, %space
  984.   while (%i >= 1) {
  985.     if (!%space) { %reversed = %reversed $+ $mid($replace($1-,$chr(32),$chr(160)),%i,1) }
  986.     %space = $false
  987.     if ($chr($mid($1-,%i,1)) == 32) { %space = $true }
  988.     dec %i
  989.   }
  990.   return $replace(%reversed,$chr(160),$chr(32))
  991. }
  992. alias scatter {
  993.   var %hintc = $2-
  994.   if ($thget(temp.scattermask)) var %schint = $thget(temp.scattermask)
  995.   else {
  996.     var %schint
  997.     !.echo -q $regsub(%hintc,$nonpunct,@,%schint)
  998.   }
  999.   var %rnum = $int($calc(($regex(%schint,/@/g) / 100) * (100 - $1)))
  1000.   while (%rnum >= 0) {
  1001.     if ($regex(%schint,/(@)/g)) !.echo -q $regsub(%hintc,/(?<=^.{ $+ $calc($regml($rand(1,$regml(0))).pos - 1) $+ })./,@, %hintc)
  1002.     dec %rnum
  1003.   }
  1004.   thset temp.scattermask %hintc
  1005.   return $replace(%hintc,@,$trivchar)
  1006. }
  1007. alias plot {
  1008.   if ($1 >= 100) { return $2- }
  1009.   var %hintc, %i = 1, %j = 0, %rnum = $int($calc(($regsub($2-,$nonpunct,@,%hintc) / 100) * $1))
  1010.   while (%i <= %rnum) {
  1011.     if ($regex(%hintc, /(?:^|\s|\xA0)[^\s\xA0@]{ $+ %j $+ }(@)/g) == 1) { inc %j }
  1012.     %hintc = $+($left(%hintc,$calc($regml(1).pos - 1)), $mid($2-,$regml(1).pos,1),$right(%hintc,$calc($regml(1).pos * -1)))
  1013.     inc %i
  1014.   }
  1015.   return $replace(%hintc,@,$trivchar)
  1016. }
  1017. alias startandrandom {
  1018.   if ($1 > 0) return $replace($hget(hints,$1),@,$trivchar)
  1019.   if ($hget(hints)) hfree hints
  1020.   var %hintc = $2-, %onhint = 10, %f
  1021.   while (%hintc) {
  1022.     var %w = $gettok(%hintc,1,32), %rt = $regsub(%w,$nonpunct,@,%f), %hintc = $gettok(%hintc,2-,32), %k = 1
  1023.     while (%k <= %onhint) {
  1024.       hadd -m hints %k $hget(hints,%k) %f
  1025.       if ($regex(%w,$nonpunct) > 1) !.echo -q $regsub(%w, /(?<=^.{ $+ $iif(%k == 1, 0, $calc($regml($rand(1,$regml(0))).pos - 1)) $+ })(.)/,@, %w) $regsub(%f, /(?<=^.{ $+ $calc($regml(1).pos - 1) $+ })./,$regml(1), %f)
  1026.       inc %k
  1027.     }
  1028.   }
  1029. }
  1030.  
  1031. ;########################################################
  1032. ;# CHAMP aliases.                                       #
  1033. ;########################################################
  1034. alias -l trivia.newchamp {
  1035.   .rename $scoresfil $asctime(yymmddhhmmss) $+ .bak
  1036.   setset Champ $calc($setini(Champ, 0) + 1) $nick
  1037.   tsay $msg.trivia.victory($nick)
  1038.   trivia.flush
  1039.   haltdef
  1040. }
  1041. ;########################################################
  1042. ;# HALL Of FAME, RANKING.                               #
  1043. ;########################################################
  1044. alias sort {
  1045.   if (!$exists($scoresfil)) { return }
  1046.   window -h $twin
  1047.   filter -fwcgut $+ $iif($1 != time,e) [ $$gttok($iif($2 != total,$2) $+ $1) $asc(;) ] $scoresfil $twin $iif(($2) && ($2 != total),/^ $+ $str([^;]*;,$calc($$gttok($2)-1)) $+ $eval($ $+ get. $+ $2,2) $+ ;.* $+ /,/.*/)
  1048. }
  1049. alias -l msg.trivia.topx {
  1050.   if ($calc($3 - $2) > 20) { return $msg.trivia.error.topx }
  1051.   sort $1 $unit.default
  1052.   var %temp.by = $gttok($1), %i = $2, %temp.ten = $e2(Places) $e1($2) $e2(to) $e1($3) $+ $e2(:)
  1053.   while (%i <= $3) {
  1054.     var %temp.ten = %temp.ten $e1($iif($hof(%i,1),$hof(%i,1) - $hof(%i,%temp.by)) $+ $e2(;)
  1055.     inc %i
  1056.   }
  1057.   return %temp.ten
  1058. }
  1059. alias -l msg.trivia.topstats {
  1060.   sort $1 $iif($2 != total, $2)
  1061.   var %temp.by = $gttok($iif($2 != total, $2) $+ $1), %temp.ten = $e1($hof(1,1)) $e2(has the best $1 of) $e1($hof(1,%temp.by)) $iif($2 != total,$e2( for the $2 )) $+ $e2(;)
  1062.   var %i = 2
  1063.   while (%i <= $iif(%topnum,%topnum,10)) {
  1064.     var %temp.ten = %temp.ten $iif($hof(%i,1),$e1($hof(%i,1)) $e2(-) $e1($hof(%i,%temp.by)) $+ $e2(;))
  1065.     inc %i
  1066.   }
  1067.   return $iif(!$hof(1,1),$e2(No elements in the hall of fame.),%temp.ten)
  1068. }
  1069. alias topnum { set %topnum $1 }
  1070. alias -l twin { return @trivia $+ $scoresfil }
  1071. alias -l getrank {
  1072.   sort score $iif($2 != total, $2)
  1073.   set -u0 %getrank $fline($twin,$+($1,;*),1)
  1074.   if (!%getrank) { return $hof.size }
  1075.   var %score = $getvar($hof(%getrank,1),$iif($2 != total, $2) $+ score)
  1076.   while (%score == $getvar($hof(%getrank,1),$iif($2 != total, $2) $+ score)) { dec %getrank }
  1077.   inc %getrank
  1078.   if (%getrank != 1) {
  1079.     set -u0 %getnextrank $calc(%getrank - 1)
  1080.     set -u0 %getnextrankuser $hof(%getnextrank,1)
  1081.     set -u0 %getnextrankat $user.score(%getnextrankuser,$2)
  1082.   }
  1083.   unset %uprank
  1084.   if (!$3) { return %getrank }
  1085.   set -u0 %uprank 1
  1086.   var %upscore = $calc(%score + $3)
  1087.   while ((%upscore >= $getvar($hof($calc(%getrank - %uprank),1),$iif($2 != total, $2) $+ score)) && (%getrank >= %uprank)) {
  1088.     inc %uprank
  1089.   }
  1090.   dec %uprank
  1091.   return %getrank
  1092. }
  1093. alias mrankon {
  1094.   if (!$getset(trivia, ranks)) { return $false }
  1095.   if ($setini(ranks,0) == 0) { return $false }
  1096.   else { return $true }
  1097. }
  1098. alias getmrank {
  1099.   if (!$getset(trivia, ranks)) { return }
  1100.   var %score = $user.score($1,$2), %i = $setini(ranks,0), %te = 0, %temax = 0
  1101.   while (%i >= 1) {
  1102.     %te = $setini(ranks,%i)
  1103.     if ((%score >= %te) && (%te >= %temax)) { %temax = %te }
  1104.     dec %i
  1105.   }
  1106.   return $getset(ranks,%temax)
  1107. }
  1108. alias getnextmrank {
  1109.   var %next.rank = $getnextmrankat($1)
  1110.   return $iif(%next.rank, $getset(ranks,%next.rank), None)
  1111. }
  1112. alias getnextmrankat {
  1113.   if (!$getset(trivia, ranks)) { return }
  1114.   var %score = $1, %i = $setini(ranks,0), %te = 0, %temax = 0, %by = 0
  1115.   while (%i >= 1) {
  1116.     %te = $setini(ranks,%i)
  1117.     if ((%score <= %te) && ((!%by) || ($calc(%score + %by) >= %te))) {
  1118.       %temax = %te
  1119.       %by = $calc(%te - %score)
  1120.     }
  1121.     dec %i
  1122.   }
  1123.   return %temax
  1124. }
  1125.  
  1126. alias -l recordstat {
  1127.   sort $1 $unit.default
  1128.   return $hof(1,1)
  1129. }
  1130. ;########################################################
  1131. ;# TIME SCORE DURATIONS AND GENERAL ALIASES             #
  1132. ;# All time alias just return the number of that time   #
  1133. ;# unit which have occurred since Jan 1st, 1970         #
  1134. ;# Do not alter the unit.tokens. It will break the bot. #
  1135. ;########################################################
  1136. alias unit.tokens { return year.month.week.day }
  1137. alias get.day { return $int($calc(($ctime - $timezone) / 86400)) }
  1138. alias get.week { return $int($calc((($get.day - 4) - $iif($getset(status,monday),0,1)) / 7)) }
  1139. alias get.month { return $calc(($get.year * 12) + $asctime($ctime,mm)) }
  1140. alias get.year { return $calc($asctime($ctime,yyyy)  - 1970) }
  1141. alias process.scores.time {
  1142.   var %i = 1
  1143.   while (%i <= 4) {
  1144.     var %unit = $gettok($unit.tokens,%i,$asc(.))
  1145.     var %uvalue = $eval($ $+ get. $+ %unit,2)
  1146.     if ((%unit) && (%uvalue)) {
  1147.       if ($getvar($1,%unit) != %uvalue) {
  1148.         setvar $1 %unit %uvalue
  1149.         setvar $1 %unit $+ score $calc(0 + $2)
  1150.         setvar $1 %unit $+ streak $calc(0 + $3)
  1151.         setvar $1 %unit $+ time $ifd($4,9999)
  1152.         setvar $1 %unit $+ wpm $calc(0 + $5)
  1153.       }
  1154.       else {
  1155.         if ($2) setvar $1 %unit $+ score $calc($getvar($1,%unit $+ score) + $2)
  1156.         if ($3 > $getvar($1,%unit $+ streak)) setvar $1 %unit $+ streak $3
  1157.         if ($4 < $getvar($1,%unit $+ time)) setvar $1 %unit $+ time $4
  1158.         if ($5 > $getvar($1,%unit $+ wpm)) setvar $1 %unit $+ wpm $5
  1159.       }
  1160.     }
  1161.     inc %i
  1162.   }
  1163. }
  1164. ;########################################################
  1165. ;# VAR MANIPULATIONS.                                   #
  1166. ;########################################################
  1167. alias setvar {
  1168.   if ($3 == $null) return
  1169.   var %backburner = $read($tempfil, wnt, $1 $+ ;*)
  1170.   if (%backburner != $null) mergeentry $tempfil $scoresfil $1
  1171.   var %newline = $readvar($1)
  1172.   if (!%newline) { %newline = $1 }
  1173.   if ($numtok(%newline,59) < $numtok($tvartoks, $asc(.))) {
  1174.     %newline = %newline $+ $str(;0,$calc($numtok($tvartoks, $asc(.)) - $numtok(%newline,59)))
  1175.     if ($gettok(%newline,9,59) == 0) { %newline = $puttok(%newline,trivia,9,59) }
  1176.     if (($gettok(%newline,8,59) == 0) && ($address($1,5))) { %newline = $puttok(%newline,$address($1,5),8,59) }
  1177.     if ($gettok(%newline,6,59) == 0) { %newline = $puttok(%newline,$date,6,59) }
  1178.     if ($gettok(%newline,3,59) == 0) { %newline = $puttok(%newline,9999,3,59) }
  1179.   }
  1180.   %newline = $puttok(%newline,$3-,$gttok($2),59)
  1181.   write $iif($readn,-l $+ $readn) $scoresfil %newline
  1182.   set -u3 %cache.nick $1
  1183.   set -u3 %cache.line %newline
  1184. }
  1185. alias realvar { return $getvar($1,$2) }
  1186. alias readvar {
  1187.   var %scoreline = $read($scoresfil, wnt, $1 $+ ;*)
  1188.   if (!%scoreline) { return }
  1189.   if (!$2) { return %scoreline }
  1190.   else { return $gettok(%scoreline, $gttok($2), 59) }
  1191. }
  1192. alias getvar {
  1193.   if ($1 == %cache.nick) { var %scoreline = %cache.line }
  1194.   else {
  1195.     var %scoreline = $read($scoresfil, wnt, $1 $+ ;*)
  1196.     if (!%scoreline) { return }
  1197.     set -u3 %cache.nick $1
  1198.     set -u3 %cache.line %scoreline
  1199.   }
  1200.   if (!$2) { return %scoreline }
  1201.   else { return $gettok(%scoreline, $gttok($2), 59) }
  1202. }
  1203. alias -l gttok { return $findtok($tvartoks, $1, 1, $asc(.)) }
  1204. alias -l tvartoks { return name.score.time.streak.wpm.lastwin.answered.address.password.admin.block.day.dayscore.daystreak.daytime.daywpm.week.weekscore.weekstreak.weektime.weekwpm.month.monthscore.monthstreak.monthtime.monthwpm.year.yearscore.yearstreak.yeartime.yearwpm }
  1205. alias -l varfil { return $iif($2 == $null, $iif($1 == 0, $lines($scoresfil), $gettok($read($scoresfil, $1),1,59)), $gettok($read($scoresfil, $1),$2,59)) }
  1206. alias -l trivini { return $iif($exists(trivia.ini),trivia.ini,$iif($exists(" $+ $scriptdir $+ \ $+ trivia.ini $+ ")," $+ $scriptdir $+ \ $+ trivia.ini $+ ",trivia.ini)) }
  1207. alias -l setset {
  1208.   if ($3- != $null) { writeini -n $trivini $1 $2 $3- }
  1209.   else { remini -n $trivini $$1 $2 }
  1210. }
  1211. alias getset { return $readini($trivini, n, $1, $2) }
  1212. alias -l setini { return $iif($2 != $null, $ini($trivini, $1, $2), $ini($trivini, $1)) }
  1213. alias -l thuser { return $thget($eval(Temp. $+ $1 $+ . $+ $nick,1)) }
  1214. alias -l thuset { thset $eval(Temp. $+ $1 $+ . $+ $nick,1) $2- }
  1215. alias -l thset { if ($hget(Trivia $+ $idenn)) hadd Trivia $+ $idenn $1- }
  1216. alias thget { return $hget(Trivia $+ $idenn, $1) }
  1217. ;########################################################
  1218. ;# Color aliases.                                       #
  1219. ;########################################################
  1220. alias -l colorcode { return $gettok(colors off.white.black.blue.green.lightred.brown.purple.orange.yellow.lightgreen.cyan.lightcyan.lightblue.pink.grey.lightgrey,$calc($1 + 1),$asc(.)) }
  1221. alias -l fixer { return $base($1,10,10,2) }
  1222. alias varcolors {
  1223.   unset %c1 %c1o %c2 %c2o
  1224.   if ((!$getset(color,on)) || (!$tc(1)) || (!$tc(2))) { return }
  1225.   %c1o = $iif($tc(1).b,$chr(2)) $+ $iif($tc(1).u,$chr(31)) $+ $chr(3)
  1226.   %c2o = $iif($tc(2).b,$chr(2)) $+ $iif($tc(2).u,$chr(31)) $+ $chr(3)
  1227.   %c1 = %c1o $+ $fixer($calc($tc(1) - 1)) $+ $iif(($tc(3)) && ($getset(color,bon)), $chr(44) $+ $fixer($calc($tc(3) - 1)))
  1228.   %c2 = %c2o $+ $fixer($calc($tc(2) - 1)) $+ $iif(($tc(4)) && ($getset(color,bon)), $chr(44) $+ $fixer($calc($tc(4) - 1)))
  1229. }
  1230. alias rdc {
  1231.   if ($getset(status,nocolorshort) == 1) return $1
  1232.   var %a
  1233.   !.echo -q $regsub($1,/(?<=\x03|\x03\d\d\x2C)(\d)(?!\d)/g,0\1, %a)
  1234.   while ($regsub(%a, /(?<=\x03\d\d\x2C\d\d|\x03\d\d\x03|\x03)([\x02\x1F\x16\s\xA0]+)(\x03(?:\d\d(?:\x2C\d\d)?)?)/g,\2\1, %a)) { }
  1235.   !.echo -q $regsub(%a, /(\x02)([\x1F\x16\s\xA0]*)\1/g,\2, %a) $&
  1236.     $regsub(%a, /(\x1F)([\x02\x16\s\xA0]*)\1/g,\2, %a) $&
  1237.     $regsub(%a, /(\x16)([\x02\x1F\s\xA0]*)\1/g,\2, %a) $&
  1238.     $regsub(%a, /(?:\x03(?:\d\d(?:\x2C\d\d)?)?)+(\x03(?:(?!\d)|\d\d\x2C\d\d))/g,\1, %a) $&
  1239.     $regsub(%a, /(?:\x03\d\d)(\x2C\d\d)(?:\x03\d\d)*(\x03\d\d)/g,\2\1, %a) $&
  1240.     $regsub(%a, /(?<=\x03\d\d)(\x2C\d\d)([^\x03]+\x03\d\d)\1/g,\1\2, %a)
  1241.   while ($regsub(%a,/(\x03\d\d)((\x2C\d\d)?[^\x03]+)\1(?!\x2c\d)/g,\1\2, %a)) { }
  1242.   !.echo -q $regsub(%a, /^\x03(?!\d)|(\x03(\d\d(\x2C\d\d)?)?|\x02|\x16|\x1F)+$/g,,%a) $&
  1243.     $regsub(%a, /(?<=\x03|\x03\d\d\x2C)0(\d)(?!\d)/g,\1, %a)
  1244.   return %a
  1245. }
  1246. ;########################################################
  1247. ;# AWARD setups.                                        #
  1248. ;########################################################
  1249. alias -l msg.trivia.award { return %c2 $+ $replace($eval($1,2),^, %c2o $+ $e1($2) $+ %c2,*, %c2o $+ $e1($nick) $+ %c2) $+ %c2o }
  1250. alias -l award {
  1251.   if ($getset(status,noawards)) { return }
  1252.   var %i = 1, %award = $calc($findtok($award.on.tok, $1, 1, $asc(.)) - 1), %trigger = $2-
  1253.   while ($aw(%i)) {
  1254.     tokenize 32 $aw(%i)
  1255.     if (%award == $1) {
  1256.       if (($2 == 0) || (($2 == 1) && (%trigger == $4)) || (($2 == 2) && (%trigger isnum $4 - $5)) || (($2 == 3) && (%trigger >= $4)) || (($2 == 4) && (%trigger <= $4)) || (($2 == 5) && (%trigger == $getrank($nick,$unit.default))) || (($2 == 6) && ($rand(1,$4) <= $5)) || (($2 == 7) && ($4 $+ * iswm %trigger)) || (($2 == 8) && (* $+ $4 iswm %trigger))) { $award.act($3,%trigger,$6-) }
  1257.     }
  1258.     inc %i
  1259.   }
  1260. }
  1261. alias award.act {
  1262.   var %do
  1263.   if ($1 == 1) { var %do = tact $rdc($msg.trivia.award($3,$2)) }
  1264.   if (($1 == 2) || ($1 == 5)) { var %do = tsay $rdc($msg.trivia.award($3,$2)) }
  1265.   if ($1 == 3) { var %do = notice $nick $rdc($msg.trivia.award($3,$2)) }
  1266.   if ($1 == 4) { var %do = trivia.credit $nick $3 }
  1267.   if ($1 == 5) { var %do = tban $nick }
  1268.   if ($1 == 6) { var %do = $eval($replace($3-,*,$2),3) }
  1269.   .timer 1 0 schan $chan %do
  1270. }
  1271. alias schan {
  1272.   set -u3 %ident $1
  1273.   $2-
  1274. }
  1275. alias award.on.tok { return Null.Score.Row.Time.WPM.Join.Question.Uprank.Promotion.Answered.RoundStart.RoundStop.Command.NoAnswer.Hint.HTMLUpdate }
  1276. alias award.val.tok { return Always.Exactly.Between.At Least.At Most.Ranked.Random.Begins.Ends }
  1277. alias award.do.tok { return Null.Describe.Msg.Notice.Give Points.Ban.Special }
  1278. ;########################################################
  1279. ;# MESSAGING.                                           #
  1280. ;########################################################
  1281. alias -l inform {
  1282.   if ((!$1) || (!$server)) { return }
  1283.   if (!%respond) {
  1284.     var %respondlevel = $getset(status,respondlevel)
  1285.     set -u2 %respond .notice $nick
  1286.     if (%respondlevel == 2) { }
  1287.     if (%respondlevel == 3) { set -u2 %respond msg $iden }
  1288.     if (%respondlevel == 4) { set -u2 %respond msg $nick }
  1289.     if (%respondlevel == 5) { set -u2 %respond describe $chan }
  1290.   }
  1291.   $iif($scid(%cid.force),scid %cid.force) $iif($nick == $me, .timer -m 1 $calc($timer(0) * 100)) %respond $check.auto.strip($rdc($1-))
  1292. }
  1293. alias here { set %cid.force $cid }
  1294. alias -l tsay { if (($1) && ($server) && ($me ison $iden)) { $iif($nick == $me, .timer -m 1 $calc($timer(0) * 100)) msg $iden $check.auto.strip($rdc($1-)) } }
  1295. alias -l tact { if (($1) && ($server) && ($me ison $iden)) describe $iden $check.auto.strip($rdc($1-)) }
  1296. alias -l check.auto.strip { return $iif(c isincs $gettok($chan($iden).mode,1,32), $strip($1-), $1-) }
  1297. ;########################################################
  1298. ;# Direct basic processing, for special functions.      #
  1299. ;########################################################
  1300. alias -l do.ping {
  1301.   if ($eval(% $+ pingantispam. $+ $nick,2)) return
  1302.   ctcp $nick ping
  1303.   set -u120 % $+ ping. $+ $nick $ticks
  1304.   set -u120 % $+ pingchan. $+ $nick $chan
  1305.   set -u120 % $+ pingcid. $+ $nick $cid
  1306. }
  1307. alias -l trivia.report {
  1308.   inform $msg.trivia.thanks
  1309.   write " $+ $triv(dir) $+ / $+ $iif($1 == 29, $triv(additions), $triv(report)) $+ " $nick $adate $time $2-
  1310. }
  1311. ;########################################################
  1312. ;# FRIENDS/BANNED.                                      #
  1313. ;########################################################
  1314. alias addressize {
  1315.   if (*!*@* iswm $1) { return $1 }
  1316.   return $1 $+ !*@*
  1317. }
  1318. alias -l is.friend {
  1319.   var %i = 1
  1320.   while ($getset(friend, %i)) {
  1321.     if ($addressize($getset(friend, %i)) iswm $address($ifd($1,$nick),5)) { return %i }
  1322.     inc %i
  1323.   }
  1324. }
  1325. alias -l is.banned {
  1326.   var %i = 1
  1327.   while ($getset(banned,%i)) {
  1328.     if ($addressize($getset(banned, %i)) iswm $address($ifd($1,$nick),5)) { return %i }
  1329.     inc %i
  1330.   }
  1331. }
  1332. alias -l trivia.banned {
  1333.   var %banned = $is.banned($1)
  1334.   if (%banned) {
  1335.     if (!$1) { inform $msg.trivia.banned }
  1336.     return %banned
  1337.   }
  1338. }
  1339. alias -l ban.size { return $calc(1 + $setini(banned, 0)) }
  1340. alias -l tban { if (!$trivia.banned($$1)) { setset banned $ban.size $1 } }
  1341. alias -l tunban {
  1342.   var %i = $trivia.banned($$1)
  1343.   while ($getset(banned, $calc(%i + 1))) {
  1344.     setset banned %i $getset(banned, $calc(%i + 1))
  1345.     inc %i
  1346.   }
  1347.   setset banned %i
  1348. }
  1349. ;########################################################
  1350. ;# CONVERTORS #
  1351. ;########################################################
  1352. alias convertscores {
  1353.   var %ini = $iif($1,$1,triviascores.ini)
  1354.   if (!$exists(%ini)) { return }
  1355.   var %i = $ini(%ini,0)
  1356.   echo 4 -a Converting %i scores into Trivia 3.12+ format.
  1357.   while (%i > 0) {
  1358.     var %m = $ini(%ini,%i)
  1359.     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))
  1360.     dec %i
  1361.   }
  1362.   .rename %ini %ini $+ .bak
  1363. }
  1364. ;########################################################
  1365. ;# MISC.                                                #
  1366. ;########################################################
  1367. alias timealias {
  1368.   var %ticks = $ticks
  1369.   echo -a ... $eval($ $+ $1,2) ... $calc(($ticks - %ticks) / 1000) ... $1
  1370. }
  1371. alias timealias2 {
  1372.   var %ticks = $ticks, %i = 1, %result
  1373.   while (%i <= $2) {
  1374.     var %result = $eval($ $+ $eval($1-,2),2)
  1375.     inc %i
  1376.   }
  1377.   return $calc(($ticks - %ticks) / (1000 * $2))
  1378. }
  1379. alias iden { return $iif($chan, $chan, $iif(%ident, %ident, $tchan(1))) }
  1380. alias idenn { return $iden $+ . $+ $ifd($network,irc) }
  1381. alias -l deleteplayer { if ($getvar($1)) { write -dl $+ $readn $scoresfil } }
  1382. alias -l hof.size { return $line($twin,0) }
  1383. alias -l hof { return $gettok($line($twin,$1),$2,59) }
  1384. alias -l scoresfil { return $nopath($ifd($thget(scores),$ifd($tchan($trivchan, 4), TriviaScores.fil))) }
  1385. alias -l user.score { return $getvar($1,$unit.prefix($2) $+ score) }
  1386. alias -l trivia.on { if (($timer(q $+ $idenn)) || ($timer(end $+ $idenn))) { return $true } }
  1387. alias -l question.on { if ($timer(end $+ $idenn)) { return $true } }
  1388. alias -l tokq { return $thget(tokq) }
  1389. alias -l tok { return $thget(tok $+ $1) }
  1390. alias -l question.time { return $calc(($ticks - $thget(Start)) / 1000) }
  1391. alias -l te { return $getset(team, $1 $+ $prop) }
  1392. alias -l teamscore { return $thget(Score $+ $1) }
  1393. alias -l max.hinted { return $iif($calc($thget(Temp.Hints) + 0) > $calc($thuser(Hint) + 0), $thget(Temp.Hints), $thuser(hint)) }
  1394. alias -l isteam { return $thget(Team. $+ $1) }
  1395. alias -l chkadate { return $iif($getset(status,adate), $+($gettok($1,2,$asc(/)),/,$gettok($1,1,$asc(/)),/,$gettok($1,3,$asc(/))), $1) }
  1396. alias -l team { if ($thget(team) == 1) { return $true } }
  1397. alias -l tempini { return triviascbb.ini }
  1398. alias -l lag { return $iif($thget(lag $+ $1), $thget(lag $+ $1), $getset(lag,$1)) }
  1399. alias -l slag { return $getset(lag,$1) }
  1400. alias -l tc { return $getset(color, $1 $+ $iif($prop == b, -bold) $+ $iif($prop == u, -underline)) }
  1401. alias -l triv { return $getset(trivia, $1) }
  1402. alias -l aw { return $getset(award, $1) }
  1403. ;########################################################
  1404. ;# MESSAGE COLOR CODE SETTING ALIASES.                  #
  1405. ;########################################################
  1406. alias e1 { return %c1 $+ $1- $+ %c1o }
  1407. alias e2 { return %c2 $+ $trivtran($1-) $+ %c2o }
  1408. alias trivtran {
  1409.   if (!$triv(translate)) return $1-
  1410.   if ($isfile($transfile)) {
  1411.     var %tran = $read($transfile, wtn, $1- $+ ::=*)
  1412.     if ($regex(%tran, /.*::=(.*))) { return $regml(1) }
  1413.     if (#* iswm $read($transfile,n,1)) var %nowrite 1
  1414.   }
  1415.   if (!%nowrite) write $transfile $1- $+ ::= $+ $1-
  1416.   return $1-
  1417. }
  1418. alias untrans {
  1419.   if (!$triv(translate)) return $1-
  1420.   if ($isfile($transfile)) {
  1421.     var %tran = $read($transfile, wtn, *::= $+ $1-)
  1422.     if ($regex(%tran, /(.*)::=.*)) { return $regml(1) }
  1423.   }
  1424.   return $1-
  1425. }
  1426. alias tranord { return $1 $+ $trivtran($remove($ord($1),$1)) }
  1427. alias transfile { return " $+ $triv(translate) $+ " }
  1428. ;########################################################
  1429. ;# MESSAGES.                                            #
  1430. ;########################################################
  1431. alias -l msg.ping.reply { return $e1($nick) $+ $e2($chr(44) your ping is) $e1($calc(($ticks - % [ $+ ping. [ $+ [ $nick ] ] ] ) / 1000)) $e2(secs.) }
  1432. alias -l msg.answer.correct { return $iif($1,$msg.answer.correct2($2,$3,$4),$e2(Winner:) $e1($getmrank($nick) $nick) $iif(!$getset(status,shownone),$e2(Answer:) $e1($trivq.answer)) $iif(!$getset(hide,time),$e2(Time:) $e1($thget(Time))) $iif(!$getset(hide,streak),$e2(Streak:) $e1($getset(Var $+ $idenn, Row))) $iif(!$getset(hide,score),$e2(Points:) $e1($user.score($nick))) $iif(!$getset(hide,wpm),$e2(WPM:) $e1($int($2))) $iif(!$getset(hide,score),$e2(Rank:) $e1($tranord($3)) $iif($4,$e2(Previously:) $e1($tranord($4))))) }
  1433. alias -l msg.answer.correct2 { return $e1($getmrank($nick) $nick) $e2(got the answer) $+ $iif(!$getset(status,shownone),$e2(:) $e1($trivq.answer),$e2(.)) $iif(!$getset(hide,time),$e2(in) $e1($thget(Time)) $e2(seconds.)) $iif(!$getset(hide,score),$e2(Points:) $e1($user.score($nick))) $e2(Rank:) $e1($tranord($2)) }
  1434. alias -l msg.answer.timeout { return $e2(Time's up! The answer was:) $e1($trivq.answer) }
  1435. alias -l msg.answer.timeout.total { return $e2(Time's up! Remaining answers were:) $e1($left($gettotalremain,850)) }
  1436. alias -l msg.answer.timeout.pick { return $e2(Time's up! The answer was:) $e1($left($get.picklist,850)) }
  1437. alias -l msg.answer.timeout2 { return $e2(Time's up! Nobody got the answer!) }
  1438. alias -l msg.question.multi { return $iif($1, $e1($1) $+ $e2(:)) $e2(Multiple Choice:) $e1($right($tok(1),-7)) $+ $e2(;) $e1($get.multianswers) }
  1439. alias -l msg.question.total { return $iif($1, $e1($1) $+ $e2(:)) $e2(Give all correct responses:) $e1($right($tok(1),-7)) }
  1440. alias -l msg.question.points { return $iif($1, $e1($1) $+ $e2(:)) $e2(For) $e1($ifd($thget(temp.points),0)) $e2(point $+ $iif($thget(temp.points) != 1,s) $+ :) $e1($get.question($2-)) }
  1441. alias -l msg.question.scramble { return $iif($1, $e1($1) $+ $e2(:)) $iif($getset(status, sayscramble),$e2(Unscramble the following:)) $iif($2,$e1($2) $+ $e2(:)) $e1($scramble($tok(2)) $+ ?) }
  1442. alias -l msg.question.standard { return $iif($1, $e1($1) $+ $e2(:)) $e1($get.question($ifd($2,$tok(1)))) }
  1443. alias -l msg.question.answer { return $e2(The answer to the last question was $+ :) $e1($thget(answer)) }
  1444. alias -l msg.trivia.stats { return $iif($getvar($1,$2 $+ score), $e1($getmrank($1,$iif(!$2,total,$2)) $1) $+ $e2(:) $iif(!$getset(hide,score),$e2(Rank:) $e1($tranord($getrank($1,$2))) $e2(out of) $e1($hof.size) $+ $e2(.) $e2(Current wins:) $e1($getvar($1,$2 $+ score)) $+ $e2(.)) $iif(!$getset(hide,streak),$e2(Best streak:) $e1($getvar($1,$2 $+ streak)) $+ $e2(.)) $iif(!$getset(hide,time),$e2(Best time:) $e1($getvar($1,$2 $+ time)) $e2(secs.)) $iif(!$getset(hide,wpm),$e2(WPM:) $e1($getvar($1,$2 $+ wpm)) $+ $e2(.)) $iif($getvar($1,lastwin), $e2(Last Win:) $e1($chkadate($getvar($1, lastwin))) $+ $e2(.)), $e2(No such user exists.)) }
  1445. alias -l msg.trivia.rank { return $iif($user.score($1), $e1($getmrank($1) $1) $+ $e2(:) $iif(!$getset(hide,score),$e2(Current wins:) $e1($user.score($1)) $+ $e2(.)) $iif(($mrankon) && ($getnextmrankat($user.score($1)) != 0),$e2(Next rank:) $e1($getnextmrank($user.score($1))) $iif(!$getset(hide,score),$e2(after:) $e1($calc($getnextmrankat($user.score($1)) - $user.score($1))) $e2(more points.))) $iif(!$getset(hide,score),$e2(Rank:) $e1($tranord($getrank($1,$unit.default))) $e2(out of) $e1($hof.size) $+ $e2(.) $iif(%getrank != 1,$e1($calc(%getnextrankat - $user.score($1))) $e2(points below) $e1(%getnextrankuser) $+ $e2(.))),$e2(Error.)) }
  1446. 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.) $e1($numl) $e2(questions. Trivia is:) $e1($trivia.onoff) $+ $e2(.) $iif($trivia.on, $iif($question.on,$e2(Time left:) $e1($calc($thget(lagtimedout) - $question.time))) $e2(Question:) $e1($thget(Current)) $+ $e2(/) $+ $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) }
  1447. alias -l msg.trivia.enabled { return $e2(Enabling the trivia. Have an op type:) $e1($pre $+ $gtok(2)) $e2(to disable the bot.) }
  1448. alias -l msg.trivia.disabled { return $e2(Disabling the trivia. Have an op type:) $e1($pre $+ $gtok(3)) $e2(to enable the bot.) }
  1449. 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!) }
  1450. alias -l msg.trivia.unactive { return $e2(The game has been disabled due to inactivity.) }
  1451. alias -l msg.trivia.emptyoff { return $e2(The game has been disabled due lack of players.) }
  1452. alias -l msg.trivia.pause { return $e2(Trivia paused.) $e1($pre $+ $gtok(8)) $e2(to resume.) }
  1453. alias -l msg.trivia.resume { return $e2(Trivia resumed.) }
  1454. alias -l msg.trivia.started { return $e2(Starting the trivia. Round of) $e1($iif($thget(Max) == Unlimited,$gtok(1,5),$thget(Max))) $e2(questions.) $e1($pre $+ $gtok(6)) $e2(to stop. Total:) $e1($numl) }
  1455. alias -l msg.trivia.stopped { return $e2(Stopping the trivia.) $e1($pre $+ $gtok(5) $iif(!$isdis(1),< $+ $trivtran(number) $+ >)) $e2(to restart.) }
  1456. alias -l msg.trivia.awarded { return $e1($1) $e2(was awarded) $e1($2) $e2(point $+ $iif($2 > 1,s) $+ . Current Wins:) $e1($user.score($1)) }
  1457. alias -l msg.trivia.deducted { return $e1($1) $e2(was deducted) $e1($calc($2 * -1)) $e2(point $+ $iif($2 < -1,s) $+ . Current Wins:) $e1($user.score($1)) }
  1458. alias -l msg.trivia.hof { return $msg.trivia.champ(1) $msg.trivia.topstats(score) }
  1459. alias -l msg.trivia.error.midq { return $e2(Cannot pause while trivia game has a question issued.) }
  1460. alias -l msg.trivia.banned { return $e2(You cannot play $+ $chr(44) you are banned.) }
  1461. alias -l msg.trivia.guessed { return $e2(You already guessed) $e1($1) $e2(times.) }
  1462. alias -l msg.trivia.thanks { return $e2(Thank you for your contribution!) }
  1463. alias -l msg.trivia.totalover { return $e2(All correct responses have been given!) }
  1464. alias -l msg.trivia.version { return $e1($trivia.name $+ $chr(44) v $+ $trivia.version) }
  1465. alias -l msg.trivia.web { return $e2(Get your own copy of) $msg.trivia.version $e2(at) $e1($trivia.web) $e2(.) }
  1466. alias -l msg.trivia.onjoin { return $iif($getset(trivia,onjoin),$get.onjoin($getset(trivia,onjoin)),$e2(Welcome) $e1($getmrank($nick) $nick) $+ $e2($chr(44)) $e1($msg.trivia.version) $e2(is activated. Type ') $+ $e1($pre $+ $gtok(33)) $+ $e2(' for a list of commands or just ') $+ $e1($pre $+ $gtok(5)) $+ $e2(' to start a game!)) }
  1467. alias -l msg.trivia.records { return $iif(!$getset(hide,streak),$e2(Record streak:) $e1($recordstat(streak)) $e2(of) $e1($hof(1,4)) $+ $e2(.)) $iif(!$getset(hide,time),$e2(Record time:) $e1($recordstat(time)) $e2(of) $e1($hof(1,3)) $+ $e2(.)) $iif(!$getset(hide,wpm),$e2(Record wpm:) $e1($recordstat(WPM)) $e2(of) $e1($hof(1,5)) $+ $e2(.)) }
  1468. alias -l msg.trivia.themes { return $e2(Current themes are:) $e1($get.themes) }
  1469. alias -l msg.trivia.champ { return $iif($getset(status,champ), $e2(Current champ:) $e1($getset(Champ, $ini($trivini, Champ, 0))) $+ $e2(. $get.champ($1))) }
  1470. 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)) }
  1471. alias -l msg.trivia.showteam { return $iif($get.showteams($1), $e2(Current members of) $e1($te($1)) $e2(are:) $e1($get.showteams($1))) }
  1472. alias -l msg.trivia.hintpaused { return $e2(You requested a $pre $+ $gtok(39) less than) $e1($triv(hintpause)) $e2(seconds ago.) }
  1473. alias -l msg.trivia.roundscores { return $e2(Current Round:) $e1($get.roundscores) }
  1474. alias -l msg.trivia.banlist { return $e2(The following people are banned:) $e1($get.banlist) }
  1475. alias -l msg.team.start { return $e2(Team Trivia: ') $+ $e1($pre $+ $gtok(34) 1) $+ $e2(' or ') $+ $e1($pre $+ $gtok(34) 2) $+ $iif($getset(team,4-team),$e2(' or ') $+ $e1($pre $+ $gtok(34) 3) $+ $e2(' or ') $+ $e1($pre $+ $gtok(34) 4)) $+ $e2(' to add to a team.) }
  1476. alias -l msg.team.add { return $e2(Team:) $e1($1) $e2(has a new member:) $e1($2) }
  1477. alias -l msg.team.joinover { return $e2(I am sorry no more people can join/change at this time.) }
  1478. alias -l msg.team.toomany { return $e2(That team currently has enough players.) }
  1479. alias -l msg.team.joinbefore { return $e2(Teams are no longer accepting player.) }
  1480. alias -l msg.team.alreadyon { return $e2(You are already on that team.) }
  1481. 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)) }
  1482. 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.) }
  1483. 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(!) }
  1484. alias -l msg.hint.words { return $e2(Here's $iif($getset(status,sayhintnum),your $tranord($ifd($thuser(hint),$thget(Temp.Hints))), a)  hint $+ $chr(44)) $e2(there $iif($$get.hint(words) == 1,is,are)) $e1($$get.hint(words)) $e2(word $+ $iif($$get.hint(words) != 1,s) in the answer.) }
  1485. alias -l msg.hint.vowels { return $e2(Here's $iif($getset(status,sayhintnum),your $tranord($ifd($thuser(hint),$thget(Temp.Hints))), a)  hint $+ $chr(44)) $e2(the vowels are:) $e1($$get.hint(vowels)) }
  1486. alias -l msg.hint.last { return $e2(Here's $iif($getset(status,sayhintnum),your $tranord($ifd($thuser(hint),$thget(Temp.Hints))), a)  hint $+ $chr(44)) $e2(the last character in the answer is:) $e1($$get.hint(last)) }
  1487. alias -l msg.hint.space { return $e2(Here's $iif($getset(status,sayhintnum),your $tranord($ifd($thuser(hint),$thget(Temp.Hints))), a)  hint $+ $chr(44)) $e2(answer space:) $e1($$get.hint(space)) }
  1488. alias -l msg.hint.scramble { return $e2(Here's $iif($getset(status,sayhintnum),your $tranord($ifd($thuser(hint),$thget(Temp.Hints))), a)  hint $+ $chr(44)) $e2(scrambled:) $e1($$get.hint(scramble)) }
  1489. alias -l msg.hint.hint { return $e2(Here's $iif($getset(status,sayhintnum),your $tranord($ifd($thuser(hint),$thget(Temp.Hints))), a)  hint $+ $chr(44)) $e1($$get.hint(hint,$1)) }
  1490. alias -l msg.features.built { return $e2(Trivia scores updated:) $e1($1) $e2(!) }
  1491. alias -l msg.trivia.hof.error { return $e1($pre $+ $gtok(14) < $+ $gtok(1,3) $+ $chr(124) $+ $gtok(2,3) $+ $chr(124) $+ $gtok(3,3) $+ $chr(124) $+ $gtok(4,3) $+ > < $+ $gtok(1,4) $+ $chr(124) $+ $gtok(2,4) $+ $chr(124) $+ $gtok(3,4) $+ $chr(124) $+ $gtok(4,4) $+ $chr(124) $+ $gtok(5,4) $+ >) $e2(to display the hall of fame table of your choice.) }
  1492. alias -l msg.trivia.stats.error { return $e1($pre $+ $gtok(11) < $+ $trivtran(player) $+ $chr(124) $+ $trivtran(number) $+ > < $+ $gtok(1,4) $+ $chr(124) $+ $gtok(2,4) $+ $chr(124) $+ $gtok(3,4) $+ $chr(124) $+ $gtok(4,4) $+ $chr(124) $+ $gtok(5,4) $+ >) $e2(to display stats on that individual.) }
  1493. alias -l msg.trivia.op.ban { return $e2(User is banned.) }
  1494. alias -l msg.trivia.error.ban { return $e2(You need to specify a user or address to ban.) }
  1495. alias -l msg.trivia.error.unban { return $e2(You need to specify a user or address to unban.) }
  1496. alias -l msg.trivia.op.unban { return $e2(User is unbanned.) }
  1497. alias -l msg.trivia.error.badnum { return $e2(You need to specify a valid question number to be asked.) }
  1498. alias -l msg.trivia.op.ask { return $e2(Question will be asked.) }
  1499. alias -l msg.trivia.error.noquestion { return $e2(You need append the question that is to be added directly into the question file.) }
  1500. alias -l msg.trivia.error.nodelim { return $e2(You need at least one delimiter to indicate: question $+ $triv(delimiter) $+ answer) }
  1501. alias -l msg.trivia.op.added { return $e2(Question has been added.) }
  1502. alias -l msg.trivia.error.nosearch { return $e2(You need at least some search text.) }
  1503. alias -l msg.trivia.op.find { return $iif($get.find($1-),$e1($get.find($1-)),$msg.trivia.error.find) }
  1504. alias -l msg.trivia.error.find { return $e2(That text was not found.) }
  1505. alias -l msg.trivia.error.topx { return $e2(Range too great.) }
  1506. alias -l msg.trivia.echoanswer { return $e2(Answer:) $e1($trivq.answer) }
  1507. ;########################################################
  1508. ;# Help structure.                                      #
  1509. ;########################################################
  1510. alias -l givehelp {
  1511.   if (!$1-) {
  1512.     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) $pre $+ $gtok(62))
  1513.     inform $e1($pre $+ $gtok(33) < $+ $trivtran(command) $+ >) $e2(for specific help. Some commands may be disabled.)
  1514.   }
  1515.   var %ctok = $iif($pre $+ * iswm $1, $ctok($right($1,$calc(-1 * $len($pre)))), $ctok($1))
  1516.   if ((%ctok == 1)) { inform $e1($gtok(%ctok) -----) $e2(Displays the state of the bot) }
  1517.   if ((%ctok == 6)) { inform $e1($gtok(%ctok) ---) $e2(Stops trivia) }
  1518.   if ((%ctok == 3)) { inform $e1($gtok(%ctok) ----) $e2(Enables trivia bot) }
  1519.   if ((%ctok == 2)) { inform $e1($gtok(%ctok) ---) $e2(Disables trivia bot) }
  1520.   if ((%ctok == 7)) { inform $e1($gtok(%ctok) ----) $e2(Pauses trivia bot) }
  1521.   if ((%ctok == 8)) { inform $e1($gtok(%ctok) ----) $e2(Resumes trivia bot) }
  1522.   if ((%ctok == 4)) { inform $e1($gtok(%ctok) < $+ $trivtran(command) $+ > -) $e1($gtok(1,2)) $+ $e2($chr(44)) $e1($gtok(2,2)) $+ $e2($chr(44)) $e1($gtok(3,2)) $+ $e2($chr(44)) $e1($gtok(4,2)) $+ $e2($chr(44)) $e1($gtok(5,2)) $+ $e2($chr(44)) $e1($gtok(6,2)) $+ $e2($chr(44)) $e1($gtok(7,2)) $+ $e2($chr(44)) $e1($gtok(8,2)) $+ $e2($chr(44) commands to allow ops to control the trivia bot.) }
  1523.   if ((%ctok == 5)) { inform $e1($gtok(%ctok) x --) $e2(Starts trivia, x can be a number, "unlimited", <theme> or "team" for team mode) }
  1524.   if ((%ctok == 39)) { inform $e1($gtok(%ctok) ------) $e2(Gives a hint) }
  1525.   if ((%ctok == 42)) { inform $e1($gtok(%ctok) ------) $e2(Gives the last character of the answer) }
  1526.   if ((%ctok == 41)) { inform $e1($gtok(%ctok) ------) $e2(Gives the number of words in the answer) }
  1527.   if ((%ctok == 43)) { inform $e1($gtok(%ctok) ------) $e2(Gives the vowels of the answer) }
  1528.   if ((%ctok == 34)) { inform $e1($gtok(%ctok) x ----) $e2(Joins a team, must be in team mode, x can be a 1 or 2) }
  1529.   if ((%ctok == 29)) { inform $e1($gtok(%ctok) -------) $e2(Allows you to add questions: $pre $+ $gtok(29) What is the square root of 4*two*2) }
  1530.   if ((%ctok == 30)) { inform $e1($gtok(%ctok) ----) $e2(Lets you report problems with the questions: $pre $+ $gtok(30) The square root of 4 is also -2) }
  1531.   if ((%ctok == 31)) { inform $e1($gtok(%ctok) -----) $e2(Checks your lag from the bot) }
  1532.   if ((%ctok == 27)) { inform $e1($gtok(%ctok) ---) $e2(Displays the version of the bot) }
  1533.   if ((%ctok == 28)) { inform $e1($gtok(%ctok) -------) $e2(Displays the web page for the bot) }
  1534.   if ((%ctok == 14)) { inform $e1($gtok(%ctok) < $+ $gtok(1,3) $+ $chr(124) $+ $gtok(2,3) $+ $chr(124) $+ $gtok(3,3) $+ $chr(124) $+ $gtok(4,3) $+ > < $+ $gtok(1,4) $+ $chr(124) $+ $gtok(2,4) $+ $chr(124) $+ $gtok(3,4) $+ $chr(124) $+ $gtok(4,4) $+ $chr(124) $+ $gtok(5,4) $+ > -------) $e2(Displays the hall of fame, for requested entry) }
  1535.   if ((%ctok == 19)) { inform $e1($gtok(%ctok) ---) $e2(Displays the record times. Same as $pre $+ $gtok(14) $gtok(2,3)) }
  1536.   if ((%ctok == 16)) { inform $e1($gtok(%ctok) --) $e2(Displays the record streaks. Same as $pre $+ $gtok(14) $gtok(3,3)) }
  1537.   if ((%ctok == 21)) { inform $e1($gtok(%ctok) ----) $e2(Displays the record words per minute. Same as $pre $+ $gtok(14) $gtok(4,3)) }
  1538.   if ((%ctok == 25)) { inform $e1($gtok(%ctok) ---) $e2(Displays the record $gtok(2,3) & $gtok(3,3) & $gtok(4,3)) }
  1539.   if ((%ctok == 23)) { inform $e1($gtok(%ctok) ----) $e2(Displays the bot's server) }
  1540.   if ((%ctok == 26)) { inform $e1($gtok(%ctok) -----) $e2(Displays the champ stats) }
  1541.   if ((%ctok == 36)) { inform $e1($gtok(%ctok)) $e2(Displays the scores for the current round.) }
  1542.   if ((%ctok == 35)) { inform $e1($gtok(%ctok)) $e2(Displays the teams and which players are on each.) }
  1543.   if ((%ctok == 44)) { inform $e1($gtok(%ctok) ----) $e2(Repeats the question) }
  1544.   if ((%ctok == 37)) { inform $e1($gtok(%ctok) ----) $e2(Provides the answer to the last question to an op who requests it) }
  1545.   if ((%ctok == 38)) { inform $e1($gtok(%ctok) ----) $e2(After half the time to answer has expired allows an instant timeout.) }
  1546.   if ((%ctok == 10)) { inform $e1($gtok(%ctok) ----) $e2(Lists available themes) }
  1547.   if ((%ctok == 11)) { inform $e1($gtok(%ctok) ------) $e2(Returns your current stats, or $pre $+ $gtok(11) <player> for somebody else) }
  1548.   if ((%ctok == 62)) { inform $e1($gtok(%ctok) ----) $e2(Displays score required for next promotion.) }
  1549. }
  1550. ;########################################################
  1551. ;# MESSAGE PROCESSES.                                   #
  1552. ;########################################################
  1553. alias -l get.question {
  1554.   var %gq $1-
  1555.   if (!$getset(status,noautoqm)) { var %aqm = 1 }
  1556.   if ($right(%gq,1) isin :!?.-) { var %aqm = 0 }
  1557.   if ($right(%gq,1) isin -) { var %gq = $left(%gq,-1) }
  1558.   if ($thget(temp.bonus) == S)  { %gq = $scramble(%gq) }
  1559.   if ($thget(temp.bonus) == R)  { %gq = $reverse(%gq) }
  1560.   if ($thget(temp.bonus) == G)  { %gq = $scatter(75,%gq) }
  1561.   return %gq $+ $iif(%aqm,?)
  1562. }
  1563. alias -l get.banlist {
  1564.   var %i = 1, %b.temp
  1565.   while ($getset(banned,%i)) {
  1566.     var %b.temp = %b.temp $getset(banned,%i)
  1567.     inc %i
  1568.   }
  1569.   return %b.temp
  1570. }
  1571. alias -l get.roundscores {
  1572.   if ($window(@round $+ $idenn)) { window -c @round $+ $idenn }
  1573.   window -hn @round $+ $idenn
  1574.   .timer 1 0 window -c @round $+ $idenn
  1575.   var %i = 1
  1576.   while ($hmatch(Trivia $+ $idenn, Score.*, %i)) {
  1577.     var %j = $line(@round $+ $idenn,0)
  1578.     while (( $hget(Trivia $+ $idenn, $hmatch(Trivia $+ $idenn, Score.*, %i)) > $thget(Score. $+ $line(@round $+ $idenn, %j))) && (%j >= 1)) { dec %j }
  1579.     iline @round $+ $idenn $calc(%j + 1) $remove($hmatch(Trivia $+ $idenn, Score.*, %i),Score.)
  1580.     inc %i
  1581.   }
  1582.   var %roundscores
  1583.   %i = 1
  1584.   while (%i <= 15) {
  1585.     %roundscores = %roundscores $iif($line(@round $+ $idenn,%i),$line(@round $+ $idenn,%i) $+ - $+ $thget(Score. $+ $line(@round $+ $idenn,%i)))
  1586.     inc %i
  1587.   }
  1588.   return %roundscores
  1589. }
  1590. alias sortroundscores {
  1591.   var %j = 1
  1592.   while (%j <= $line(@round $+ $idenn,0)) {
  1593.     var %k = %j
  1594.     while (%k <= $line(@round $+ $idenn,0)) {
  1595.       if ($thget(Score. $+ $line(@round $+ $idenn, %j)) > $thget(Score. $+ $line(@round $+ $idenn, %k))) {
  1596.         var %temp.name = $line(@round $+ $idenn, %j)
  1597.         rline @round $+ $idenn %j $line(@round $+ $idenn, %k)
  1598.         rline @round $+ $idenn %j %temp.name
  1599.       }
  1600.       inc %k
  1601.     }
  1602.     inc %j
  1603.   }
  1604. }
  1605. alias -l get.showteams {
  1606.   var %i = 1
  1607.   while ($hmatch(Trivia $+ $idenn, Team.*, %i)) {
  1608.     if ($isteam($remove($hmatch(Trivia $+ $idenn, Team.*, %i),Team.)) == $1) { var %temp.team = %temp.team $remove($hmatch(Trivia $+ $idenn, Team.*, %i),Team.) }
  1609.     inc %i
  1610.   }
  1611.   return %temp.team
  1612. }
  1613. alias -l get.champ {
  1614.   if (($setini(Champ,0) <= 0) || (!$getset(status,champ))) { return }
  1615.   var %temp.champ, %i = $calc($ini($trivini, Champ, 0) - 1)
  1616.   while ((%i >= 1) && (!$1)) {
  1617.     var %temp.champ = %temp.champ $getset(Champ, %i)
  1618.     dec %i
  1619.   }
  1620.   return %temp.champ
  1621. }
  1622. alias -l get.multianswers {
  1623.   var %i 2, %answers.t
  1624.   if ($window(@multianswer)) { window -c @multianswer }
  1625.   window -h @multianswer
  1626.   .timer 1 0 window -c @multianswer
  1627.   while ($tok(%i)) {
  1628.     aline @multianswer $tok(%i)
  1629.     inc %i
  1630.   }
  1631.   filter -wwct 1 13 @multianswer @multianswer *
  1632.   var %i 2
  1633.   var %answers.t $line(@multianswer,1)
  1634.   while ($line(@multianswer, %i)) { var %answers.t = %answers.t $+ , $line(@multianswer, %i), %i = $calc(%i + 1) }
  1635.   return %answers.t
  1636. }
  1637. alias -l get.themes {
  1638.   var %i = 1
  1639.   while ($getset(triviamode $+ %i, name)) {
  1640.     var %temp.themes = %temp.themes $getset(triviamode $+ %i, name)
  1641.     inc %i
  1642.   }
  1643.   return $e1(%temp.themes)
  1644. }
  1645. alias -l get.onjoin {
  1646.   return %c2 $+ $replace($1-,$chr(35),$+(%c2o,%c1,$chan,%c1o,%c2),*, $+(%c2o,%c1,$getmrank($nick) $nick,%c1o,%c2),@, $+(%c2o,%c1,$tranord($getrank($nick,$unit.default)),%c1o,%c2),^, $+(%c2o,%c1,$ifd($getvar($nick,score),0),%c1o,%c2)) $+ %c2o
  1647. }
  1648. alias -l get.picklist {
  1649.   if ($tokq <= 2) return $tok(2)
  1650.   var %i = 2, %picklist
  1651.   while (%i <= $tokq) {
  1652.     %picklist = %picklist $tok(%i)
  1653.     if (%i < $calc($tokq - 1)) { %picklist = %picklist $+ $chr(44) }
  1654.     if (%i == $calc($tokq - 1)) { %picklist = %picklist $trivtran(and) }
  1655.     inc %i
  1656.   }
  1657.   return %picklist
  1658.  
  1659. }
  1660. ;########################################################
  1661. ;# HTML BUILD                                           #
  1662. ;########################################################
  1663. alias bgcolor { return #000000 }
  1664. alias textcolor { return #339933 }
  1665. alias linkcolor { return #33FF00 }
  1666. alias alinkcolor { return #666600 }
  1667. alias vlinkcolor { return #666666 }
  1668.  
  1669. alias htmlbuild {
  1670.   var %start.ticks = $ticks
  1671.   set %htmlfile " $+ $mircdir $+ \ $+ $ifd($getset(build,genname),triv.htm) $+ "
  1672.   sort score $unit.default
  1673.   if ($exists(%htmlfile)) { .remove %htmlfile }
  1674.   write %htmlfile <HTML><head><title> $+ $iden $iif($network,$trivtran(Trivia Scores on) $network) $+ </title></head>
  1675.   write %htmlfile <body bgcolor=" $+ $bgcolor $+ " text=" $+ $textcolor $+ " link=" $+ $linkcolor $+ " alink=" $+ $alinkcolor $+ " vlink=" $+ $vlinkcolor $+ ">
  1676.   write %htmlfile $trivtran(The scores file was compiled by:) $strip($msg.trivia.version) <br>
  1677.   write %htmlfile $trivtran(This file was created on:) $time $chkadate($date) <br>
  1678.   write %htmlfile <table BORDER COLS=5 WIDTH="80%" ><tr><tr>
  1679.   write %htmlfile <th> $+ $trivtran(Ranking) $+ </th><th> $+ $trivtran(Name) $+ </th> $+ $iif(!$getset(hide,score),<th> $+ $trivtran(Score) $+ </th>) $+ $iif(!$getset(hide,time),<th> $+ $trivtran(Best Time) $+ </th>) $+ $iif(!$getset(hide,streak),<th> $+ $trivtran(Best Streak) $+ </th>) $+ $iif(!$getset(hide,wpm),<th> $+ $trivtran(Best WPM) $+ </th>) $+ </tr>
  1680.   var %i = 1, %j = $hof.size
  1681.   if ($getset(build,top) isnum 1 - %j) { %j = $getset(build,top) }
  1682.   if ($version >= 6.15) {
  1683.     set %count.num.t %i
  1684.     filter -wkr %i $+ - $+ %j $twin htmlprocess
  1685.     unset %count.num.t
  1686.   }
  1687.   else {
  1688.     while (%i <= %j) {
  1689.       write %htmlfile <tr><th> $+ %i $+ </th><td> $+ $hof(%i,1) $+ </td> $+ $iif(!$getset(hide,score),<td> $+ $hof(%i,$gttok($unit.mark $+ score)) $+ </td>) $+ $iif(!$getset(hide,time),<td> $+ $hof(%i,$gttok($unit.mark $+ time)) $+ </td>) $+ $iif(!$getset(hide,streak),<td> $+ $hof(%i,$gttok($unit.mark $+ streak)) $+ </td>) $+ $iif(!$getset(hide,wpm),<td> $+ $hof(%i,$gttok($unit.mark $+ wpm)) $+ </td>) $+ </tr>
  1690.       inc %i
  1691.     }
  1692.   }
  1693.   write %htmlfile </table><br>
  1694.   write %htmlfile $trivtran(Made with) <a href=" $+ $trivia.web $+ " "target="_top"> $+ $strip($msg.trivia.version) $+ </a><br>
  1695.   echo -a $e2(Finished:) $e1(%htmlfile) $e2(is written. In) $e1($calc(($ticks - %start.ticks) / 1000)) $+ $e2(secs.)
  1696.   unset %htmlfile
  1697. }
  1698. alias htmlprocess {
  1699.   write %htmlfile <tr><th> $+ %count.num.t $+ </th><td> $+ $gettok($1,1,59) $+ </td> $+ $iif(!$getset(hide,score),<td> $+ $gettok($1,$gttok($unit.mark $+ score),59) $+ </td>) $+ $iif(!$getset(hide,time),<td> $+ $gettok($1,$gttok($unit.mark $+ time),59) $+ </td>) $+ $iif(!$getset(hide,streak),<td> $+ $gettok($1,$gttok($unit.mark $+ streak),59) $+ </td>) $+ $iif(!$getset(hide,wpm),<td> $+ $gettok($1,$gttok($unit.mark $+ wpm),59) $+ </td>) $+ </tr>
  1700.   inc %count.num.t
  1701. }
  1702.  
  1703. alias xmlbuild {
  1704.   if ($version < 6.15) {
  1705.     echo -a Update to a later version of mIRC. This code will not work with versions prior to 6.15.
  1706.     return
  1707.   }
  1708.   var %start.ticks = $ticks
  1709.   set %xmlfile " $+ $mircdir $+ \ $+ triv-rss-091.xml $+ "
  1710.   sort score $unit.default
  1711.   if ($exists(%xmlfile)) { .remove %xmlfile }
  1712.  
  1713.   write %xmlfile <?xml version="1.0" ?>
  1714.   write %xmlfile <rss version="0.91">
  1715.   write %xmlfile    <channel>
  1716.   write %xmlfile        <title> $trivia.name </title>
  1717.   write %xmlfile        <link> $trivia.web </link>
  1718.   write %xmlfile        <description>Latest Scores</description>
  1719.   write %xmlfile        <language>en-us</language>
  1720.   write %xmlfile        <copyright>Copyright $asctime(yyyy) $+ </copyright>
  1721.   write %xmlfile        <lastBuildDate> $asctime($gmt, ddd $+ $chr(44) dd mmm yyyy HH:nn:ss) GMT </lastBuildDate>
  1722.  
  1723.   var %i = 1, %j = $hof.size
  1724.   if ($getset(build,top) isnum 1 - %j) { %j = $getset(build,top) }
  1725.   set %count.num.t %i
  1726.   filter -wkr %i $+ - $+ %j $twin xmlprocess
  1727.   unset %count.num.t
  1728.  
  1729.   write %xmlfile        </channel>
  1730.   write %xmlfile    </rss>
  1731.  
  1732.   echo -a $e2(Finished:) $e1(%xmlfile) $e2(is written. In) $e1($calc(($ticks - %start.ticks) / 1000)) $+ $e2(secs.)
  1733.   unset %xmlfile
  1734. }
  1735. alias xmlprocess {
  1736.   write %xmlfile        <item>
  1737.   write %xmlfile            <title> $+ $gettok($1,1,59) $+ </title>
  1738.   write %xmlfile            <description> Score: $gettok($1,$gttok($unit.mark $+ score),59) Record Time: $gettok($1,$gttok($unit.mark $+ time),59) Streak: $gettok($1,$gttok($unit.mark $+ streak),59) WPM: $gettok($1,$gttok($unit.mark $+ wpm),59)  </description>
  1739.   write %xmlfile            <link> $+ $trivia.web $+ </link>
  1740.   write %xmlfile            </item>
  1741.   inc %count.num.t
  1742. }
  1743. alias xmlbuildon { setset build xml 1 }
  1744. alias xmlbuildoff { setset build xml 0 }
  1745.  
  1746. alias unit.mark { return $iif($unit.default != total,$unit.default) }
  1747. alias htmltrigger {
  1748.   if ($getset(build,xml)) { xmlbuild }
  1749.   if ($getset(build,generate)) { htmlbuild }
  1750.   if (($getset(build,auto)) && ($exists($+(",$triv(dir),\,ftpbatch.txt,")))) { run -n ftp $+(-s:,",$triv(dir),\,ftpbatch.txt") }
  1751.   if (($getset(build,copy)) && ($exists(" $+ $getset(build,from) $+ ")) && ($exists(" $+ $getset(build,to) $+ "))) { .copy -o " $+ $getset(build,from) $+ " " $+ $getset(build,to) $+ \ $+ $nopath($getset(build,from)) $+ " }
  1752.   if ($getset(build,web)) { tsay $msg.features.built($getset(build,web)) }
  1753.   award HTMLUpdate 0
  1754. }
  1755. ;########################################################
  1756. ;# SPECIAL COMMANDS.                                    #
  1757. ;# /find <text> : Finds the text in your current        #
  1758. ;#     question files for the channel.                  #
  1759. ;# /add <question> : directly adds the given question.  #
  1760. ;# /ask <question|#> : Force asks a given question.     #
  1761. ;# /sortfile : Sorts the selcted file alphanumerically. #
  1762. ;# /killdup : Kills exact duplicate questions in file.  #
  1763. ;# /killfixdup : Uses internal fix routine to kill same #
  1764. ;#      questions with a little more checking.          #
  1765. ;# /reformfile <filename> <regex> <regex> : Uses the    #
  1766. ;#      regsub command to reform a file. For example:   #
  1767. ;#      /reformfile q.txt ([^\|]+)\|([^\*]+) \2*\1      #
  1768. ;#      would change q.txt from answer|question form to #
  1769. ;#      question*answer form. You need to know regex.   #
  1770. ;# /tpurge <#> : Moves everybody with less that # point #
  1771. ;#       to a secondary file called backburner. If they #
  1772. ;#       score another point they will be restored.     #
  1773. ;# /tdpurge <#> : Anybody who hasn't played in # days.  #
  1774. ;# /copyentry <filefrom> <fileto> <nickname> : Copies.  #
  1775. ;# /debackburn : Reverses effect of /tpurge commands.   #
  1776. ;# /mergefiles <filefrom> <fileto> : Merges two score   #
  1777. ;#       files into one score file.                     #
  1778. ;# /tfind : finds score files that should be merged.    #
  1779. ;# /tmerge <fromplayer> <toplayer> : merge player score #
  1780. ;# /trename <fromplayer> <toplayer> : renames player    #
  1781. ;# /triviaad <#> <message> : displays message every <#> #
  1782. ;#       of minutes.                                    #
  1783. ;# /triviaad2 <#> <message> : Same but colored.         #
  1784. ;# /truntimes <timeon> <timeoff> : turns bot on and off #
  1785. ;#       only plays during the given times.             #
  1786. ;########################################################
  1787. alias find { echo $get.find($1-) }
  1788. alias add { if ($exists($qfile(1))) write $qfile(1) $1- }
  1789. alias ask {
  1790.   var %asknm = 1
  1791.   while ($thget(Ask $+ %asknm)) { inc %asknm }
  1792.   if ($hget(Trivia $+ $idenn)) { thset Ask $+ %asknm $iif($1-,$1-,$$?="Force which question number(#) or ask what question(Question*Answer)?") }
  1793. }
  1794. alias sortfile {
  1795.   var %file = " $+ $sfile($mircdir) $+ "
  1796.   filter -ffct 1 13 %file %file *
  1797. }
  1798. alias killdup {
  1799.   var %file = " $+ $sfile($mircdir) $+ ", %i = 0
  1800.   window -hn @temp.window
  1801.   window -hn @temp.windowfile
  1802.   filter -fwct 1 13 %file @temp.windowfile *
  1803.   while ($line(@temp.windowfile,0) >= %i) {
  1804.     var %line = $line(@temp.windowfile,%i)
  1805.     if (%line) { aline -n @temp.window %line }
  1806.     unset %line
  1807.     inc %i
  1808.   }
  1809.   filter -wfc @temp.window %file *
  1810.   window -c @temp.window
  1811.   window -c @temp.windowfile
  1812. }
  1813. alias killfixdup {
  1814.   var %file = $sfile($mircdir), %i = 0, %fixed = 0
  1815.   window -hn @temp.windowfix
  1816.   window -hn @temp.windowfile
  1817.   .timer 1 0 window -c @temp.windowfix
  1818.   .timer 1 0 window -c @temp.windowfile
  1819.   filter -fwct 1 13 " $+ %file $+ " @temp.windowfile *
  1820.   while ($line(@temp.windowfile,0) >= %i) {
  1821.     if ($line(@temp.windowfile,%i)) {
  1822.       aline -n @temp.windowfix $fix($line(@temp.windowfile,%i))
  1823.       if (%fixed != $line(@temp.windowfix,0)) { write $nopath(%file) $+ .fix $line(@temp.windowfile,%i) }
  1824.       var %fixed = $line(@temp.windowfix,0)
  1825.     }
  1826.     inc %i
  1827.   }
  1828.   echo -s Killed dups, saved as %file $+ .fix $+ !
  1829. }
  1830. alias reformfile {
  1831.   if (!$exists($1)) { echo File not found. | return }
  1832.   var %i = 1, %replace, %matchez = 0
  1833.   while (%i <= $lines($1)) {
  1834.     if ($regsub($read($1,%i),$2, $3, %replace)) { write $1 $+ .ref %replace | inc %matchez }
  1835.     inc %i
  1836.   }
  1837.   echo Done, %matchez lines replaced, saved as $1 $+ .ref
  1838. }
  1839. alias tpurge {
  1840.   var %i = 1
  1841.   sort score
  1842.   while ($hof(%i,1)) {
  1843.     if ($hof(%i,2) <= $$1) { copyentry $$scoresfil $$tempfil $hof(%i,1) }
  1844.     inc %i
  1845.   }
  1846. }
  1847. alias tdpurge {
  1848.   var %i = 1
  1849.   sort score
  1850.   while ($hof(%i,1)) {
  1851.     if ($round($calc(($ctime($date) - $ctime($hof(%i,6)))/86400),0) > $$1) { copyentry $$scoresfil $$tempfil $hof(%i,1) }
  1852.     inc %i
  1853.   }
  1854. }
  1855. alias copyentry {
  1856.   write $2 $$read($1, w, $3 $+ ;*)
  1857.   write -dl $+ $$readn $1
  1858. }
  1859. alias debackburn { mergefiles $tempfil $scoresfil }
  1860. alias mergefiles {
  1861.   echo Merging files $1 and $2
  1862.   if (!$exists($1)) { echo -a $1 does not exist. | return }
  1863.   if (!$exists($2)) { echo -a $2 does not exist. | return }
  1864.   while ($lines($1) > 0) {
  1865.     if ($numtok($read($1,1),$asc(;)) <= 1) { echo -a ERROR, file does not appear to be standard format. | return }
  1866.     var %player = $gettok($read($1,1),1,$asc(;))
  1867.     mergeentry $1 $2 %player
  1868.   }
  1869. }
  1870. alias mergeentry {
  1871.   var %merger = $read($1, wnt, $3 $+ ;*)
  1872.   var %other = $read($2, wnt, $3 $+ ;*)
  1873.   var %merger.line = $readn
  1874.   if (%merger) {
  1875.     if (%other) {
  1876.       write $2 PlayerMoving= $+ %merger
  1877.       write -d1 $+ %merger.line $1
  1878.       tmergeplayers PlayerMoving= $+ $3 $3
  1879.     }
  1880.     else copyentry $1 $2 $3
  1881.   }
  1882. }
  1883. alias tfind {
  1884.   if ($exists($scoresfil)) {
  1885.     echo -a Finding Duplicate Entries
  1886.     window -h $twin
  1887.     filter -fwc $scoresfil $twin
  1888.     var %k = $line($twin,0)
  1889.     while (%k > 0) {
  1890.       %hostname = $replace($mask($gettok($line($twin,%k), $gttok(address), 59),2),.,\.,*,.*)
  1891.       if (%hostname) {
  1892.         var %j = 1
  1893.         var %fline = $fline($twin,$str([^;]*;,7) $+ %hostname $+ ;.*,1,2)
  1894.         while (%fline) {
  1895.           if (%j == 2) {
  1896.             echo -a Multiple references:
  1897.             echo -a ... $gettok($line($twin,%prev.fline),1,59) ... $gettok($line($twin,%prev.fline),$gttok(address),59)
  1898.           }
  1899.           if (%j >= 2) {
  1900.             echo -a ... $gettok($line($twin,%fline),1,59) ... $gettok($line($twin,%fline),$gttok(address),59)
  1901.             dline $twin %prev.fline
  1902.           }
  1903.           inc %j
  1904.           var %prev.fline = %fline
  1905.           var %fline = $fline($twin,$str([^;]*;,7) $+ %hostname $+ ;.*,2,2)
  1906.         }
  1907.       }
  1908.       dec %k
  1909.     }
  1910.   }
  1911.   echo -a To combine entries use: /tmerge <from-nick> <to-nick>
  1912.   window -c $twin
  1913. }
  1914. alias tmerge {
  1915.   tmergeplayers $1 $2
  1916.   tsay $msg.trivia.stats($2)
  1917. }
  1918. alias tmergeplayers {
  1919.   if (($$realvar($$1,score)) && ($$realvar($$2,score))) {
  1920.     var %i = $numtok($unit.tokens, $asc(.))
  1921.     while (%i > 0) {
  1922.       var %unit = $gettok($unit.tokens, %i, $asc(.))
  1923.       if ($realvar($1, %unit) == $eval($ $+ get. $+ %unit,2)) {
  1924.         if ($realvar($2, %unit) == $eval($ $+ get. $+ %unit,2)) {
  1925.           setvar $2 %unit $+ score $calc($realvar($2,%unit $+ score) + $realvar($1,%unit $+ score))
  1926.           if ($realvar($1, %unit $+ WPM) > $realvar($2,%unit $+ WPM)) { setvar $2 %unit $+ WPM $realvar($1, %unit $+ WPM) }
  1927.           if ($realvar($1, %unit $+ streak) > $realvar($2,%unit $+ streak)) { setvar $2 %unit $+ streak $realvar($1, %unit $+ streak) }
  1928.           if ($realvar($1, %unit $+ time) < $realvar($2,%unit $+ time)) { setvar $2 %unit $+ time $realvar($1, %unit $+ time) }
  1929.         }
  1930.         else {
  1931.           setvar $2 %unit $+ score $realvar(%unit $+ score)
  1932.           setvar $2 %unit $+ WPM $realvar(%unit $+ WPM)
  1933.           setvar $2 %unit $+ streak $realvar(%unit $+ streak)
  1934.           setvar $2 %unit $+ time $realvar(%unit $+ time)
  1935.         }
  1936.       }
  1937.       dec %i
  1938.     }
  1939.     setvar $2 score $calc($realvar($2,score) + $realvar($1,score))
  1940.     if ($realvar($1, wpm) > $realvar($2,wpm)) { setvar $2 wpm $realvar($1, wpm) }
  1941.     if ($realvar($1, streak) > $realvar($2,streak)) { setvar $2 streak $realvar($1, streak) }
  1942.     if ($realvar($1, time) < $realvar($2,time)) { setvar $2 time $realvar($1, time) }
  1943.     setvar $2 admin $or($realvar($1,admin),$realvar($2,admin))
  1944.     deleteplayer $1
  1945.   }
  1946. }
  1947. alias trename {
  1948.   setvar $1 name $2
  1949.   tsay $msg.trivia.stats($2)
  1950. }
  1951. alias triviad {
  1952.   if (($1 >= 1) && ($2)) { .timertriviaad 0 $calc($$1 * 60) timer.ad $chan $2- }
  1953.   else { .timertriviaad off }
  1954. }
  1955. alias triviad2 {
  1956.   if (($1 >= 1) && ($2)) { .timertriviaad 0 $calc($$1 * 60) msg $chan $e1($2-) }
  1957.   else { .timertriviaad off }
  1958. }
  1959. alias truntimes {
  1960.   if (($regex($1,/\d+:\d+/)) && ($regex($2,/\d+:\d+/))) {
  1961.     .timertriviarunon -o $1 1 1 tboton $1
  1962.     .timertriviarunoff -o $2 1 1 tbotoff $2
  1963.   }
  1964.   else { .timertriviarun* off }
  1965. }
  1966. alias tboton {
  1967.   .timertriviarunon -o $1 1 1 tboton $1
  1968.   setset status bot 1
  1969.   trivia
  1970. }
  1971. alias tbotoff {
  1972.   .timertriviarunoff -o $1 1 1 tbotoff $1
  1973.   if ($trivia.on) { strivia }
  1974.   setset status bot 0
  1975. }
  1976. alias tempfil { return backburner.txt }
  1977. alias timer.ad { if (!$trivia.on) { msg $1 $e1($2-) } }
  1978. ;########################################################
  1979. ;# DIALOGS.                                             #
  1980. ;########################################################
  1981. dialog trivset {
  1982.   title "Trivia Settings"
  1983.   size -1 -1 456 356
  1984.   option pixels
  1985.   tab General, 1, 4 0 456 359
  1986.   box Channels, 9, 12 28 266 80, tab 1
  1987.   text Delimiter, 10, 22 287 48 13, tab 1
  1988.   text Add/Report, 11, 18 265 60 13, tab 1
  1989.   button Add, 24, 20 156 44 16, tab 1
  1990.   edit , 30, 72 81 198 22, tab 1 multi autohs
  1991.   edit $triv(delimiter), 31, 84 287 30 22, tab 1
  1992.   edit $triv(additions), 32, 84 261 86 22, tab 1 multi autohs
  1993.   edit $triv(report), 33, 172 261 86 22, tab 1 multi autohs
  1994.   edit $triv(dir), 35, 84 235 174 22, tab 1 multi autohs
  1995.   text Percent Hint, 14, 288 64 68 13, tab 1
  1996.   edit $triv(perchint), 99, 384 60 36 20, tab 1
  1997.   text Number of hints, 15, 288 46 80 13, tab 1
  1998.   edit $triv(numhint), 861, 384 38 36 20, tab 1
  1999.   text Hint Reduction, 16, 288 260 80 13, tab 1
  2000.   edit $triv(DPH), 863, 400 256 36 20, tab 1
  2001.   text Points per answer, 17, 288 238 88 13, tab 1
  2002.   edit $triv(PPQ), 65, 400 234 36 20, tab 1
  2003.   list 108, 70 40 200 40, tab 1 size
  2004.   button Add, 115, 22 48 46 16, tab 1
  2005.   button Remove, 119, 22 64 46 16, tab 1
  2006.   text Channel:, 125, 16 84 50 16, tab 1
  2007.   edit , 132, 68 192 202 21, tab 1 multi autohs
  2008.   box "Points", 133, 280 220 168 64, tab 1
  2009.   box "Global", 134, 12 224 264 120, tab 1
  2010.   button "Scores", 141, 20 196 44 16, tab 1
  2011.   button "Define", 20, 216 288 47 17, tab 1
  2012.   check "Trivia Ranks", 148, 132 288 80 20, tab 1
  2013.   check Crosshatch, 47, 288 96 80 20, tab 1
  2014.   text Chr, 21, 372 96 19 13, tab 1
  2015.   edit , 961, 392 96 24 18, tab 1
  2016.   box "Hints", 80, 280 28 168 192, tab 1
  2017.   radio "Scatter", 58, 336 148 56 16, group tab 1
  2018.   radio "Plot", 129, 392 148 44 16, tab 1
  2019.   radio "Basic", 130, 288 148 48 16, tab 1
  2020.   text $hint.example, 199, 288 132 154 16, tab 1
  2021.   check "Say Hint Number", 147, 288 112 100 20, tab 1
  2022.   radio "Standard", 149, 284 184 68 16, group tab 1
  2023.   radio "Last", 150, 360 184 44 16, tab 1
  2024.   radio "Vowels", 151, 284 200 60 16, tab 1
  2025.   radio "Random", 152, 360 200 68 16, tab 1
  2026.   text "First Hint Type", 153, 288 168 74 12, tab 1
  2027.   button "Remove", 12, 20 172 44 16, tab 1
  2028.   list 34, 68 156 202 32, tab 1 sort size
  2029.   box "Channel Properties", 83, 12 108 266 116, tab 1
  2030.   edit $triv(translate), 131, 104 312 152 21, tab 1 multi autohs
  2031.   button "Translation File", 136, 20 316 79 17, tab 1
  2032.   button "Trivia Dir", 13, 20 240 63 17, tab 1
  2033.   text "Nick", 543, 28 128 30 16, tab 1
  2034.   edit "", 544, 68 124 76 21, tab 1 multi autohs
  2035.   text "Network", 66, 148 128 42 16, tab 1
  2036.   edit "", 67, 192 124 76 21, tab 1 multi autohs
  2037.   check Auto-Hint, 41, 288 79 72 20, tab 1
  2038.   tab Options, 6
  2039.   text questions, 18, 72 143 52 13, tab 6
  2040.   check No-activity off, 88, 20 126 88 20, tab 6
  2041.   edit $triv(naoff), 89, 36 143 30 20, tab 6
  2042.   text seconds, 19, 174 143 44 13, tab 6
  2043.   check Hint-Pause, 96, 120 126 88 20, tab 6
  2044.   edit $triv(hintpause), 97, 138 143 30 20, tab 6
  2045.   check Echo Answer, 40, 20 40 88 20, tab 6
  2046.   check Timeout Answer, 45, 120 75 96 20, tab 6
  2047.   check Join Message, 46, 12 220 96 20, tab 6
  2048.   check Traditional win, 48, 20 75 88 20, tab 6
  2049.   check Auto-Start, 49, 224 40 88 20, tab 6
  2050.   check Say Scramble:, 53, 120 40 88 20, tab 6
  2051.   check Showteam End, 55, 120 58 96 20, tab 6
  2052.   check Answer Space, 56, 224 92 88 20, tab 6
  2053.   check No Mid-Match, 57, 320 126 88 20, tab 6
  2054.   check Show Matched, 59, 120 92 88 20, tab 6
  2055.   check Use Adate, 60, 20 58 88 20, tab 6
  2056.   check No ? end, 830, 320 40 88 20, tab 6
  2057.   check No Spell Correct, 817, 320 109 96 20, tab 6
  2058.   check "Monday Week", 126, 224 58 88 20, tab 6
  2059.   check Limit Guesses, 51, 224 126 88 20, tab 6
  2060.   edit $triv(limitguess), 144, 236 143 28 20, tab 6
  2061.   check Round HoF, 52, 224 75 88 20, tab 6
  2062.   edit , 22, 12 248 432 53, tab 6 read multi autovs
  2063.   edit $triv(onjoin), 138, 108 220 340 21, tab 6 multi autohs
  2064.   check No Partial Match, 43, 320 143 96 20, tab 6
  2065.   text "tries", 146, 268 143 34 16, tab 6
  2066.   check No Decheater, 44, 320 58 88 20, tab 6
  2067.   check No Color Short, 61, 320 75 88 20, tab 6
  2068.   check "Score", 106, 20 180 56 20, tab 6
  2069.   check "Time", 169, 80 180 52 20, tab 6
  2070.   check "Streak", 171, 136 180 56 20, tab 6
  2071.   check "WPM", 173, 204 180 52 20, tab 6
  2072.   box "Hide Stat", 174, 12 168 252 36, tab 6
  2073.   check "No Catergories", 62, 320 92 96 20, tab 6
  2074.   check "Empty Off", 54, 20 92 88 20, tab 6
  2075.   check "No Bonus", 50, 320 160 88 20, tab 6
  2076.   check "No Q number", 63, 320 177 88 20, tab 6
  2077.   box Settings, 70, 8 24 440 188, tab 6
  2078.   check "Keep Ask", 156, 20 109 68 20, tab 6
  2079.   check "Show Nothing", 143, 120 108 92 20, tab 6
  2080.   tab Defaults, 2
  2081.   box , 23, 8 43 250 64, tab 2
  2082.   box , 25, 258 43 154 64, tab 2
  2083.   check Colors, 116, 12 32 76 16, tab 2 push
  2084.   text Primary, 110, 18 58 60 13, tab 2
  2085.   text Secondary, 120, 18 78 60 13, tab 2
  2086.   edit $tc(1), 121, 80 58 30 20, tab 2 read
  2087.   edit $tc(2), 122, 80 78 30 20, tab 2 read
  2088.   edit $tc(3), 123, 263 58 30 20, tab 2 read
  2089.   edit $tc(4), 124, 263 78 30 20, tab 2 read
  2090.   check B, 117, 205 58 20 20, tab 2 push
  2091.   check U, 118, 228 58 20 20, tab 2 push
  2092.   check B, 127, 205 78 20 20, tab 2 push
  2093.   check U, 128, 228 78 20 20, tab 2 push
  2094.   combo 111, 116 56 80 240, tab 2 size drop
  2095.   combo 112, 116 80 80 240, tab 2 size drop
  2096.   combo 113, 300 60 80 240, tab 2 size drop
  2097.   combo 114, 300 80 80 240, tab 2 size drop
  2098.   box Time, 26, 8 108 168 216, tab 2
  2099.   text Before Start, 27, 18 126 98 13, tab 2
  2100.   text Between Questions (answered), 36, 18 244 98 29, tab 2
  2101.   text Given to Answer, 37, 18 150 98 13, tab 2
  2102.   text Before Auto-Hint, 38, 18 200 98 13, tab 2
  2103.   text (timed-out), 39, 18 274 98 17, tab 2
  2104.   text Before hint allowed, 862, 18 174 98 13, tab 2
  2105.   text Between Ping Delay, 167, 18 296 98 16, tab 2
  2106.   text Between Auto-Hints, 177, 18 220 98 13, tab 2
  2107.   edit $slag(start), 135, 120 126 50 20, tab 2
  2108.   edit $slag(answered), 145, 120 244 50 20, tab 2
  2109.   edit $slag(timedout), 155, 120 148 50 20, tab 2
  2110.   edit $slag(hint), 165, 120 192 50 20, tab 2
  2111.   edit $slag(timed), 175, 120 270 50 20, tab 2
  2112.   edit $slag(hintallow), 185, 120 170 50 20, tab 2
  2113.   edit $slag(ping), 195, 120 296 48 21, tab 2
  2114.   edit $slag(betweenhint), 205, 120 216 48 21, tab 2
  2115.   box Questions, 64, 178 108 150 116, tab 2
  2116.   text Default Round, 68, 252 118 70 13, tab 2
  2117.   text Champ Goal, 69, 184 300 62 13, tab 2
  2118.   text Team Round, 71, 252 158 70 13, tab 2
  2119.   edit $triv(default), 299, 252 134 63 20, tab 2
  2120.   edit $triv(reset), 215, 248 296 63 20, tab 2
  2121.   edit $triv(dteam), 217, 252 174 63 20, tab 2
  2122.   button $record.type($triv(Record)), 218, 186 198 133 20, tab 2
  2123.   button Themes, 700, 246 236 68 20, tab 2
  2124.   radio Unlimited, 201, 184 150 64 20, tab 2
  2125.   radio Team, 202, 184 172 52 20, tab 2
  2126.   radio Normal, 203, 184 128 60 20, tab 2
  2127.   check Disable, 816, 184 236 56 20, tab 2
  2128.   box , 8, 178 220 150 48, tab 2
  2129.   check "Background", 158, 260 32 76 16, tab 2 push
  2130.   check Champ Mode, 42, 184 276 88 17, tab 2
  2131.   box , 179, 178 264 152 60, tab 2
  2132.   box Score By, 178, 328 108 84 76, tab 2
  2133.   check "Change", 182, 336 120 68 20, tab 2
  2134.   combo 183, 336 148 72 100, tab 2 size drop
  2135.   tab Teams, 3
  2136.   box Names, 72, 12 72 400 72, tab 3
  2137.   text Team 1, 73, 20 88 42 20, tab 3
  2138.   text Team 2, 74, 20 112 42 20, tab 3
  2139.   text Team 3, 308, 212 88 42 20, disable tab 3
  2140.   text Team 4, 309, 212 112 42 20, disable tab 3
  2141.   box Victories, 75, 12 144 412 144, tab 3
  2142.   text Tied Message, 76, 20 168 66 13, tab 3
  2143.   text Team 1 Wins, 77, 20 192 66 13, tab 3
  2144.   text Team 2 Wins, 78, 20 216 66 13, tab 3
  2145.   text Team 3 Wins, 303, 20 240 66 16, disable tab 3
  2146.   text Team 4 Wins, 304, 20 264 66 16, disable tab 3
  2147.   edit $te(1), 380, 60 88 148 20, tab 3 multi autohs
  2148.   edit $te(2), 381, 60 112 148 20, tab 3 multi autohs
  2149.   edit $te(4), 382, 252 112 148 20, disable tab 3 multi autohs
  2150.   edit $te(3), 383, 252 88 148 20, disable tab 3 multi autohs
  2151.   edit $te(0).victory, 320, 84 168 320 20, tab 3 multi autohs
  2152.   edit $te(1).victory, 321, 84 192 320 20, tab 3 multi autohs
  2153.   edit $te(2).victory, 322, 84 216 320 20, tab 3 multi autohs
  2154.   edit $te(3).victory, 323, 84 240 320 20, disable tab 3 multi autohs
  2155.   edit $te(4).victory, 324, 84 264 320 20, disable tab 3 multi autohs
  2156.   check Limit Join Period, 330, 276 32 88 20, tab 3 push
  2157.   edit $te(JoinBefore), 335, 276 51 88 20, tab 3
  2158.   radio 2 Teams, 28, 48 40 76 20, tab 3
  2159.   radio 4 Teams, 29, 144 40 76 20, tab 3
  2160.   tab Awards, 4
  2161.   box Awards, 79, 14 48 380 152, tab 4
  2162.   button Delete, 411, 400 80 48 20, tab 4
  2163.   button Add, 412, 400 56 48 20, tab 4
  2164.   list 420, 19 64 368 130, tab 4 size
  2165.   text "* is winner's nick.", 81, 214 257 92 13, tab 4
  2166.   text "^ is value of trigger", 82, 316 257 104 13, tab 4
  2167.   check Disable, 819, 20 28 76 17, tab 4
  2168.   combo 137, 72 212 68 100, tab 4 size drop
  2169.   edit "", 139, 268 212 68 21, tab 4
  2170.   text "Award", 140, 12 272 42 16, tab 4
  2171.   edit "", 142, 68 272 364 21, tab 4 multi autohs
  2172.   text "Trigger on", 154, 12 212 54 16, tab 4
  2173.   combo 159, 188 212 68 100, tab 4 size drop
  2174.   text "and", 160, 340 216 22 16, hide tab 4
  2175.   edit "", 161, 368 212 68 21, hide tab 4
  2176.   text "points", 162, 300 236 34 16, tab 4
  2177.   text "Do Action", 163, 12 252 50 16, tab 4
  2178.   text "values", 164, 144 212 38 16, tab 4
  2179.   combo 166, 68 248 140 100, tab 4 size drop
  2180.   tab Status, 5
  2181.   text Trivia Script version:, 84, 24 40 150 20, tab 5
  2182.   text $strip($msg.trivia.version), 85, 184 40 150 20, tab 5
  2183.   text Trivia bot is currently:, 86, 24 62 150 20, tab 5
  2184.   text $trivon, 504, 184 62 80 20, tab 5
  2185.   text Current mIRC version is:, 87, 24 84 150 20, tab 5
  2186.   text $version, 90, 184 84 80 20, tab 5
  2187.   text Current Trivia directory exists:, 91, 24 106 150 20, tab 5
  2188.   text $trivia.dir, 92, 184 106 80 20, tab 5
  2189.   text Currently in Trivia Channel:, 93, 24 128 150 20, tab 5
  2190.   text $trivia.chan, 94, 184 128 80 20, tab 5
  2191.   text Question file in Directory:, 95, 24 150 150 20, tab 5
  2192.   text $trivia.file, 98, 184 150 80 20, tab 5
  2193.   text Number of questions:, 103, 24 172 150 20, tab 5
  2194.   text $numl, 104, 184 172 78 20, tab 5
  2195.   button Delete Scores, 515, 308 96 80 20, tab 5
  2196.   button Scores, 519, 308 68 80 20, tab 5
  2197.   list 601, 26 202 288 42, tab 5 sort size
  2198.   button Unban, 602, 326 224 80 20, tab 5
  2199.   button Ban, 603, 326 202 80 20, tab 5
  2200.   list 610, 26 248 288 42, tab 5 sort size
  2201.   button Add Friend, 611, 326 250 80 20, tab 5
  2202.   button Remove, 612, 326 272 80 20, tab 5
  2203.   tab Commands, 7
  2204.   box Command Limits, 105, 188 144 208 48, tab 7
  2205.   combo 806, 200 160 184 132, disable tab 7 size drop
  2206.   text Command Prefix, 107, 24 296 82 16, tab 7
  2207.   edit %command-prefix, 850, 116 296 36 21, tab 7
  2208.   text blank = default, 109, 28 312 82 16, tab 7
  2209.   button "Build HTML Options", 157, 188 296 107 21, tab 7
  2210.   list 800, 20 52 156 236, tab 7 size
  2211.   text "Commands", 170, 20 32 62 16, tab 7
  2212.   combo 809, 200 208 184 100, disable tab 7 size drop
  2213.   box "Respond Method", 168, 188 192 208 48, tab 7
  2214.   check "Disable", 801, 192 48 68 16, tab 7
  2215.   text "Name", 172, 192 72 34 16, tab 7
  2216.   edit "", 803, 232 68 120 21, tab 7 read
  2217.   edit "", 802, 188 92 204 49, tab 7 read multi autovs
  2218.   box "Default Respond Method", 180, 184 244 216 44, tab 7
  2219.   combo 181, 200 260 184 100, tab 7 size drop
  2220.   box "Command Attributes", 176, 184 32 216 212, tab 7
  2221.   button Cancel, 101, 366 326 40 20, cancel
  2222.   button OK, 100, 409 326 40 20, ok
  2223.   button Apply, 102, 324 326 40 20
  2224.   link $nopath($trivia.web), 518, 364 304 72 16
  2225. }
  2226. ;########################################################
  2227. ;# DIALOG EVENTS.                                       #
  2228. ;########################################################
  2229. on *:dialog:trivset:init:*:{
  2230.   var %i = 1
  2231.   while ($getset(chan, %i)) {
  2232.     did -a $dname 108 $gettok($getset(chan, %i), 1, 59)
  2233.     inc %i
  2234.   }
  2235.   if ($did(108,1)) { did -c $dname 108 1 }
  2236.   var %i = $numtok($status.toks, $asc(.))
  2237.   while (%i >= 1) {
  2238.     if ($getset(status, $gettok($status.toks, %i, $asc(.))) == 1) { did -c $dname $calc(39 + %i) }
  2239.     dec %i
  2240.   }
  2241.   if (!$did(58).state) {
  2242.     if (!$getset(status, plot)) { did -c $dname 130 }
  2243.     else { did -c $dname 129 }
  2244.   }
  2245.   if ($getset(trivia,ranks) == 1) { did -c $dname 148 }
  2246.   if ($getset(status,naoff) == 1) { did -c $dname 88 }
  2247.   if ($getset(status,hintpause) == 1) { did -c $dname 96 }
  2248.   if ($getset(status,autostart) == 1) { did -c $dname 49 }
  2249.   if ($getset(status,monday) == 1) { did -c $dname 126 }
  2250.   if ($getset(status,noautoqm) == 1) { did -c $dname 830 }
  2251.   if ($getset(status,noawards) == 1) { did -c $dname 819 }
  2252.   if ($getset(status,nospellfix) == 1) { did -c $dname 817 }
  2253.   if ($getset(status,sayhintnum) == 1) { did -c $dname 147 }
  2254.   if ($getset(status,keepask) == 1) { did -c $dname 156 }
  2255.   if ($getset(status,shownone) == 1) { did -c $dname 143 }
  2256.   did -c $dname $calc(149 + $getset(trivia,firsthint))
  2257.   if ($getset(hide,score) == 1) { did -c $dname 106 }
  2258.   if ($getset(hide,time) == 1) { did -c $dname 169 }
  2259.   if ($getset(hide,streak) == 1) { did -c $dname 171 }
  2260.   if ($getset(hide,wpm) == 1) { did -c $dname 173 }
  2261.   if ($getset(color,on) == 1) { did -c $dname 116 }
  2262.   if ($getset(color,bon) == 1) { did -c $dname 158 }
  2263.   if ($getset(color,1-bold) == 1) { did -c $dname 117 }
  2264.   if ($getset(color,1-underline) == 1) { did -c $dname 118 }
  2265.   if ($getset(color,2-bold) == 1) { did -c $dname 127 }
  2266.   if ($getset(color,2-underline) == 1) { did -c $dname 128 }
  2267.   if ($getset(trivia,odefault) == Unlimited) { did -c $dname 201 }
  2268.   elseif ($getset(trivia,odefault) == Team) { did -c $dname 202 }
  2269.   else { did -c $dname 203 }
  2270.   if ($getset(team,Joinbeforeon) == 1) { did -c $dname 330 }
  2271.   if ($getset(team,4-team) == 1) {
  2272.     trivset.teams 1
  2273.     did -c $dname 29
  2274.   }
  2275.   else { did -c $dname 28 }
  2276.   var %i = 0
  2277.   while (%i <= 16) {
  2278.     did -a $dname 111,112,113,114 $colorcode(%i)
  2279.     inc %i
  2280.   }
  2281.   did -a $dname 806 Default
  2282.   did -a $dname 806 User
  2283.   did -a $dname 806 Voice
  2284.   did -a $dname 806 Half-Op
  2285.   did -a $dname 806 Op
  2286.   did -a $dname 806 Friend
  2287.   did -a $dname 806 Nobody
  2288.   did -c $dname 806 1
  2289.   did -a $dname 183 Day
  2290.   did -a $dname 183 Week
  2291.   did -a $dname 183 Month
  2292.   did -a $dname 183 Year
  2293.   did -a $dname 183 Total
  2294.   did -c $dname 183 $ifd($getset(status,scoreby),5)
  2295.   did -a $dname 181,809 Default
  2296.   did -a $dname 181,809 Notice
  2297.   did -a $dname 181,809 MSG Channel
  2298.   did -a $dname 181,809 MSG User
  2299.   did -a $dname 181,809 Describe Channel
  2300.   did -c $dname 181 $ifd($getset(status,respondlevel),1)
  2301.   did -c $dname 809 1
  2302.   did -c $dname 111 $calc($did(121) + 1)
  2303.   did -c $dname 112 $calc($did(122) + 1)
  2304.   did -c $dname 113 $calc($did(123) + 1)
  2305.   did -c $dname 114 $calc($did(124) + 1)
  2306.   awards.load
  2307.   var %i = 1
  2308.   while ($setini(banned,%i)) {
  2309.     did -a $dname 601 $getset(banned,%i)
  2310.     inc %i
  2311.   }
  2312.   did -a $dname 961 $iif($chr($triv(ch)),$chr($triv(ch)),_)
  2313.   disable.load
  2314.   trivia.load.friends
  2315.   check.toggle.multichan
  2316.   check.toggle.options
  2317.   check.color.toggle
  2318.   check.awards.toggle
  2319.   multichan.load
  2320. }
  2321. on *:dialog:trivset:sclick:100,102:{
  2322.   setset trivia delimiter $did(31)
  2323.   setset trivia additions $did(32)
  2324.   setset trivia report $did(33)
  2325.   setset trivia dir $did(35)
  2326.   setset trivia translate $did(131)
  2327.   setset status plot $did(129).state
  2328.   setset status naoff $did(88).state
  2329.   setset status monday $did(126).state
  2330.   setset status noautoqm $did(830).state
  2331.   setset status noawards $did(819).state
  2332.   setset status nospellfix $did(817).state
  2333.   setset status sayhintnum $did(147).state
  2334.   setset status keepask $did(156).state
  2335.   setset status shownone $did(143).state
  2336.   setset hide score $did(106).state
  2337.   setset hide time $did(169).state
  2338.   setset hide streak $did(171).state
  2339.   setset hide wpm $did(173).state
  2340.   setset trivia naoff $did(89)
  2341.   setset status hintpause $did(96).state
  2342.   setset trivia hintpause $did(97)
  2343.   setset trivia limitguess $did(144)
  2344.   setset trivia perchint $did(99)
  2345.   setset trivia numhint $did(861)
  2346.   setset trivia DPH $did(863)
  2347.   setset trivia PPQ $did(65)
  2348.   var %i = 0
  2349.   while (%i < 4) {
  2350.     if ($did($calc(149 + %i)).state == 1) setset trivia firsthint %i
  2351.     inc %i
  2352.   }
  2353.   setset trivia ranks $did(148).state
  2354.   setset color on $did(116).state
  2355.   setset color bon $did(158).state
  2356.   setset color 1-bold $did(117).state
  2357.   setset color 1-underline $did(118).state
  2358.   setset color 2-bold $did(127).state
  2359.   setset color 2-underline $did(128).state
  2360.   setset team JoinBeforeon $did(330).state
  2361.   setset team Joinbefore $did(335)
  2362.   setset color 1 $int($did(121))
  2363.   setset color 2 $int($did(122))
  2364.   setset color 3 $int($did(123))
  2365.   setset color 4 $int($did(124))
  2366.   varcolors
  2367.   var %i = 1
  2368.   while (%i <= 8) {
  2369.     setset lag $gettok(start.answered.timedout.hint.timed.hintallow.ping.betweenhint, %i, $asc(.)) $int($did($calc(125 + (%i * 10))))
  2370.     inc %i
  2371.   }
  2372.   var %i = $numtok($status.toks, $asc(.))
  2373.   while (%i >= 1) {
  2374.     setset status $gettok($status.toks, %i, $asc(.)) $did($calc(39 + %i)).state
  2375.     dec %i
  2376.   }
  2377.   setset trivia onjoin $did(138)
  2378.   setset trivia default $int($did(299))
  2379.   setset trivia odefault
  2380.   if ($did(201).state == 1) { setset trivia odefault Unlimited }
  2381.   if ($did(202).state == 1) { setset trivia odefault Team }
  2382.   setset trivia reset $int($did(215))
  2383.   setset trivia dteam $int($did(217))
  2384.   setset award
  2385.   var %i = 1
  2386.   while (%i <= $did(420).lines) {
  2387.     setset award %i $did(420,%i)
  2388.     inc %i
  2389.   }
  2390.   setset team 1 $did(380)
  2391.   setset team 2 $did(381)
  2392.   setset team 3 $did(382)
  2393.   setset team 4 $did(383)
  2394.   setset team 0victory $did(320)
  2395.   setset team 1victory $did(321)
  2396.   setset team 2victory $did(322)
  2397.   setset team 3victory $did(323)
  2398.   setset team 4victory $did(324)
  2399.   setset team 4-team $did(29).state
  2400.   var %i = 1
  2401.   setset trivia ch $asc($right($did(961),1))
  2402.   %command-prefix = $did(850)
  2403.   disable.save
  2404.   setset status respondlevel $did(181).sel
  2405.   setset status scoreby $did(183).sel
  2406. }
  2407. on *:dialog:trivset:sclick:816:{
  2408.   setset disable 18.disable $did($did).state
  2409.   check.toggle.options
  2410. }
  2411. on *:dialog:trivset:sclick:12:{
  2412.   if ((!$did(34).sel) || (!$did(108).sel)) { return }
  2413.   var %todel = $did(34).sel
  2414.   did -d $dname 34 %todel
  2415.   did -c $dname 34 %todel
  2416.   save.qs
  2417. }
  2418. on *:dialog:trivset:sclick:24:{
  2419.   var %temp.file = $$sfile($iif($isdir($did(35)),$did(35),$mircdir))
  2420.   did -a $dname 34 $nopath(%temp.file)
  2421.   did -ra $dname 35 $nofile(%temp.file)
  2422.   save.qs
  2423. }
  2424. on *:dialog:trivset:edit:30:{
  2425.   var %temp.num = $did(108).sel
  2426.   tchan.set $did(108).sel 1 $did(30)
  2427.   did -o $dname 108 $did(108).sel $did(30)
  2428.   did -c $dname 108 %temp.num
  2429. }
  2430. on *:dialog:trivset:sclick:108:{ multichan.load }
  2431. on *:dialog:trivset:sclick:115:{
  2432.   var %toadd = $$?="Add what channel?"
  2433.   did -a $dname 108 %toadd
  2434.   chan.add %toadd
  2435. }
  2436. on *:dialog:trivset:sclick:119:{
  2437.   var %todel = $did(108).sel
  2438.   chan.del %todel
  2439.   did -d $dname 108 %todel
  2440.   did -c $dname 108 %todel
  2441.   did -r $dname 30,34,132
  2442.   multichan.load
  2443.   check.toggle.multichan
  2444. }
  2445. on *:dialog:trivset:sclick:136:{
  2446.   var %temp.file = $$sfile($mircdir $+ \ $+ *.txt, Choose a trivia translation file.)
  2447.   did -ra $dname 131 $nopath(%temp.file)
  2448. }
  2449. on *:dialog:trivset:sclick:13:{
  2450.   var %temp.file = $$sdir($mircdir, Choose a trivia directory.)
  2451.   did -ra $dname 35 %temp.file
  2452. }
  2453. on *:dialog:trivset:edit:132:{ tchan.set $$did(108).sel 4 $$did(132) }
  2454. on *:dialog:trivset:edit:67:{ tchan.set $$did(108).sel 2 $$did(67) }
  2455. on *:dialog:trivset:edit:544:{ tchan.set $$did(108).sel 3 $$did(544) }
  2456. on *:dialog:trivset:sclick:141:{
  2457.   did -ra $dname 132 $nopath($$sfile($mircdir $+ *.fil,Choose a scores file.))
  2458.   tchan.set $$did(108).sel 4 $did(132)
  2459. }
  2460. ;########################################################
  2461. ;# MOUSE EVENTS.                                        #
  2462. ;########################################################
  2463. on *:dialog:trivset:mouse:40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,88,96,106,126,143,156,169,171,173,817,830:{
  2464.   if (%didt == $did) { return }
  2465.   if ($did == 43) { exp Forbids any partial matches, for example if the answer is "truck" and you guess "not a truck" it won't take the answer. }
  2466.   if ($did == 44) { exp Disables the decheater feature, which might produce blocks between words or odd characters on some fonts. Prevents people from using some cheating scripts. }
  2467.   if ($did == 50) { exp Disables bonus. For example if a question is "2004: This picture won movie of the year-" the bot would take this question to be worth 2004 points. }
  2468.   if ($did == 54) { exp If the room is empty the bot turns off. }
  2469.   if ($did == 61) { exp Turns off the color shortening. Color shortening is a feature which reduces the amount of text sent by optimizing the colorcodes. }
  2470.   if ($did == 62) { exp Turns off categories. If categories exist in a question file #Category after a list of questions, it doesn't look for or display it. }
  2471.   if ($did == 106) { exp Hide score. Refuses to indicate how many more points any person has. }
  2472.   if ($did == 169) { exp Hide time. Refuses to indicate how long it took for any person to answer. }
  2473.   if ($did == 171) { exp Hide streak. Refuses to indicate the current or record streak. }
  2474.   if ($did == 173) { exp Hide WPM. Refuses to indicate the Words Per Minute people achieve. }
  2475.   if ($did == 40) { exp Echo's the answer so that you can see it after the question is read. }
  2476.   if ($did == 60) { exp Uses the American dating style for the $pre $+ stats response. MM/DD/YY rather than DD/MM/YY. }
  2477.   if ($did == 63) { exp Stops showing the number before the question in the question message. }
  2478.   if ($did == 48) { exp Traditional win provides more less clinical information about the correct answer. }
  2479.   if ($did == 56) { exp Provides the spacing of the answer directly after the question is read. }
  2480.   if ($did == 46) { exp Gives a message to each person who joins the trivia channel, providing information about the bot. * = nick,  $chr(35) = channel, @ = rank, ^ = score. eg: Welcome to #, * trivia bot is active... "!trivia" to start a game. Blank uses default. }
  2481.   if ($did == 53) { exp For scramble questions, this forces the standard scramble category to read Unscramble the Following. }
  2482.   if ($did == 57) { exp Rather than accept answers anywhere in a response, this feature forces the bot to ignore answered contained entirely inside a response. }
  2483.   if ($did == 49) { exp This feature makes the bot start up as soon as you rejoin the trivia channel. }
  2484.   if ($did == 42) { exp This allows for champ mode, when a specific score is reached the game resets the score and logs the winner. }
  2485.   if ($did == 58) { exp Rather than start the hint from left to right it displays random letters in the hint. }
  2486.   if ($did == 41) { exp This feature automaticly displays a hint to the channel after a time specified in Defaults. }
  2487.   if ($did == 45) { exp This allows people to be told the correct answer after nobody in the room answered correctly. }
  2488.   if ($did == 55) { exp When a team game is ends this provides a list of players on each team. }
  2489.   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. }
  2490.   if ($did == 88) { exp After a specified number of questions, the bot will turn itself off. }
  2491.   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. }
  2492.   if ($did == 47) { exp This allows for unfinished part of a hint to use a specific character to indicate where letters are missing. }
  2493.   if ($did == 51) { exp This option limits the number of guesses to the specific value. }
  2494.   if ($did == 52) { exp This option makes a round hall of fame displayed along with the win messages throughout a trivia round. }
  2495.   if ($did == 156) { exp This feature retains the hash table that scores the asked questions beyond one round of trivia. Make repeats happen less often. }
  2496.   if ($did == 143) { exp After a win, this feature would will turn off any acknowledgement of the answer to the room. Protect questions. }
  2497.   if ($did == 126) { exp In the United States and other countries the week starts on Sunday, this is default. This feature starts the week mark a day later. }
  2498.   if ($did == 817) { exp Turns off the spell correction and only allows exact answers to be accepted. }
  2499.   if ($did == 830) { exp Turns off the automatic ? at the end of each question. A - at the end of the question also does this. }
  2500.   set -u5 %didt $did
  2501. }
  2502. alias exp { did -ra $dname 22 $$1- }
  2503. ;########################################################
  2504. ;# Stray.                                               #
  2505. ;########################################################
  2506. on *:dialog:trivset:sclick:20:{ if (!$dialog(trivrank)) dialog -m trivrank trivrank }
  2507. on *:dialog:trivset:sclick:28,29:{ trivset.teams $iif($did != 28,1) }
  2508. alias hint.example { return This is an example of a hint }
  2509. on *:dialog:trivset:sclick:58,129,130:{
  2510.   if ($did == 58) { did -ra $dname 199 $scatter(50,$hint.example) }
  2511.   else if ($did == 129) { did -ra $dname 199 $plot(50,$hint.example) }
  2512.   else { did -ra $dname 199 $standard(50,$hint.example) }
  2513. }
  2514. on *:dialog:trivset:sclick:111,112,113,114:{ did -ra $dname $calc($did + 10) $calc($did($did).sel - 1) }
  2515. on *:dialog:trivset:sclick:218:{
  2516.   var %record = $calc($triv(Record) + 1)
  2517.   if (%record == 9) { var %record = 1 }
  2518.   did -ra $dname $did $record.type(%record)
  2519.   setset Trivia Record %record
  2520. }
  2521. ;########################################################
  2522. ;# Awards.                                              #
  2523. ;########################################################
  2524. on *:dialog:trivset:sclick:412:{
  2525.   did -a $dname 420 0 0 0 0 0 Award
  2526.   did -c $dname 420 $did(420).lines
  2527.   check.award.click
  2528. }
  2529. on *:dialog:trivset:sclick:411:{ did -d $dname 420 $$did(420,1).sel | check.awards.toggle }
  2530. on *:dialog:trivset:sclick:420:{ check.award.click }
  2531. alias check.award.click {
  2532.   check.awards.toggle
  2533.   tokenize 32 $$did(420).seltext
  2534.   did -c $dname 137 $calc($1 + 1)
  2535.   did -c $dname 159 $calc($2 + 1)
  2536.   did -c $dname 166 $calc($3 + 1)
  2537.   did -ra $dname 139 $4
  2538.   did -ra $dname 161 $5
  2539.   did -ra $dname 142 $6-
  2540.   check.award.range
  2541. }
  2542. alias check.award.range {
  2543.   did $iif((($did(159).seltext == Between) || ($did(159).seltext == Random)),-v,-h) $dname 160,161
  2544. }
  2545. on *:dialog:trivset:sclick:137,159,166:{ award.modified }
  2546. on *:dialog:trivset:edit:139,142,161:{ award.modified }
  2547. alias award.modified {
  2548.   if (!$did(420).sel) { return }
  2549.   var %t.line = $did(420).sel
  2550.   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)
  2551.   did -c $dname 420 %t.line
  2552.   check.award.range
  2553. }
  2554. ;########################################################
  2555. ;# Settings.                                            #
  2556. ;########################################################
  2557. on *:dialog:trivset:sclick:515:{
  2558.   if ($?!="Are you sure you wish to delete all scores?") {
  2559.     rename $scoresfil $asctime(yymmddhhmmss) $+ .bak
  2560.     trivia.flush
  2561.   }
  2562. }
  2563. on *:dialog:trivset:sclick:518:{ run $trivia.web }
  2564. on *:dialog:trivset:sclick:519:{ dialog -m triviascores triviascores }
  2565. on *:dialog:trivset:sclick:602:{
  2566.   tunban $did(601,1).sel
  2567.   did -d $dname 601 $$did(601,1).sel
  2568. }
  2569. on *:dialog:trivset:sclick:603:{
  2570.   var %ban = $$?"Enter the nick or address (nick!ident@host) of a person to ban, note wildcards are permitted."
  2571.   tban %ban
  2572.   did -a $dname 601 %ban
  2573. }
  2574. on *:dialog:trivset:sclick:611:{
  2575.   var %friend.add = $$?"Enter the nick or address (nick!ident@host) of a friend to add, note wildcards are permitted."
  2576.   did -a $dname 610 %friend.add
  2577.   triviafriend.add %friend.add
  2578. }
  2579. on *:dialog:trivset:sclick:612:{
  2580.   triviafriend.del $$did(610).sel
  2581.   trivia.load.friends
  2582. }
  2583. on *:dialog:trivset:sclick:700:{ if (!$dialog(triviatheme)) { dialog -m triviatheme triviatheme } }
  2584. on *:dialog:trivset:sclick:157:{ if (!$dialog(trivbuild)) { dialog -m trivbuild trivbuild } }
  2585. ;########################################################
  2586. ;# Disables                                             #
  2587. ;########################################################
  2588. on *:dialog:trivset:sclick:800:{
  2589.   disable.access
  2590.   disable.check.disabled
  2591. }
  2592. on *:dialog:trivset:sclick:801:{
  2593.   setset disable $$did(800).sel $+ .disable $did($did).state
  2594.   did -oc $dname 800 $did(800).sel $gettok($disable.tokens,$did(800).sel,$asc(;)) $iif($getset(disable,$did(800).sel $+ .disable),( $+ Disabled $+ ))
  2595.   disable.check.disabled
  2596. }
  2597. on *:dialog:trivset:sclick:806:{ setset disable $$did(800).sel $+ .limitlevel $did($did).sel }
  2598. on *:dialog:trivset:sclick:809:{ setset disable $$did(800).sel $+ .respondlevel $did($did).sel }
  2599. alias disable.access {
  2600.   did $iif($getset(disable,$did(800).sel $+ .disable) == 1,-c,-u) trivset 801
  2601.   did -ra trivset 802 $gettok($disable.info.tokens,$did(800).sel,$asc(;))
  2602.   did -ra trivset 803 $did(800).seltext
  2603.   did -c trivset 806 $ifd($getset(disable,$did(800).sel $+ .limitlevel),1)
  2604.   did -c trivset 809 $ifd($getset(disable,$did(800).sel $+ .respondlevel),1)
  2605. }
  2606. alias disable.check.disabled { did $iif(!$did(801).state,-e,-b) $dname 802,803,806,809 }
  2607. alias disable.save { }
  2608. alias disable.load {
  2609.   did -r trivset 800
  2610.   tokenize $asc(;) $disable.tokens
  2611.   var %i = 1
  2612.   while (%i <= $0) {
  2613.     did -a trivset 800 $eval($ $+ %i,2) $iif($getset(disable,%i $+ .disable),( $+ Disabled $+ ))
  2614.     inc %i
  2615.   }
  2616. }
  2617. alias disable.tokens { return trivia N;trivia unlimited;trivia team;trivia team N;pause/resume;op;op unban;hof;hoftime;hofstreak;hofwpm;records;op find;op ask;next;answer;ping;themes;add/report;op ban;disable/enable;hint;vowels;last;words;repeat;op add;trivia;strivia;promotion;join message }
  2618. alias disable.info.tokens { return Start N question game;Start unlimited Game;Start team game;Start team game for N questions;pause/resume;operator commands;op unban;hall of fame;hoftime;hofstreak;hofwpm;records;op find;op ask;End current question early;Answer to last question;ping;themes;add/report;op ban;disable/enable;hint;vowels;last;words;repeat;op add;trivia;strivia;promotion;join channel message }
  2619. alias isdis {
  2620.   check.respond $1
  2621.   if ($getset(disable, $1 $+ .disable) == 1) { return $true }
  2622.   if (($chan) && ($nick) && (!$trivia.allowed($1))) { return $true }
  2623. }
  2624. alias -l trivia.allowed {
  2625.   var %level = $getset(disable,$$1 $+ .limitlevel)
  2626.   if ((!%level) || (%level == 1)) {
  2627.     %level = 1
  2628.     if ($1 == 6) %level = 4
  2629.   }
  2630.   if (%level == 7) { return }
  2631.   if (($is.friend) && (%level <= 6)) { return $true }
  2632.   if (($nick isop $chan) && (%level <= 5))  { return $true }
  2633.   if (($nick ishelp $chan) && (%level <= 4)) { return $true }
  2634.   if (($nick isvoice $chan) && (%level <= 3))  { return $true }
  2635.   if (($nick ison $chan) && (%level <= 2))  { return $true }
  2636. }
  2637. alias -l check.respond {
  2638.   unset %respond
  2639.   var %respondlevel = $getset(disable,$1 $+ .respondlevel)
  2640.   if (%respondlevel == 2) set -u2 %respond .notice $nick
  2641.   else if (%respondlevel == 3) set -u2 %respond msg $chan
  2642.   else if (%respondlevel == 4) set -u2 %respond .msg $nick
  2643.   else if (%respondlevel == 5) set -u2 %respond describe $chan
  2644. }
  2645. ;########################################################
  2646. ;# DIALOG TOGGLES                                       #
  2647. ;########################################################
  2648. on *:dialog:trivset:sclick:158,116:{ check.color.toggle }
  2649. on *:dialog:trivset:sclick:88,96,51,47,42,330,819,148,46,182:{ check.toggle.options }
  2650. alias check.toggle.options {
  2651.   did $iif($did(88).state,-e,-b) $dname 89
  2652.   did $iif($did(96).state,-e,-b) $dname 97
  2653.   did $iif($did(51).state,-e,-b) $dname 144
  2654.   did $iif($did(47).state,-e,-b) $dname 961,21
  2655.   did $iif($did(42).state,-e,-b) $dname 215
  2656.   did $iif($did(330).state,-e,-b) $dname 335
  2657.   did $iif(!$did(816).state,-e,-b) $dname 700
  2658.   did $iif($did(148).state,-e,-b) $dname 20
  2659.   did $iif($did(46).state,-e,-b) $dname 138
  2660.   did $iif($did(182).state,-e,-b) $dname 183
  2661.   if (($did == 819) || (!$did)) {
  2662.     did $iif(!$did(819).state,-e,-b) $dname 420,411,412
  2663.     did -u $dname 420
  2664.     check.awards.toggle
  2665.   }
  2666. }
  2667. 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 }
  2668. alias check.toggle.multichan { did $iif($did(108).sel,-e,-b) $dname 12,24,30,34,132,141,544,67 }
  2669. alias check.color.toggle {
  2670.   did $iif($did(116).state,-e,-b) $dname 23,25,120,110,121,122,123,124,117,118,127,128,111,112,113,114
  2671.   if (!$did(158).state) did -b $dname 25,123,124,113,114
  2672. }
  2673. ;########################################################
  2674. ;# TRIVIA SETUP, alias expanded.                        #
  2675. ;########################################################
  2676. alias save.qs {
  2677.   var %i = 1
  2678.   tchan.noqs $$did(108).sel
  2679.   while (%i <= $did(34).lines) {
  2680.     tchan.set $did(108).sel $calc(4 + %i) $did(34,%i)
  2681.     inc %i
  2682.   }
  2683. }
  2684. alias status.toks { return echo.autohint.champ.exactmatch.nodecheater.showanswer.onjoin.cross.tradwin.autostart.nobonus.limitguess.rrs.sayscramble.emptyoff.noshowt.answers.nomid.scatter.showmatched.adate.nocolorshort.nocat.nosaycurrent }
  2685. alias chan.add { tchan.set $calc($setini(chan,0) + 1) 1 $1- }
  2686. alias chan.set {
  2687.   var %chan.num = $tfindchan($1)
  2688.   if (%chan.num) { tchan.set %chan.num $2 $3- }
  2689. }
  2690. alias chan.del {
  2691.   var %i = $$1, %j = $setini(chan,0)
  2692.   while (%i < %j) {
  2693.     setset chan %i $getset(chan,$calc(%i + 1))
  2694.     inc %i
  2695.   }
  2696.   setset chan %j
  2697. }
  2698. alias tchan.noqs { setset chan $1 $gettok($getset(chan, $1),1-4,59) }
  2699. alias tchan.set {
  2700.   if ($3- != $null) {
  2701.     var %nl = $getset(chan,$1)
  2702.     if (!%nl) { %nl = $1 $+ ;*;*; $+ $scoresfil $+ ; $+ questions.txt }
  2703.     if ($2 > $numtok(%nl,59)) %nl = %nl $+ $str(;0,$calc($2 - $numtok(%nl,59)))
  2704.     %nl = $puttok(%nl,$3-,$2,59)
  2705.     setset chan $1 %nl
  2706.   }
  2707. }
  2708. alias tfindchan {
  2709.   var %i = 1
  2710.   while ($tchan(%i)) {
  2711.     if (((!$1) || ($tchan(%i) == $1)) && ((!$2) || ($tchan(%i,3) iswm $2)) && ((!$3) || ($tchan(%i,2) iswm $3))) { return %i }
  2712.     inc %i
  2713.   }
  2714. }
  2715. alias multichan.load {
  2716.   if (!$did(108).sel) { return }
  2717.   did -r $dname 34
  2718.   did -ra $dname 30 $tchan($did(108).sel)
  2719.   did -ra $dname 67 $ifd($tchan($did(108).sel,2),*)
  2720.   did -ra $dname 544 $ifd($tchan($did(108).sel,3),*)
  2721.   did -ra $dname 132 $tchan($did(108).sel,4)
  2722.   var %i = 5
  2723.   while ($tchan($did(108).sel, %i)) {
  2724.     did -a $dname 34 $tchan($did(108).sel,%i)
  2725.     inc %i
  2726.   }
  2727.   check.toggle.multichan
  2728. }
  2729. alias awards.load {
  2730.   var %i = 1
  2731.   did -r $dname 420
  2732.   while ($aw(%i)) {
  2733.     did -a $dname 420 $aw(%i)
  2734.     inc %i
  2735.   }
  2736.   did -r $dname 137,159,166
  2737.   %i = 1
  2738.   while ($gettok($award.on.tok, %i, $asc(.))) {
  2739.     did -a $dname 137 $gettok($award.on.tok, %i, $asc(.))
  2740.     inc %i
  2741.   }
  2742.   %i = 1
  2743.   while ($gettok($award.val.tok, %i, $asc(.))) {
  2744.     did -a $dname 159 $gettok($award.val.tok, %i, $asc(.))
  2745.     inc %i
  2746.   }
  2747.   %i = 1
  2748.   while ($gettok($award.do.tok, %i, $asc(.))) {
  2749.     did -a $dname 166 $gettok($award.do.tok, %i, $asc(.))
  2750.     inc %i
  2751.   }
  2752. }
  2753. alias -l record.type { return $gettok(hof.streak.time.wpm.champ.web.roundscores.records, $ifd($1, 8), $asc(.)) }
  2754. alias -l trivset.teams { did $iif($1, -e, -b) $dname 308,309,303,304,382,383,323,324 }
  2755. alias triviafriend.del {
  2756.   var %i = $$1, %j = $setini(friend,0)
  2757.   while (%i < %j) {
  2758.     setset friend %i $getset(friend,$calc(%i + 1))
  2759.     inc %i
  2760.   }
  2761.   setset friend %j
  2762. }
  2763. alias triviafriend.add {
  2764.   var %i = 1
  2765.   while ($getset(friend, %i)) { inc %i }
  2766.   setset friend %i $1-
  2767. }
  2768. alias triviafriend.clear { setset friend }
  2769. alias trivia.load.friends {
  2770.   did -r $dname 610
  2771.   var %i = 1
  2772.   while ($getset(friend, %i)) {
  2773.     did -a $dname 610 $getset(friend, %i)
  2774.     inc %i
  2775.   }
  2776. }
  2777. ;########################################################
  2778. ;# TRIVIA RANKS DIALOG.                                 #
  2779. ;########################################################
  2780. dialog trivrank {
  2781.   title "Trivia Ranks"
  2782.   size -1 -1 180 104
  2783.   option dbu
  2784.   list 1, 2 12 146 50, size
  2785.   text "Rank Name", 11, 4 66 31 8
  2786.   edit "", 2, 46 64 74 10, multi autohs
  2787.   text "Points Required", 10, 4 76 39 8
  2788.   edit "", 3, 46 76 36 10, read multi autohs
  2789.   button "Add", 4, 150 12 21 8
  2790.   button "Del", 5, 150 24 21 8
  2791.   button "Ok", 999, 114 78 17 8, ok
  2792.   check "Trivia Ranks", 6, 4 4 50 6
  2793. }
  2794. ;########################################################
  2795. ;# DIALOG EVENTS.                                       #
  2796. ;########################################################
  2797. on *:dialog:trivrank:init:*:{
  2798.   if ($getset(trivia,ranks) == 1) { did -c $dname 6 }
  2799.   check.toggle.ranks
  2800.   var %i = $setini(ranks,0), %j = 1
  2801.   while (%j <= %i) {
  2802.     did -a $dname 1 $setini(ranks,%j) : $getset(ranks, $setini(ranks,%j))
  2803.     inc %j
  2804.   }
  2805. }
  2806. on *:dialog:trivrank:sclick:1:{
  2807.   did -ra $dname 3 $setini(ranks, $did(1).sel)
  2808.   did -ra $dname 2 $getset(ranks, $setini(ranks, $did(1).sel))
  2809. }
  2810. on *:dialog:trivrank:edit:2:{
  2811.   if (!$did(1).sel) return
  2812.   setset ranks $$did(3) $$did(2)
  2813.   var %p = $did(1).sel
  2814.   did -o $dname 1 %p $did(3) : $did(2)
  2815.   did -c $dname 1 %p
  2816. }
  2817. on *:dialog:trivrank:sclick:4:{
  2818.   var %r = $$?="What is the minimum amount points for this rank?"
  2819.   if ((%r !isnum) || ($getset(ranks,%r))) return
  2820.   var %n = $$?="What is this rank called?"
  2821.   setset ranks %r %n
  2822.   did -a $dname 1 %r : %n
  2823. }
  2824. on *:dialog:trivrank:sclick:5:{
  2825.   var %p = $$did(1).sel
  2826.   setset ranks $$setini(ranks, %p)
  2827.   did -d $dname 1 %p
  2828.   did -r $dname 2,3
  2829. }
  2830. on *:dialog:trivrank:sclick:6:{
  2831.   setset trivia ranks $did(6).state
  2832.   check.toggle.ranks
  2833. }
  2834. alias check.toggle.ranks { did $iif($did(6).state,-e,-b) $dname 1,2,3,4,5,10,11 }
  2835. ;########################################################
  2836. ;# TRIVIA BUILD DIALOG.                                 #
  2837. ;########################################################
  2838. dialog trivbuild {
  2839.   title "Build Html"
  2840.   size -1 -1 200 232
  2841.   option dbu
  2842.   check Run FTP Batch, 1, 8 52 50 10
  2843.   edit "", 2, 10 124 86 88, multi autohs autovs
  2844.   button Ok, 99, 172 220 23 10, ok
  2845.   radio Write All Scores, 3, 80 12 50 10
  2846.   radio Write Top, 4, 132 12 34 10
  2847.   edit 25, 5, 168 12 20 10
  2848.   box Generate Scores File, 57, 76 4 118 35
  2849.   text Password, 54, 104 172 25 8
  2850.   box Ftp Batch Creator, 55, 100 124 84 88
  2851.   text Username, 53, 104 160 25 8
  2852.   text Ftp Site, 51, 104 136 25 8
  2853.   edit "", 6, 136 136 46 10, multi autohs
  2854.   text Port, 52, 104 148 25 8
  2855.   edit "", 7, 136 148 46 10, multi autohs
  2856.   edit "", 8, 136 160 46 10, multi autohs
  2857.   edit "", 9, 136 172 46 10, multi autohs
  2858.   edit "triv.htm", 11, 136 196 46 10, multi autohs
  2859.   text Filename, 56, 104 196 23 6
  2860.   text Every, 58, 8 16 17 6
  2861.   edit "", 13, 28 16 22 10, multi autohs
  2862.   text Points, 14, 52 16 17 6
  2863.   button "Cancel", 12, 144 220 23 10, cancel
  2864.   text "Directory", 50, 104 184 25 8
  2865.   edit "", 16, 136 184 46 10
  2866.   check "Announce Update", 17, 8 68 54 10
  2867.   edit "", 18, 92 48 98 10, multi autohs
  2868.   text "URL", 20, 80 48 10 7
  2869.   text "Batch File", 21, 12 116 29 8
  2870.   check "Generate Scores File", 15, 8 36 62 10
  2871.   box "On Trigger", 10, 4 4 70 102
  2872.   box "Announce Update", 19, 76 40 118 22
  2873.   check "Copy File", 22, 8 84 58 10
  2874.   box "Copy File", 23, 76 64 118 42
  2875.   edit "", 24, 100 72 90 10, multi autohs
  2876.   button "File", 25, 80 72 17 8
  2877.   button "Dir", 26, 80 92 17 8
  2878.   edit "", 27, 100 92 90 10, multi autohs
  2879.   text "TO", 28, 124 84 9 7
  2880.   box "Run FTP Batch", 29, 4 108 190 110
  2881.   edit "", 30, 116 24 74 10
  2882.   text "Generate File", 31, 80 24 33 8
  2883. }
  2884. ;########################################################
  2885. ;# TRIVIA BUILD EVENTS.                                 #
  2886. ;########################################################
  2887. on *:dialog:trivbuild:sclick:1,17,22,15,4,3:{ trivbuild.toggle.check }
  2888. on *:dialog:trivbuild:edit:13:{ trivbuild.toggle.check }
  2889. on *:dialog:trivbuild:edit:6,7,8,9,16,11:{ build.generate }
  2890. on *:dialog:trivbuild:sclick:25:{ did -ra $dname 24 $$sfile($mircdir) }
  2891. on *:dialog:trivbuild:sclick:26:{ did -ra $dname 27 $$sdir($mircdir) }
  2892. alias trivbuild.toggle.check {
  2893.   did -b $dname 1,17,15,22,4,3,5,30,18,24,27,6,7,8,9,16,2,11
  2894.   if (!$did(13)) { return }
  2895.   did -e $dname 1,17,22,15
  2896.   if ($did(1).state) {
  2897.     did -e $dname 2,6,7,8,9,16,11
  2898.     build.generate
  2899.   }
  2900.   if ($did(17).state) did -e $dname 17,18
  2901.   if ($did(22).state) did -e $dname 24,27
  2902.   if ($did(15).state) did -e $dname 3,4,30
  2903.   if ($did(4).state) did -e $dname 5
  2904. }
  2905. on *:dialog:trivbuild:init:*:{
  2906.   if ($getset(build,auto)) { did -c $dname 1 }
  2907.   if ($getset(build,web)) { did -c $dname 17 }
  2908.   if ($getset(build,copy)) { did -c $dname 22 }
  2909.   if ($getset(build,generate)) { did -c $dname 15 }
  2910.   did -c $dname $iif($getset(build,top),4,3)
  2911.   did -ra $dname 5 $getset(build,top)
  2912.   did -ra $dname 13 $getset(build,instabuild)
  2913.   did -ra $dname 18 $getset(build,web)
  2914.   did -ra $dname 30 $getset(build,genname)
  2915.   did -ra $dname 24 $getset(build,from)
  2916.   did -ra $dname 27 $getset(build,to)
  2917.   if ($getset(build,host)) { did -ra $dname 6 $getset(build,host) }
  2918.   if ($getset(build,port)) { did -ra $dname 7 $getset(build,port) }
  2919.   if ($getset(build,user)) { did -ra $dname 8 $getset(build,user) }
  2920.   if ($getset(build,pass)) { did -ra $dname 9 $decode($getset(build,pass),m) }
  2921.   if ($getset(build,dir)) { did -ra $dname 16 $getset(build,dir) }
  2922.   if ($getset(build,file)) { did -ra $dname 11 $getset(build,file) }
  2923.   build.generate
  2924.   trivbuild.toggle.check
  2925. }
  2926. on *:dialog:trivbuild:sclick:99:{
  2927.   setset build instabuild $did(13))
  2928.   setset build auto $did(1).state
  2929.   setset build generate $did(15).state
  2930.   setset build genname $did(30)
  2931.   setset build copy $did(22).state
  2932.   setset build web $iif($did(17).state, $did(18))
  2933.   setset build from $did(24)
  2934.   setset build to $did(27)
  2935.   setset build host $did(6)
  2936.   setset build port $did(7)
  2937.   setset build user $did(8)
  2938.   setset build pass $encode($did(9),m)
  2939.   setset build dir $did(16)
  2940.   setset build file $did(11)
  2941.   setset build top $iif($did(4).state,$did(5))
  2942.   setset build html $did(11)
  2943.   build.generate
  2944.   if ($did(2)) { filter -ifc $dname 2 $+(",$triv(dir),\,ftpbatch.txt,") * }
  2945. }
  2946. alias build.generate {
  2947.   did -r $dname 2
  2948.   did -i $dname 2 $did(2).lines open
  2949.   did -i $dname 2 $did(2).lines $did(6) $did(7)
  2950.   did -i $dname 2 $did(2).lines $did(8)
  2951.   did -i $dname 2 $did(2).lines $did(9)
  2952.   if ($did(16)) { did -i $dname 2 $did(2).lines cd $did(16) }
  2953.   did -i $dname 2 $did(2).lines put $shortfn($mircdir $+ $did(11))
  2954.   did -i $dname 2 $did(2).lines bye
  2955. }
  2956. ;########################################################
  2957. ;# TRIVIA THEMES DIALOG.                                #
  2958. ;########################################################
  2959. dialog triviatheme {
  2960.   title "Trivia Themes"
  2961.   size -1 -1 508 340
  2962.   option pixels
  2963.   list 1, 22 24 376 88, sort size
  2964.   button Add, 2, 410 28 50 20
  2965.   button Remove, 3, 410 62 50 20
  2966.   text Name:, 30, 242 142 60 16
  2967.   text Points per Question:, 33, 238 224 100 16
  2968.   text Hint-Point Decrease:, 34, 238 250 100 16
  2969.   edit , 11, 318 142 152 20, multi autohs
  2970.   edit , 12, 318 168 156 20, multi autohs
  2971.   edit , 13, 350 194 40 20, multi autohs
  2972.   edit , 14, 350 224 40 20, multi autohs
  2973.   edit , 15, 350 250 40 20, multi autohs
  2974.   check Team Game, 16, 402 254 72 20, push
  2975.   check Limit Guesses, 17, 402 224 72 20, push
  2976.   check Roundscores, 18, 402 196 72 20, push
  2977.   box Lag, 35, 8 124 220 208
  2978.   text Before Start, 26, 18 150 96 20
  2979.   text Between Questions (Answered), 37, 18 180 96 28
  2980.   text Given to Answer, 38, 18 214 96 20
  2981.   text Before Auto-Hint, 39, 18 244 88 20
  2982.   text Between Question (Timed Out), 40, 18 274 88 28
  2983.   edit , 19, 140 150 80 20
  2984.   edit , 20, 140 180 80 20
  2985.   edit , 21, 140 210 80 20
  2986.   edit , 22, 140 240 80 20
  2987.   edit , 23, 140 274 80 20
  2988.   edit , 24, 140 304 80 20
  2989.   button OK, 999, 430 310 40 20, ok
  2990.   text "Before hint allowed", 5, 16 308 102 16
  2991.   box "Themes", 6, 8 8 480 116
  2992.   box "Theme Features", 7, 232 124 256 160
  2993.   button "Question File", 8, 240 168 67 17
  2994.   text "Number of Questions", 4, 240 196 102 16
  2995. }
  2996. ;########################################################
  2997. ;# TRIVIA THEMES EVENTS.                                #
  2998. ;########################################################
  2999. on *:dialog:triviatheme:init:*:{
  3000.   var %i = 1
  3001.   while ($getset(triviamode $+ %i, name)) {
  3002.     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))
  3003.     inc %i
  3004.   }
  3005. }
  3006. on *:dialog:triviatheme:sclick:1:{
  3007.   did -ra triviatheme 11 $gettok($did(1).seltext, 1, $asc(;))
  3008.   did -ra triviatheme 12 $gettok($did(1).seltext, 2, $asc(;))
  3009.   did -ra triviatheme 13 $gettok($did(1).seltext, 3, $asc(;))
  3010.   did -ra triviatheme 14 $gettok($did(1).seltext, 4, $asc(;))
  3011.   did -ra triviatheme 15 $gettok($did(1).seltext, 5, $asc(;))
  3012.   did -u triviatheme 16,17,18
  3013.   if ($gettok($did(1).seltext, 6, $asc(;))) { did -c triviatheme 16 }
  3014.   if ($gettok($did(1).seltext, 7, $asc(;))) { did -c triviatheme 17 }
  3015.   if ($gettok($did(1).seltext, 8, $asc(;))) { did -c triviatheme 18 }
  3016.   did -ra triviatheme 19 $ifd($gettok($did(1).seltext, 9, $asc(;)),$slag(start))
  3017.   did -ra triviatheme 20 $ifd($gettok($did(1).seltext, 10, $asc(;)),$slag(answered))
  3018.   did -ra triviatheme 21 $ifd($gettok($did(1).seltext, 11, $asc(;)),$slag(timedout))
  3019.   did -ra triviatheme 22 $ifd($gettok($did(1).seltext, 12, $asc(;)),$slag(hint))
  3020.   did -ra triviatheme 23 $ifd($gettok($did(1).seltext, 13, $asc(;)),$slag(timed))
  3021.   did -ra triviatheme 24 $ifd($gettok($did(1).seltext, 14, $asc(;)),$slag(hintallow))
  3022. }
  3023. on *:dialog:triviatheme:sclick:2:{
  3024.   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))
  3025.   triviatheme.save
  3026. }
  3027. on *:dialog:triviatheme:sclick:3:{
  3028.   did -d triviatheme 1 $did(1).sel
  3029.   triviatheme.save
  3030. }
  3031. on *:dialog:triviatheme:sclick:8:{
  3032.   did -ra $dname 12 $nopath($$sfile($mircdir $+ *.txt,Choose a question file.))
  3033.   triviatheme.update
  3034. }
  3035. on *:dialog:triviatheme:edit:11,12,13,14,15,19,20,21,22,23,24:{ triviatheme.update }
  3036. on *:dialog:triviatheme:sclick:16,17,18:{ triviatheme.update }
  3037. on *:dialog:triviatheme:sclick:999:{ triviatheme.save }
  3038. 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)) } }
  3039. alias triviatheme.save {
  3040.   var %i = 1
  3041.   while ($getset(triviamode $+ %i,name)) {
  3042.     setset triviamode $+ %i
  3043.     inc %i
  3044.   }
  3045.   %i = 1
  3046.   while ($did(1,%i).text) {
  3047.     setset triviamode $+ %i name $gettok($did(1, %i).text,1,59)
  3048.     setset triviamode $+ %i file $gettok($did(1, %i).text,2,59)
  3049.     setset triviamode $+ %i max $gettok($did(1, %i).text,3,59)
  3050.     setset triviamode $+ %i ppq $gettok($did(1, %i).text,4,59)
  3051.     setset triviamode $+ %i dph $gettok($did(1, %i).text,5,59)
  3052.     setset triviamode $+ %i team $gettok($did(1, %i).text,6,59)
  3053.     setset triviamode $+ %i guess $gettok($did(1, %i).text,7,59)
  3054.     setset triviamode $+ %i rrs $gettok($did(1, %i).text,8,59)
  3055.     setset triviamode $+ %i lagstart $gettok($did(1, %i).text,9,59)
  3056.     setset triviamode $+ %i laganswered $gettok($did(1, %i).text,10,59)
  3057.     setset triviamode $+ %i lagtimedout $gettok($did(1, %i).text,11,59)
  3058.     setset triviamode $+ %i laghint $gettok($did(1, %i).text,12,59)
  3059.     setset triviamode $+ %i lagtimed $gettok($did(1, %i).text,13,59)
  3060.     setset triviamode $+ %i laghintallow $gettok($did(1, %i).text,14,59)
  3061.     inc %i
  3062.   }
  3063. }
  3064. ;########################################################
  3065. ;# TRIVIA SCORES DIALOG.                                #
  3066. ;########################################################
  3067. dialog triviascores {
  3068.   title "Trivia Scores"
  3069.   size -1 -1 452 288
  3070.   option pixels
  3071.   list 1, 5 20 100 200, size vsbar
  3072.   list 2, 115 20 75 200, size vsbar
  3073.   list 3, 200 20 75 200, size vsbar
  3074.   list 4, 285 20 75 200, size vsbar
  3075.   list 5, 370 20 75 200, size vsbar
  3076.   button Delete, 10, 5 225 75 20
  3077.   button Reset Score, 11, 115 225 75 20
  3078.   button Reset Streak, 12, 200 225 75 20
  3079.   button Reset Time, 13, 285 225 75 20
  3080.   button Reset WPM, 14, 370 225 75 20
  3081.   button Name, 20, 5 5 50 15
  3082.   button Score, 21, 115 5 50 15
  3083.   button Streak, 22, 200 5 50 15
  3084.   button Time, 23, 285 5 50 15
  3085.   button WPM, 24, 370 5 50 15
  3086.   button Ok, 100, 398 258 45 20, ok
  3087. }
  3088. ;########################################################
  3089. ;# TRIVIA SCORES EVENTS.                                #
  3090. ;########################################################
  3091. on 1:dialog:triviascores:init:*: { sortscores score }
  3092. alias -l sortscores {
  3093.   sort $1
  3094.   loaddata.triviascores
  3095. }
  3096. alias -l loaddata.triviascores {
  3097.   did -r $dname 1,2,3,4,5
  3098.   var %i = 1
  3099.   while ($hof(%i,1) != $null) {
  3100.     did -a $dname 1 $hof(%i,1)
  3101.     did -a $dname 2 $hof(%i,2)
  3102.     did -a $dname 3 $hof(%i,4)
  3103.     did -a $dname 4 $hof(%i,3)
  3104.     did -a $dname 5 $hof(%i,5)
  3105.     inc %i
  3106.   }
  3107. }
  3108. on 1:dialog:triviascores:sclick:1,2,3,4,5:{ did -c $dname 1,2,3,4,5 $did($did).sel }
  3109. on 1:dialog:triviascores:sclick:20,21,22,23,24: { sortscores $gettok(name.score.streak.time.wpm, $calc($did - 19), $asc(.)) }
  3110. on 1:dialog:triviascores:sclick:10: {
  3111.   deleteplayer $did(1).seltext
  3112.   if ($did(1).sel) { did -d triviascores 1,2,3,4,5 $did(1).sel }
  3113. }
  3114. on 1:dialog:triviascores:sclick:11,12,13,14: {
  3115.   setvar $did(1).seltext $gettok(score.streak.time.wpm, $calc($did - 10), 46) $iif($did == 13, 9999, 0)
  3116.   if ($did(1).sel) { did -o triviascores $calc($did - 9) $did(1).sel 0 }
  3117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement