on *:text:*:#:bet # $nick $1-
on *:nick:bet_ $nick $newnick
alias -l bet {
noop $regex($3,/^!((?:new|won)?bet)/)
var %r $regml(1)
if $istok(newbet wonbet,%r,32) && $2 !isop $1 && $2 != $me && !%bet. [ $+ [ %r ] ] {
set -u60 %bet. [ $+ [ %r ] ] 1
msg $1 $+(!,%r) is OP command.
return
}
if %r == newbet {
if %bet.q { .notice $2 Bet was already opened | return }
if !$4 || $numtok($4-,58) != 3 { .notice $2 command: !newbet <question> : <option1>,<option2>,<option3>,<etc> : <point> | return }
var %p $remove($gettok($4-,3,58),$chr(32))
if %p !isnum || %p < 1 { .notice $2 <point> was set incorrectly | return }
msg $1 [BET OPENED] $4- - Use: !bet <option> to set your bet.
set -e %bet.q $gettok($4-,1,58)
noop $regex($gettok($4-,2,58),/(\S.+$)/iS)
var %re /((:?\s+)?,(:?\s+)?)/giS
set -e %bet.a $regsubex($regml(1),%re,$chr(44))
set -e %bet.p %p
.timerbet.warn 1 90 msg $1 [BET] Bet will be closed in 30secs.
.timerbet.close 1 120 bet $1 $me !wonbet
}
if %r == bet {
if !%bet.q && !%bet.bet {
set -u60 %bet.bet 1
msg $1 [BET] There is no BET yet.
return
}
if $readini(casino.ini,$2,Money) < %bet.p {
if !$istok(%bet.point,$2,32) {
.notice $2 You dont have enough point to bet. Point required to bet is $+(<,%bet.p,>)
set -e %bet.point $addtok(%bet.point,$2,32)
}
return
}
if $wildtok(%bet.user,$+($2,*),1,215) {
if !$istok(%bet.twice,$2,32) {
.notice $2 You can't bet twice!
set -e %bet.twice $addtok(%bet.twice,$2,32)
}
return
}
if !$4 {
if !$istok(%bet.warned,$2,32) || $2 isop $1 {
.notice $2 [BET] %bet.q : %bet.a - Use: !bet <option> to set your bet.
set -e %bet.warned $addtok(%bet.warned,$2,32)
}
return
}
if !$istok(%bet.a,$4-,44) {
if !$istok(%bet.invalid,$2,32) {
.notice $2 Valid options are: %bet.a
set -e %bet.invalid $addtok(%bet.invalid,$2,32)
}
return
}
set -e %bet.user $addtok(%bet.user,$2 $4-,215)
msg $1 $+($2,'s) bet is $4-
}
if %r == wonbet {
if !%bet.q { .notice $2 There is no BET yet. | return }
var %won $iif($2 != $me,$4-,$gettok(%bet.a,$rand(1,$numtok(%bet.a,44)),44))
if !%won { .notice $2 command: !wonbet <option> | return }
if !$istok(%bet.a,%won,44) { .notice $2 Valid options are: %bet.a | return }
var %i 1
while $gettok(%bet.user,%i,215) {
var %w $v1, %n $gettok(%w,1,32), %add 0
if $+(*,%won) iswm %w && %n ison $1 { var %win %win %n, %add 1 }
if $+(*,%won) !iswm %w { var %add -1 }
writeini -n casino.ini %n Money $calc($readini(casino.ini,%n,Money) + (%bet.p * %add))
inc %i
}
msg $1 [BET CLOSED] $+(<,%won,>) was the winning option! $iif(%win,Winners are: %win - good luck for all others on the next bet!,There is no winner!)
unset %bet.*
.timerbet.* off
}
}
alias bet_ {
if %bet.q {
set -e %bet.twice $reptok(%bet.twice,$1,$2,1,32)
set -e %bet.warned $reptok(%bet.warned,$1,$2,1,32)
set -e %bet.invalid $reptok(%bet.invalid,$1,$2,1,32)
set -e %bet.point $reptok(%bet.point,$1,$2,1,32)
if $wildtok(%bet.user,$+($1,*),1,215) {
set -e %bet.user $reptok(%bet.user,$v1,$2 $gettok($v1,2-,32),215)
}
}
}