Lottery for IRC

By newklear on Aug 29, 2018

Lottery system for IRC

with Top winners list.


Usage:
!tatamachance|!lotto|!powerball|!lottery to start the Lottery
Examples: !lotto - Will start a 10 minute long Lottery
!lotto 3600 - Will start a 1 hour or 3600 second lottery
!lotto cancel - Will cancel the Lottery draw

!toplotto - Will display the Top 10 Lottery winners
!toplotto 20 - Will display the Top 20 Lottery winners, etc.

The winner will receive Ops in channel and previous winner will be de-Opped in channel
Feel free to edit accordingly :-)

on *:LOAD: {
  $iif($exists($mircdir/Lotto),,mkdir $mircdir/Lotto)
}

on $*:TEXT:/!tatamachance|!lotto|!powerball|!lottery/:#: {
  if (%lottolen) && ($2 == cancel) {
    timerlotto? off
    unset %lotto*
    msg $chan The Lottery has been cancelled $nick $+ .
    return
  }
  if (%lotto.fl [ $+ [ $address($nick,2) ] ] >= 2) { return }
  if (!%lottolen) { 
    if ($2 > 86400) || ($2 < 60) { msg $chan Choose a number in range of: 60 - 86400 | return }
    $iif(!$2,set %lottolen 600,set %lottolen $2) 
  }
  inc -u $+ [ %lottolen ] %lotto.fl [ $+ [ $address($nick,2) ] ] 1
  if (!%lottodraw) { 
    set %lottochan $chan
    set %lottodraw $ctime
    .timerlottodraw 1 %lottolen lotto
    .timerlottodraw1 1 $calc(%lottolen + 5) unset %lotto*
  }
  if ($istok(%lotto,$nick,32)) {
    msg $chan You are already entered into the lottery $nick $+ .
    .timer2 1 1 msg $chan the Lotto Draw will take place in: $duration($timer(lottodraw).secs)
    return
  }
  msg $chan You are entered into the Lottery $nick $+ .
  .timer1 1 1 msg $chan the Lotto Draw will take place in: $duration($timer(lottodraw).secs)
  %lotto = $addtok(%lotto,$nick,32)
}

alias -l lotto {
  var %rand $r(1,$numtok(%lotto,32))
  set %prevnick %winnick
  set %winnick $gettok(%lotto,%rand,32)
  msg %lottochan The Lottery Winner is: %winnick out of $iif($numtok(%lotto,32) == 1,1 entrant.,$numtok(%lotto,32) entrants.) Congratulations!
  .timerlottodraw2 1 1 msg %lottochan You have won OP'S !!!
  var %file $mircdir\Lotto\Lotto.txt 
  ;by newklear - 2018
  if ($read(%file,s,%winnick)) { var %line $readn | var %lwins $gettok($read(%file,%line),2,32) | write -ds $+ %winnick %file | inc %lwins | write %file %winnick %lwins | msg %winnick You have won the Lotto %lwins times. }
  else { write %file %winnick 1 }
  .timerlottodraw3 1 2 mode %lottochan -o %prevnick
  .timerlottodraw4 1 3 mode %lottochan +o %winnick
}

on *:TEXT:!toplotto*:#:{ 
  if (%toplotto. [ $+ [ $address($nick,2) ] ] == 6) { halt }
  inc -u3600 %toplotto. [ $+ [ $address($nick,2) ] ] 1
  if ($2 > 30) { msg $chan Keep it 30 and below @ $nick | return }
  $iif($2,set -u30 %topwhat $2,set -u30 %topwhat 10)
  toplotto #
}

alias -l toplotto {
  var %file = $mircdir\Lotto\Lotto.txt, %l = %topwhat $+ , %d = $lines(%file), %w = @top10
  window -hn %w
  clear %w
  while %d {
    tokenize 32 $read(%file,nt,%d)
    aline %w 4 $+ $1 $+ :3 $2 $+ 10 
    dec %d
  }
  filter -cuteww 2 32 %w %w
  var %k = 1, %k1
  while %k <= %l  {
    %k1 = $addtok(%k1,$+($chr(32),12,$chr(35),%k,) $iif($line(%w,%k),$v1,),44)
    inc %k
  }
  msg $chan  12Top4 %toplotto 12Lotto Winner High Score's:
  msg $chan %k1 $+ .
}

Comments

Sign in to comment.
Karlien   -  22 days ago

Another cool one :)
However; I can't get it to display the toplotto. It just shows a white "."
I've checked and rechecked and its nearly the same as the topiq so am stumped as to why it won't show. I thought maybe conflicting variables with the topiq but changing those did nothing.

Karlien  -  22 days ago

I figured it out :)
In the "alias -l toplotto"
%toplotto needs to be %topwhat
Works like a charm now!

newklear  -  21 days ago

Thank you for that Karlien, change made in OP :-)
Apologies, I copied over the top alias without correctly editing/testing.

Karlien  -  18 days ago

Additional: had to switch the aline %w around in the toplotto alias. ($2 $1) to ($1 $2)
I've been trying to set it up so that only ops can start the lotto but I keep !!*!ing it all up lol.
Maybe if I chop it into two parts with seperate commands?... Will keep at it.

newklear  -  17 days ago

Hi Karlien, recopy the entire alias section.
It's now working as it should. My apologies once again, I uploaded this copy without testing, but tested now and it's all fine.

To only allow Ops too start it, add this:
if ($nick isop $chan) {
Under the 1st line of each text event
and add a: }
just before the last }
Hope that makes sense.

Karlien  -  10 days ago

Perfect. Thank you. I was making it way more complicated then it needed to be. lol

Sign in to comment

Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.