mIRC Home    About    Download    Register    News    Help

Print Thread
Bettings Script #245390 19/04/14 06:51 PM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Hey fellas,
iam looking for a small betting snippet.

Looking for something like:
!newbet Who will win this game?:Team1,Team2,Team3

Bot Answer:
[BETS OPEN] Who will win this Game? Use: !bet <Option> to set your bet.

To close the bet:
!wonbet Team1

Bot Answer:
[BETS CLOSED] Team1 was the winning Option! Winners are: User1 User2 User3 User4 User4 - good luck for all others on the next bet!



Would be awesome if someone could give me a small snippet smile

Re: Bettings Script [Re: Kawalli] #245411 20/04/14 04:38 PM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
This is interesting so i just wrote the code. Not enough testing though, but i hope it works. The difficult parts are checking here and there, so the game cannot be cheated easily, also prevent bot got flooded.

Code:
on *:text:*:#:bet # $nick $1-
on *:nick:bet_ $nick $newnick

alias bet {
  noop $regex($3,/^!((?:new|won)?bet)/)
  var %r $regml(1)
  if $istok(newbet wonbet,%r,32) && $2 !isop $1 { return }
  if %r == newbet {
    if %bet.q { .notice $2 Bet was already opened | return }
    if !$4 || $numtok($4-,58) != 2 { .notice $2 command: !newbet <question> : <option1>,<option2>,<option3>,etc | 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))
  }
  if %r == bet {
    if !%bet.q { return }
    if $wildtok(%bet.user,$+($2,*),1,215) { 
      if !$istok(%bet.twice,$2,32) {
        .notice $2 You cant 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
    }
    if !$wildtok(%bet.user,$+($2,*),1,215) {
      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 }
    if !$4 { .notice $2 command: !wonbet <option> | return }
    if !$istok(%bet.a,$4-,44) { .notice $2 Valid options are: %bet.a | return }
    var %i 1
    while $wildtok(%bet.user,$+(*,$4-),%i,215) {
      var %win %win $iif($gettok($v1,1,32) ison $1,$v1)
      inc %i
    }
    msg $1 [BET CLOSED] $+(<,$4-,>) was the winning option! Winners are: %win - good luck for all others on the next bet!
    unset %bet.*
  }
}

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)
    if $wildtok(%bet.user,$+($1,*),1,215) {
      set -e %bet.user $reptok(%bet.user,$v1,$2 $gettok($v1,2-,32),215)
    }
  }
}


Re: Bettings Script [Re: blessing] #245418 20/04/14 07:04 PM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Oh.. my ... God! Your are so awesome!!
Thank you soooo much.


I hardly dare to ask... can you add 2 options more?
It would be important that the ppl on the chan only have 120 Seconds to place bets.

And now the Hard thing, i have a own points system + a casino script, but this betting script is too much for my mirc skills ^^ Would be nice if i could setup how many coins it costs to bet! For example: !openbet Question:Option1,Option2:500

Thought about a syntax like "%costs" i dont know how to handel it to safe the users input ^^

Sure it would be nice if every user could bet their own coins and win the double of it but i dont want to make it too much work for you! laugh btw. Thank you again!


Check enough points?
Code:
if ($readini( casino.ini, $nick, Money ) < %costs) {
  msg # $nick - you dont have %costs to bet.
  halt
 } 


If they lose > they lose their betted points
If they win > they double it! Bet 500 win 1000 for example.

Write the coins:
Code:
Win
writeini -n casino.ini $nick Money $calc($readini(casino.ini,$nick,Money) +%costs)

Lose
writeini -n casino.ini $nick Money $calc($readini(casino.ini,$nick,Money) -%costs)


I hope that isnt too much LOL!



Last edited by Kawalli; 20/04/14 07:10 PM.
Re: Bettings Script [Re: Kawalli] #245433 21/04/14 02:22 PM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
This is untested.
For others, dont just copy and pasted. It would not work as this is written by request. You need to modify it to following your own point system.

Code:
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)
    }
  }
}

Re: Bettings Script [Re: blessing] #245440 21/04/14 04:12 PM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Hey blessing, first of all: Thank you!
I tested this but when i open the bet - the bet is closed right after i used the command: !newbet

If this script is loaded, the script is posting the whole time "[BET CLOSED] <> was the winning option! There is no winner!" when someone is writeing something (not even a command, only words like hi or something else laugh!)

Last edited by Kawalli; 21/04/14 04:23 PM.
Re: Bettings Script [Re: Kawalli] #245450 21/04/14 08:58 PM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Ah, I've put bracket "}" at the wrong place. Now it is fixed.

Code:
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)
    }
  }
}


Re: Bettings Script [Re: blessing] #245464 22/04/14 07:06 PM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Hey blessing, the script is nearly workin 100% fine!
Its only one Problem left...

