mIRC Home    About    Download    Register    News    Help

Print Thread
[Twitch] Gambling System #256322 10/01/16 09:49 AM
Joined: Jan 2016
Posts: 4
C
codmister11 Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Jan 2016
Posts: 4
Hello all,

So after some research and editing, I've managed to create a working points system. The next step is to add a "gambling" function. This would be an on text command of the form "!gamble <amount>"; when this command is typed, the user gambles an amount (1-50) on a "roll." I will work on this bit later, but for now, I'm just trying to get mIRC to even respond to any input of "!gamble" in chat... right now I have only put script in that is meant to help a user properly format their !gamble command. Can anyone point out to me where I've gone wrong so far? I'm getting no response or Error messages when I type anything starting with "!gamble" into chat. If I can fix this problem I will continue to post on this forum about further developing this script (as opposed to creating a new one). (P.S. I'm aware both timers are only 5 seconds, this is just while I'm testing this all out). Thanks for your time!

Quote:
on *:text:!gamble*:#: {
if (%floodgamble) || ($($+(%,floodgamble.,$nick),2)) { return }
set -u5 %floodgamble On
set -u5 %floodgamble. $+ $nick On
if ($0 != 2) || ($2 !isnum) {
msg $chan To gamble SN1PEbucks, use the form !gamble <amount (1-50)>
halt
}
if ($2 <= 0) || ($2 > 50) {
msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks.
halt
}
}

Re: [Twitch] Gambling System [Re: codmister11] #256336 11/01/16 07:58 PM
Joined: Jul 2015
Posts: 13
K
Karotte Offline
Pikka bird
Offline
Pikka bird
K
Joined: Jul 2015
Posts: 13
doesn't it have to be

elseif ($2 <= 0) || ($2 > 50) {
msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks.
halt
}
}

?

Last edited by Karotte; 11/01/16 07:58 PM.
Re: [Twitch] Gambling System [Re: codmister11] #256344 12/01/16 08:21 AM
Joined: Oct 2015
Posts: 112
B
Blas Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
As mentioned by Karotte, I believe the ($0 != 2) is not what you wanted. It looks like what you're trying to do it is create three possible responses. One response for when the command is successful and the user properly gambles 1 to 50 points. A second response for when they do enter a value, but the value is not between 1 and 50. A third response for when neither of the above are true. A simple way to do that would be this:

Code:
on *:text:!gamble*:#: {
  if (%floodgamble) || ($($+(%,floodgamble.,$nick),2)) { return }
  set -u5 %floodgamble On
  set -u5 %floodgamble. $+ $nick On
  if ($2 isnum 1-50) {
    -perform what happens with a successful gamble here-
  }
  elseif ($2 isnum) msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks. 
  else msg $chan To gamble SN1PEbucks, use the form !gamble <amount (1-50)> 
}


This basically says "IF user used the command properly, then do what the command is meant to do." "or ELSE, IF they did use a number (but it wasn't between 1 and 50), then display the message telling them to use a valid number." "ELSE, if none of the either two are true, then display the message telling them how to use the command."

Re: [Twitch] Gambling System [Re: Blas] #256384 13/01/16 08:15 PM
Joined: Jan 2016
Posts: 4
C
codmister11 Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Jan 2016
Posts: 4
Thank you so much for the help, guys! Building from the revision and insight in Blas' response, I went on to finish the code.
Code:
 on *:text:!gamble*:#: {
  if (%floodgamble) || ($($+(%,floodgamble.,$nick),2)) { return }
  set -u5 %floodgamble On
  set -u2400 %floodgamble. $+ $nick On
  if ($2 isnum 1-50) {
    var %randgamble = $rand(1,100)
    if (%randgamble <= 70) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) - $2)
      msg $chan $nick rolls a %randgamble and loses! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks. 
    halt }
    if (%randgamble >= 96) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + ($2 * 3))
      msg $chan $nick rolls a %randgamble and wins triple their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks! 
    halt }
    else {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + ($2 * 2))
    msg $chan $nick rolls a %randgamble and wins double their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks! }
  }
  elseif ($2 isnum) msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks. 
  else msg $chan To gamble SN1PEbucks, use the form !gamble <amount (1-50)> 
}
 


