alias q return $+(,10,$1-,) alias a return $+(,03,$1-,) alias h return $+(,04,$1-,) alias ssr1 return $+(,10,$1-,) alias ssr2 return $+(,06,$1-,) on *:TEXT:*:#:{ if (($nick isop $chan) || ($nick ishop $chan)) { if ($1 == !trivia) { if ($2) { if ($2 isnum) starttriv $chan $nick $2 else notice $nick u need to specify a number. } else starttriv $chan $nick } if ($1 == !strivia) stoptriv $chan $nick } if ($istok($hget($chan,answer),$1-,124)) { nextquestion $chan $nick $1- } } alias stoptriv { if (($timer($1).secs) || ($timer($+($1,nq)).secs)) { hfree $1 $+(.timer,$1,nq) off $+(.timer,$1) off msg $1 $q(Trivia ended by) $h($2) } else notice $2 there is no game in $1 } alias starttriv { if (($timer($1).secs) || ($timer($+($1,nq)).secs)) notice $2 there is already game in this channel. else { if ($3) hadd -m $1 rounds $3 msg $1 $q(Trivia was started by) $h($2) $+ $q(.) $h($iif($hget($1,rounds),$v1 Rounds.,unlimited rounds.)) hadd -m $1 qs 0 .timer $+ $1 1 5 firstq $1 } } alias displayq { hinc $1 qs 1 tokenize 64 $+($1,@,$read(questions.txt)) msg $1 $q($hget($1,qs) $+ .) $q($2) hadd -m $1 answer $3 hadd -m $1 start $ctime $+(.timer,$1) 1 15 msg $1 $q($hget($1,qs) $+ . Hint:) $h($randhint($replace($gettok($hget($1,answer),1,124),$chr(32),))) $+(.timer,$1,nq) 1 30 nextquestion $1 } alias firstq { hinc $1 qs 1 tokenize 64 $+($1,@,$read(questions.txt)) msg $1 $q($hget($1,qs) $+ .) $q($2) hadd -m $1 answer $3 hadd -m $1 start $ctime $+(.timer,$1) 1 15 msg $1 $q($hget($1,qs) $+ . Hint:) $h($randhint($replace($gettok($hget($1,answer),1,124),$chr(32),))) $+(.timer,$1,nq) 1 30 nextquestion $1 } alias nextquestion { if (!$2) { msg $1 $q(Oh no! no one got the answer! Correct:) $a($gettok($hget($1,answer),1,124)) hdel $1 streak hdel $1 start if ($timer($1).secs) $+(.timer,$1) off if ($timer($+($1,nq)).secs) $+(.timer,$1,nq) off } if ($2) { if ($hget($1,rounds)) hdec $1 rounds 1 if ($timer($1).secs) $+(.timer,$1) off if ($timer($+($1,nq)).secs) $+(.timer,$1,nq) off writeini triviascore.ini $1 $address($2,2) $calc($readini(triviascore.ini,$1,$address($2,2)) + 1) if ($hget($1,streak)) { if ($gettok($hget($1,streak),1,32) == $2) { var %streak = $calc($gettok($hget($1,streak),2,32) + 1) hdel $1 streak hadd -m $1 streak $2 %streak } else { hdel $1 streak hadd -m $1 streak $2 1 } } else { hadd -m $1 streak $2 1 } msg $1 $q(Congratz $2 You got the right answer!) $a($gettok($hget($1,answer),1,124)) msg $1 $ssr1(STREAK:) $ssr2($gettok($hget($1,streak),2,32)) $ssr1(SCORE:) $ssr2($readini(triviascore.ini,$1,$address($2,2))) $ssr1(RANK:) $ssr2($getrank($1,$2)) $ssr1(WPM:) $ssr2($base($calc(60 * ($0 - 2) / ($ctime - $hget($1,start))),10,10,0,2))) checkstreak $1 $hget($1,streak) } if ($hget($1,rounds) == 0) endround $1 $+(.timer,$1) 1 5 displayq $1 hdel $1 answer } alias endround { msg $1 $q(Stopping trivia) $q($chr(40)) $+ $h(Round limit reached) $+ $q($chr(41)) hfree $1 $+(.timer,$1,nq) off $+(.timer,$1) off } alias -l checkstreak { if ($3 == 3) describe $1 gives $2 a high five for being so good! if ($3 == 6) describe $1 passes $2 a 12 pack of soda to keep cool coz he\she's on fire. if ($3 == 10) describe $1 huggles $2 } alias -l getrank { var %r = $str(_,$ini(triviascore.ini,$1,0)), %a = 0 while (%a < $ini(triviascore.ini,$1,0)) { inc %a if ($readini(triviascore.ini,$1,$ini(triviascore.ini,$1,%a)) < $readini(triviascore.ini,$1,$address($2,2))) var %r = $left(%r,$calc($len(%r) - 1)) } return $len(%r) } alias -l randhint { var %e = $len($1),%l = $ceil($calc(.5 * %e)),%a = $replet($1) while (%l) { %f = $rand(1,%e) while ($mid(%a,%f,1) != _) %f = $rand(1,%e) %a = $+($left(%a,$calc(%f - 1)),$mid($1,%f,1),$right(%a,$calc(%e - %f))) dec %l } return $replace(%a,,$chr(32)) } alias replet { var %a = 0 while (%a < $len($1)) { inc %a var %line = %line $+ $iif($mid($1,%a,1) != ,_,$v1) } return %line } on ^*:JOIN:#:{ if ($nick == $Me) haltdef } alias msgall { var %a = $nick($active,0) + 1 while (%a > 1) { dec %a if (($nick($active,%a) isop $active) || ($nick($active,%a) ishop $active)) break notice $nick($active,%a) $1- } }