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   -  Aug 31, 2018

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  -  Aug 31, 2018

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

newklear  -  Sep 02, 2018

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

Karlien  -  Sep 04, 2018

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  -  Sep 05, 2018

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  -  Sep 13, 2018

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

natashaaboehm  -  Oct 26, 2018

And did it word? How much did you win? Interesting to see the result of using it

newklear  -  Nov 06, 2018

Yes it works ;)

Karlien  -  Jan 21, 2019

Works great, see if I can post some examples of what I did with it.
Other things in the room add to the lotto pot. Like abusing the bot, he'll take credits from you and put some in the lotto pot for the next time its active. You can also do !mylotto to see how many times you've entered and how much in total you've won per month.

!lotinfo
The Room Name Lottery: 50 credits to enter. 25 credits goes in the pot. The more entrants, the bigger the pot! To enter simply type !lotto when a lottery is active.
The winner will get: Pot credits, 1 carrot, 1 lockpick and 1 midget token.

[14:13] !lotcheck
[14:13] Last Winner: (nick here) Pot Won: 150 credits. Plus 1 carrot, 1 lockpick and 1 midget token.
[14:13] The lottery is active! Entrants: 5 Current Pot: 285 credits. The draw will take place in: 3hrs 46mins 35secs. To enter type !lotto

[14:15] !lotto
Bot takes your 50 credits, puts 25 in the pot and puts your name in the crusty hat. Check the lotto status with !lotcheck.

Hello? Mcflies? I am now randomly selecting the lottery winner.
Bot reaches into the crusty hat, pulls out a name...
and the winner is...
(winner nick here) out of (number of people here) entrants. Congratulations!
You have won: (pot credits) credits, 1 carrot, 1 lockpick, 1 midget token and a smile :)

newklear  -  Feb 04, 2019

That sounds interesting Karlien!
You should make an upload and call it V2 ;)

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.