So the "execution" part of the script with the roll and .ini management turned out to be pretty simple to make thanks to being able to copy and paste parts from the points script that I have.

Speaking of the same section, I found that unless I put the "halt" after the If relation statements, the script would execute both the first or second "If" command AND the "Else" command. Are there more elegant solutions that might save a couple of lines of text? Or is this the best that can be done?

One last question: I would like to add another bit of script to this command. If %floodgamble.$nick is on I'd like to whisper $nick (as opposed to to messaging the channel) that they need to wait 40 minutes since their last gamble. I have a json script going but I haven't found resources on how to whisper via a script/command. What should I look into to get this started?

Thanks again for the help.

P.S. Anyone who comes in with a working points system wanting to adopt this script for their own use, just edit the currency names and flood timers to match your preferences.

Re: [Twitch] Gambling System [Re: codmister11] #256387 14/01/16 05:24 AM
Joined: Oct 2015
Posts: 112
B
Blas Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
Code:
on *:text:!gamble*:#: {
  if (%floodgamble) || ($($+(%,floodgamble.,$nick),2)) { return }
  set -u5 %floodgamble On
  set -u2400 %floodgamble. $+ $nick On
  if ($2 isnum 1-50) {
    var %randgamble = $rand(1,100)
    if (%randgamble <= 70) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) - $2)
      msg $chan $nick rolls a %randgamble and loses! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks.
    }
    elseif (%randgamble >= 96) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + ($2 * 3))
      msg $chan $nick rolls a %randgamble and wins triple their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
    }
    else {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + ($2 * 2))
      msg $chan $nick rolls a %randgamble and wins double their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
    }
  }
  elseif ($2 isnum) msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks.
  else msg $chan To gamble SN1PEbucks, use the form !gamble <amount (1-50)>
}



I'm not sure how the script was executing both IF statements, as I don't see how %randgamble can be both "less/equal to 70" AND "more/equal to 96." But the issue should be fixed if you use "elseif" instead of another "if" statement. The above code should work.

As for the whispering cooldowns, I've found two ways to do this with my Twitch scripts. Either use a timer, so that when the cooldown ends, your bot will also whisper the user letting them know that their cooldown is over. You may not want to whisper the user when the CD is over, so the more likely solution is to just use a variable or hash table item that counts down. The code below should work, I added a section to set a cooldown variable, as well as whisper the user if they try to use the command while they are on CD.

As for getting whispers to work in mIRC, if you already have the JSONForMirc script, I highly suggest you also check out SReject's mTwitch scripts. Just load the mTwitch.Core.mrc and mTwitch.GroupChat.mrc scripts, and boom, whispers will work on your mIRC bot.


Code:
on *:text:!gamble*:#: {
  if (%floodgamble) { return }
  set -u5 %floodgamble On
  if ($($+(%,gamble_CD.,$nick),2)) MSG $nick $nick $+ , please wait for your cooldown to expire in $duration(%gamble_CD. [ $+ [ $nick ] ]) before using !gamble again.
  elseif ($2 isnum 1-50) {
    var %randgamble = $rand(1,100)
    if (%randgamble <= 70) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) - $2)
      msg $chan $nick rolls a %randgamble and loses! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks.
    }
    elseif (%randgamble >= 96) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + ($2 * 3))
      msg $chan $nick rolls a %randgamble and wins triple their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
    }
    else {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + ($2 * 2))
      msg $chan $nick rolls a %randgamble and wins double their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
    }
    SET -ze %gamble_CD. $+ $nick 2400
  }
  elseif ($2 isnum) msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks.
  else msg $chan To gamble SN1PEbucks, use the form !gamble <amount (1-50)>
}


EDIT: I should have mentioned something that I found out the hard way myself. I've learned that it's a good idea to use $floor or $round on the number that the user uses to gamble. The reason being that a user can "exploit" the points system, by using a number with decimal places and screwing things up. $floor will remove any decimal places. The code below should work.