Timer to close:

Quote:
.timerbet.warn 1 90 msg $1 [BET] Bet will be closed in 30secs.
.timerbet.close 1 120 bet $1 $me !wonbet


The Bot is closeing the Bet automatically with a random Option! So its like a mod wrote !wonbet option but i want only that the ppl cant bet anymore, not that the bet is "won" ^^

Rest is working like charme, thank you very much!

Last edited by Kawalli; 22/04/14 08:25 PM.
Re: Bettings Script [Re: blessing] #245466 22/04/14 07:28 PM
Joined: Apr 2014
Posts: 33
B
bl968 Offline
Ameglian cow
Offline
Ameglian cow
B
Joined: Apr 2014
Posts: 33
You should use hash tables it's better, simpler code and when you have a large number of entries takes less time to access than a sequential text file.

Re: Bettings Script [Re: Kawalli] #245476 23/04/14 01:24 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
I was thinking mods could cheating by choosing option that less user bet on and take point away smile
Thats why i thought it's more fair if bot just auto close and pick random option.

Here is part of the code modified to not auto !wonbet.
You need to include previous on join event, on nick event, and bet_ alias.
Code:
alias -l bet {
  noop $regex($3,/^!((?:new|won)?bet)/)
  var %r $regml(1)
  if $istok(newbet wonbet,%r,32) && $2 !isop $1 && !%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 and not closed yet. | 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 }
    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
    msg $1 [BET OPENED] Question: %bet.q :: Option: %bet.a :: Bet Point: %bet.p - Use: !bet <option> to set your bet.    
    .timerbet.warn 1 90 msg $1 [BET] Bet will be closed in 30secs. 
    .timerbet.close 1 120 set -e %bet.closed 1 | msg $1 [BET] Bet is closed.
  }
  if %r == bet && !%bet.closed {
    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 open BET yet. | return }
    if !$4 { .notice $2 command: !wonbet <option> | return }
    if !$istok(%bet.a,$4-,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 $+(*,$4-) iswm %w && %n ison $1 { var %win %win %n, %add 1 }
      if $+(*,$4-) !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 RESULT] $+(<,$4-,>) 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
  }
}


Re: Bettings Script [Re: blessing] #245488 23/04/14 04:39 AM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Hey blessing,
THANKS for the script, is working NICE!

Last edited by Kawalli; 23/04/14 05:17 AM.
Re: Bettings Script [Re: Kawalli] #245491 23/04/14 05:09 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
The last code i gave you does exactly what you want.
When bot msg to the channel said the bet is closed, it is actually not closed yet. It just prevents user to place bet anymore. Mods need to type !wonbet command to close the bet and show the result.

Re: Bettings Script [Re: blessing] #245493 23/04/14 05:15 AM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Nope i swear to god, it delete the bet ^^ - the script you posted its also writeing instant "[BET] Bet is Closed!" when you open a new bet!

I found a "own" solution:

Code:
    .timerbet.warn 1 60 msg $1 [BET] Bet will be closed in 30secs. 
    .timerbet.close 1 90 set %nomorebet 1
  }
  if %r == bet && !%bet.closed {
    if (%nomorebet == 1) { .msg $chan You cant place a bet atm. | halt }
    if !%bet.q && !%bet.bet { 
      set -u60 %bet.bet 1
      msg $1 [BET] There is no BET yet.
      return 
    }
   ...
    }
    msg $1 [BET RESULT] $+(<,$4-,>) was the winning option! $iif(%win,Winners are: %win - good luck for all others on the next bet!,There is no winner!)
    unset %bet.*
	set %nomorebet 0
    .timerbet.* off
  }
}


That is working like i want it. Not sure if my solution is bad.

Last edited by Kawalli; 23/04/14 05:17 AM.
Re: Bettings Script [Re: Kawalli] #245495 23/04/14 05:28 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Thats okay if your solution works, although i see no different between your code and mine.
You only change variable %bet.closed to %nomorbet.



Re: Bettings Script [Re: blessing] #245497 23/04/14 05:45 AM
Joined: Apr 2014
Posts: 18
K
Kawalli Offline OP
Pikka bird
OP Offline
Pikka bird
K
Joined: Apr 2014
Posts: 18
Okay i get a head crash... sorry blessing!
...

nvm.



Thanks to blessing!

Last edited by Kawalli; 23/04/14 05:56 AM.
Re: Bettings Script [Re: Kawalli] #245498 23/04/14 05:55 AM
Joined: Apr 2014
Posts: 191
B
blessing Offline
Vogon poet
Offline
Vogon poet
B
Joined: Apr 2014
Posts: 191
Code:
  if %r == bet {
    if (%wettannahme == 1) { msg $1 Wettannahme ist geschlossen. | return }
    if !%bet.q && !%bet.bet {