mIRC Homepage

I need help with a raffle

Posted By: beavisxtreme

I need help with a raffle - 30/04/14 08:15 PM

i got everything to work but the ticket roll. if i change the name that is allowed and try, it will say i'm not allowed only admins but if i change it back to my name it does nothing. Can someone please help

here is the raffle script

Quote:
on *:text:!ticket:#:{
if ($hget($+(tickets.,#),$nick)) { msg # $nick You already have a ticket! | return }
var %topic = $+(#,.,$nick)
; Check if enough points
if ($readini(Points.ini,%topic,Points) >= 1000) {
; Deduct the points
var %a = $v1 - 1000
writeini Points.ini %topic Points %a
; Add the user to tickets.#channel hash table, creating the table if it doesn't exist
hinc -m $+(tickets.,#) $nick
msg # $nick You bought a ticket, you now have %a points.
}
else msg # $nick Sorry, you only have $v1 points.
}
on *:text:!ticket roll:#:{
if ($nick == BeavisXtreme) {
if ($hget($+(tickets.,#))) {
var %i = $r(1,$hget(,0).item
msg # The winner is $hget($+(tickets.,#),%i).item
; The next line frees the table (all data in it is gone)
(hfree $+(tickets.,#))
}
else msg # Sorry $nick there is no such table $+(tickets.,#)
}
else msg # $nick Only Mods can use that command.
}

Posted By: Loki12583

Re: I need help with a raffle - 30/04/14 08:59 PM

Originally Posted By: /help on text
Note: You cannot test out these events by typing text to yourself. They can only be initiated by someone else saying something in a channel or in a private message.
Posted By: blessing

Re: I need help with a raffle - 01/05/14 04:36 AM

hinc -m $+(tickets.,#) $nick add hashtable with numbers as item and $nick as data, while you $hget($+(tickets.,#),$nick) using $nick as item which is never exists.

Also, this line var %i = $r(1,$hget(,0).item is incorrect.
Posted By: beavisxtreme

Re: I need help with a raffle - 01/05/14 02:50 PM

i know, i have a seperate account for my bot, and i use my actual channel name for testing
Posted By: beavisxtreme

Re: I need help with a raffle - 01/05/14 02:52 PM

Originally Posted By: blessing
hinc -m $+(tickets.,#) $nick add hashtable with numbers as item and $nick as data, while you $hget($+(tickets.,#),$nick) using $nick as item which is never exists.

Also, this line var %i = $r(1,$hget(,0).item is incorrect.


how would i go about fixing that i'm a complete noob at this trying to learn and thank you for you guy's input, i can buy a ticket and all that works but its the roll that does nothing i've just been banging my head and googling to no avail
Posted By: blessing

Re: I need help with a raffle - 01/05/14 03:42 PM

Change hinc -m $+(tickets.,#) $nick with hadd -m $+(tickets.,#) $nick 1 and var %i = $r(1,$hget(,0).item with var %i = $r(1,$hget($+(tickets.,#),0).item)

Also remove () from (hfree $+(tickets.,#)) --> hfree $+(tickets.,#)
Posted By: beavisxtreme

Re: I need help with a raffle - 01/05/14 04:46 PM

k ill give this a try and thanx a bunch for helping
UPDATE: OMG i love you thank you so much
Posted By: Echosyp

Re: I need help with a raffle - 23/05/14 09:14 PM

Is there any way I can make it so they can buy more than 1 ticket with their points? To give them a better chance of winning?
Posted By: blessing

Re: I need help with a raffle - 26/05/14 04:48 AM

I wrote this code some time ago. someone asked me to help him/her to turn this raffle into giveaway where users can buy tickets using points they have and also the user can buy more than one time.

Here is the code.
Code:
on *:text:!ticket *:#:{
  var %owner NICK1 NICK2 NICK3
  var %hash $+(ticket.,#) 
  if $istok(%owner,$nick,32) && $2 == on && !$hget(%hash) { 
    hmake %hash 
    msg # Ticket now is open. Use !ticket <point> to join.
  }
  elseif $2 isnum && $2 > 0 && $hget(%hash) {
    var %topic $+(#,.,$nick), %point $readini(points.ini,%topic,points)
    if %point >= $2 {
      var %p $calc(%point - $2)
      writeini points.ini %topic points %p 
      var %i $hget(%hash,0).item, %t $calc(%i + $2) 
      while %i < %t { inc %i | hadd %hash %i $nick }
      msg # $nick $+ , You bought $2 ticket, you now have %p points
    }
    else { msg # $nick Sorry, you only have %point points }
  }
  elseif $istok(%owner,$nick,32) && $2 == roll && $hget(%hash) {
    var %i $rand(1,$hget(%hash,0).data)
    msg # The winner is $hget(%hash,%i).data $+ . 
    hfree %hash
  }
}

change NICK1 NICK2 NICK3 with yournick, yourfriendnick, othernickyoutrust to do !ticket on and !ticket roll

here is how the script works.
user1 buy 20 ticket
bot will give him ticket no 1-20 (20 tickets)
user2 buy 70 ticket
bot will give him ticket no 21-90 (70 tickets)
user1 buy again 10 ticket
bot will give him ticket no 91-100 (10 tickets)
.. so on..

when you close it.
user1 has 30/100 = 30% chance to win
user2 has 70/100 = 70% chance to win

The code was tested by him/her and he/she said it works fine.
Posted By: Echosyp

Re: I need help with a raffle - 26/05/14 07:49 PM

Thanks a lot Blessing. I'm guessing !ticket roll closes the raffle.

I currently have the code you posted plus this one

Code:
on *:text:!ticket roll:#:{
  if ($nick == forgottenheroes) {
    if ($hget($+(tickets.,#))) {
      var %i = $r(1,$hget($+(tickets.,#),0).item)
      msg # The winner is $hget($+(tickets.,#),%i).item
      ; The next line frees the table (all data in it is gone)
      hfree $+(tickets.,#)
    }
    else msg # Sorry $nick there is no entries at the moment. 
  }
  else msg # $nick Only Mods can use that command.
}


But when I added in your code It not longer says Sorry there is no entries. It just says nothing. and if I do !ticket on then type !ticket roll it just says the winner is 0 since nobody entered.

My old script allowed users to do !ticket once and it would enter them into the raffle just 1 time only. Then I did !ticket roll to pick a winner.

I'm gonna have to make it more neat looking so I can do !ticket on and it lets ppl know the raffle is now accepting points. Then I can do !ticket off to let the users know the raffle has ended and not accepting any new entries. Then I can do !ticket roll it gives the winner and clears the names.
Posted By: blessing

Re: I need help with a raffle - 27/05/14 09:26 AM

This is modified version, but untested yet. It really does check here and there, responds this and that. So your channel might get flooded. You've been warned. wink

Usage:
!ticket <open/close/roll/end>

In this version, !ticket can be rolled/drawn more than one time.
Code:
on *:text:!ticket *:#:{
  var %owner NICK1 NICK2 NICK3
  var %hash $+(ticket.,#)
  if !$istok(%owner,$nick,32) && $istok(open close roll end,$2,32) { msg # You cant use this command. | return }
  if !$hget(%hash) && ($istok(close roll end,$2,32) || $2 isnum) {  msg # There is no open ticket. | return }
  if !$hget(%hash,close) && $istok(roll end,$2,32) { msg # !ticket is not closed yet. | return }
  if $hget(%hash,close) && ($2 == close || $2 isnum) { msg # !ticket is already closed by $hget(%hash,close) $+ . | return }  
  if $2 == open {
    if $hget(%hash) { msg # !ticket is still active | return }
    hmake %hash 
    msg # Ticket now is open. Use !ticket <point> to join.
  }
  if $2 isnum && $2 > 0 {
    var %topic $+(#,.,$nick), %point $readini(points.ini,%topic,points)
    if %point < $2 { msg # $nick Sorry, you only have %point points | return }
    var %p $calc(%point - $2)
    writeini points.ini %topic points %p 
    var %i $hget(%hash,0).item, %t $calc(%i + $2) 
    msg # $nick $+ , You bought $2 ticket ( no. $calc(%i + 1) - %t ), you now have %p points
    while %i < %t { inc %i | hadd %hash %i $nick }
  }
  if $2 == close {
    var %i 1 | while $hget(%hash,%i).data { var %d $addtok(%d,$v1,32) | inc %i }  
    msg # !ticket now is closed. ( total entries : $calc(%i - 1) tickets - $numtok(%d,32) users )
    hadd %hash close $nick
  }
  if $2 == roll {
    var %c $hget(%hash,close)
    hdel %hash close
    var %d $hget(%hash,0).item
    if !%d { msg # There is no ticket to draw. }
    else {
      var %i $rand(1,%d), %w $hget(%hash,%i).item
      msg # The winner is ticket no. %w ( $hget(%hash,%w) ) $+ .
      hdel %hash %w 
    }
    hadd %hash close %c
  }
  if $2 == end {
    hfree %hash
    msg # All tickets data now is cleared.
  }
}
Posted By: radmux

Re: I need help with a raffle - 29/05/14 06:11 PM

Is there a way to add commands like !raffle on and !raffle off so people can't randomly buy tickets when there's no raffle going on?

I'm pretty new to scripting.

~Arden
Posted By: startgame

Re: I need help with a raffle - 29/05/14 08:44 PM

Originally Posted By: radmux
Is there a way to add commands like !raffle on and !raffle off so people can't randomly buy tickets when there's no raffle going on?

I'm pretty new to scripting.

~Arden


I am pretty sure that every script posted here has exactly what you are looking for. They are just labeled as !ticket start and !ticket close.
Posted By: radmux

Re: I need help with a raffle - 29/05/14 09:06 PM

Here's what I have:
Code:
;Raffle System (Beavis)
on *:text:!raffle on:*: {

  if ($nick isop #) {
    .enable !ticket | /msg $chan A raffle/giveaway is now in progress. To enter the giveaway, type "!ticket"; only 1 ticket is allowed per user. Each ticket costs 200 points. Good luck!
  }
  else { msg $chan This command is only available to moderators. }

}
on *:text:!raffle off:*: {
  if ($nick isop #) {
  .disable !ticket | /msg $chan Raffle/giveaway system is now OFF. }
  else { msg $chan This command is only available to moderators. }

}
on *:text:!ticket:#:{
  if ((%floodraffle) || ($($+(%,floodraffle.,$nick),2))) { return }
  set -u3 %floodraffle On
  set -u60 %floodraffle. $+ $nick On
  if ($hget($+(tickets.,#),$nick)) { msg # $nick , you already have a ticket! | return }
  var %topic = $+(#,.,$nick)
  ; Check if enough points
  if ($readini(Points.ini,%topic,Points) >= 200) {
    ; Deduct the points
    var %a = $v1 - 200
    writeini Points.ini %topic Points %a
    ; Add the user to tickets.#channel hash table, creating the table if it doesn't exist
    hadd -m $+(tickets.,#) $nick 1
    msg # $nick spent 200 points on a raffle ticket.

  }
else msg #  Sorry $nick , you don't have enough points to join this raffle. }

on *:text:!roll:#:{
  if ($nick isop #) {
    if ($hget($+(tickets.,#))) {
      var %i = $r(1,$hget($+(tickets.,#),0).item)
      msg # The winner is $hget($+(tickets.,#),%i).item
      ; The next line frees the table (all data in it is gone)
      hfree $+(tickets.,#)
    }
    else msg # There are no ticket entries at this time. 
  }
  else msg # $nick, only moderators can use that command.
  }


Note: My on and off commands are not working for me.

Also, I don't quite understand blessing's script, but I'll give it a whirl...
Posted By: Loki12583

Re: I need help with a raffle - 29/05/14 10:23 PM

/enable is to enable groups (/help groups), not to enable or disable specific events.
Posted By: radmux

Re: I need help with a raffle - 30/05/14 01:59 AM

Originally Posted By: Loki12583
/enable is to enable groups (/help groups), not to enable or disable specific events.

Well then what can I use?

I'm new to this scripting stuff...
Posted By: blessing

Re: I need help with a raffle - 01/06/14 06:05 AM

Code:
on *:text:!raffle on:*: {

  if ($nick isop #) {
    .enable #ticket 
  }

}

#ticket off

on *:text:!ticket:#:{
  ...
}
on *:text:!roll:#:{
  ...
}

#ticket end

© 2019 mIRC Discussion Forums