Code:
on *:text:!gamble*:#: {
  if (%floodgamble) { return }
  set -u5 %floodgamble On
  if ($($+(%,gamble_CD.,$nick),2)) MSG $nick $nick $+ , please wait for your cooldown to expire in $duration(%gamble_CD. [ $+ [ $nick ] ]) before using !gamble again.
  elseif ($2 isnum 1-50) {
    var %wager = $floor($2)
    var %randgamble = $rand(1,100)
    if (%randgamble <= 70) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) - %wager)
      msg $chan $nick rolls a %randgamble and loses! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks.
    }
    elseif (%randgamble >= 96) {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + (%wager * 3))
      msg $chan $nick rolls a %randgamble and wins triple their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
    }
    else {
      writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + (%wager * 2))
      msg $chan $nick rolls a %randgamble and wins double their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
    }
    SET -ze %gamble_CD. $+ $nick 2400
  }
  elseif ($2 isnum) msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks.
  else msg $chan To gamble SN1PEbucks, use the form !gamble <amount (1-50)>
}


Last edited by Blas; 14/01/16 07:12 AM.
Re: [Twitch] Gambling System [Re: Blas] #256401 15/01/16 02:00 AM
Joined: Jan 2016
Posts: 4
C
codmister11 Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Jan 2016
Posts: 4
Thank you so much - this is a lot more help than I expected posing those last questions!

To clarify the misstated issue about the multiple "execution" strips performing... Before I added "halt" to the end of the two "If" "relation" statements, the script would execute the appropriate "If" "relation" statement (so it would recognize and properly evaluate the number) but would then also execute the "Else" statement at the end of that bit. My apologies if I'm still being a bit vague, but I hoped to clear that up.

The problem you mentioned with the "decimal numbers" exploit is actually an important one to address, so I appreciate you recommending and adding the $floor statement. I can't put this in my script to test tonight, but the one question I have about this is: does the $floor statement truncate the decimals off of $2, or round $2 up or down "appropriately?" I assume it does the former since there is also a $round option you mentioned. In the case it does just remove all decimals off of $2 without regards to rounding, $floor is what I would want.

But then I wonder - is there a way to write an if statement that would check if $2 was a whole number, and if false, send a msg to $chan and then halt the script? That way there's no issues with 50.99999 still being gambled as 50 during the $2-to-%wager $floor conversion and hearing troll complaints about it.

My idea: can I ask to check if $2 - %wager = 0 as a solution, since $floor is used on $2 (to eliminate all decimals, I assume) to create a whole number named %wager? Or would this calculation round the difference to exactly 0 if close enough, thus not serving a purpose? I.e., would this work?

Code:
 if (($2 - %wager) == 0) {
msg $chan blah blah no decimals blah
halt } 


Again, thanks for looking into this, everyone. And thanks for the help, Blas.

Edit:

Also, I do use SReject's json script, so I believe all I need to do is insert the Core and Group Chat modules. Then all should be well. I will confirm this script is working whenever I can access my desktop tomorrow.

Last edited by codmister11; 15/01/16 02:49 AM.
Re: [Twitch] Gambling System [Re: codmister11] #256403 15/01/16 02:36 PM
Joined: Oct 2015
Posts: 112
B
Blas Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
In mIRC, I've found it very quick and easy to use it's help files, /help $floor for example returns "Returns N rounded to the next lowest integer." Not trying to be rude, but sometimes things are really that easy. smile

I've always just used $floor as I don't care if a user tries to exploit the numbers. I'll just let the script fix it. However, if you wanted to create a reply as you mentioned, you can just have the script check if the number is whole. Something like the following code...

Code:
IF ($int($2) == $2) MSG $chan YAY!  YOU USED A WHOLE NUMBER!
ELSE MSG $chan BOOOOO!  YOU DIDN'T USE A WHOLE NUMBER!


From my understanding, $int is extremely similar to $floor, but seems more appropriate in this case. I really don't think it would matter which you use unless there's negative numbers involved. Of course, the user could still use a whole number with decimals, like 13.0000000000000. If you wanted to prevent that, I think you may need to use REGEX. Someone correct me if I am wrong with anything here. I have only been writing scripts for a few months now myself.

