on *:text:!ticket *:#:{
var %owner firestonetv
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.
}
}