Found on the forums: http://forums.mirc.com/ubbthreads.php/topics/254204/Way_to_only_read_whole_numbers

Re: [Twitch] Gambling System [Re: Blas] #256417 16/01/16 01:54 AM
Joined: Jan 2016
Posts: 4
C
codmister11 Offline OP
Self-satisified door
OP Offline
Self-satisified door
C
Joined: Jan 2016
Posts: 4
Thank you again for the help. The quick /help should prove useful later on!

So now, adding on things from last night and all, I've gotten just about everything going, but for some reason, the bot does not successfully whisper through Twitch.

So if any $nick uses gamble, the script is fully executed, all is well, and variable "%gamble_CD.[$nick]" is created. If the same user attempts to use gamble before their cooldown has expired, the script recognizes %gamble_CD.$nick and attempts(?) to send out a message and does not execute the rest of the scirpt. The only problem, of course, is that nothing goes through on the Twitch end. The window within mIRC does, however, say this ("username" substituted for appropriate $nick):
Quote:
-> *username* username, your gamble cooldown expires in 34mins 13secs

I assumed that seeing this message meant that I had improperly loaded json or mtwitch modules at some point, and so the msg command was not being properly "recognized" and "translated" into a whisper when it hit twitch. After unloading the scripts in question and then reloading what I needed in the proper order (json, core, and group chat in that order; I followed each page's installation instructions exactly) and allowing for initializations when prompted, I still got the same results from the script. The mIRC window displays that same message but nothing goes through on Twitch.

So, last question, I hope, and forgive me for my beginner mistakes that I'm sure I've made: How might I go about further diagnosing/fixing this problem? Thanks again for all your help.

Note: I realize that this is no longer about the gambling script that this forum is about, but I thought this problem was minor and didn't warrant a whole new forum creation - feel free to tell me I am wrong and I can make another post just about this issue.
Script in question:
Code:
 on *:text:!gamble*:#: {
  if (%floodgamble) { return }
  set -u5 %floodgamble On
  if ($($+(%,gamble_CD.,$nick),2)) msg $nick $nick $+ , your gamble cooldown expires in $duration(%gamble_CD. [ $+ [ $nick ] ]) 
  elseif ($2 isnum 1-50) {
    var %wager = $int($2)
    if ($int($2) == $2) {
      var %randgamble = $rand(1,100)
      if (%randgamble <= 70) {
        writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) - %wager)
        msg $chan $nick rolls a %randgamble and loses! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks.
      }
      elseif (%randgamble >= 96) {
        writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + (%wager * 3))
        msg $chan $nick rolls a %randgamble and wins triple their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
      }
      else {
        writeini -n Points.ini $+(#,.,$nick) Points $calc($readini(Points.ini,$+(#,.,$nick),Points) + (%wager * 2))
        msg $chan $nick rolls a %randgamble and wins double their bet! $nick now has $readini(Points.ini,$+(#,.,$nick),Points) SN1PEbucks!
      }
      SET -ze %gamble_CD. $+ $nick 2400
    }
    else msg $chan Whole numbers only, $nick
  }
  elseif ($2 isnum) msg $chan You can only gamble in the range of 1 - 50 SN1PEbucks.
  else msg $chan To gamble SN1PEbucks, use the form "!gamble <amount (1-50)>" with whole numbers only.
}

Last edited by codmister11; 16/01/16 02:07 AM.
Re: [Twitch] Gambling System [Re: codmister11] #256419 16/01/16 05:11 AM
Joined: Oct 2015
Posts: 112
B
Blas Offline
Vogon poet
Offline
Vogon poet
B
Joined: Oct 2015
Posts: 112
I'm not sure why the whispers are not working if you loaded all the scripts that you need. The message that you posted that you see in mIRC is the same message I see when my bot successfully whispers someone. I know some users on Twitch have settings where they can only receive whispers from users that they follow, or have whispers disabled completely. If that is not the case, then I would seek advice from SReject himself, as I am clueless otherwise.