Slot Machine for mIRC Twitch Bot and AnkhBot

By Blasman on Dec 23, 2015

UPDATE (January 3, 2016) ::: I will be updating these scripts and adding more at GitHub rather than here, as it makes things a lot easier. https://github.com/Blasman/mIRC-Twitch-Scripts

Download Here: https://dl.dropboxusercontent.com/u/1231209/mIRCslots.rar

UPDATE (December 29, 2015) ::: I made the code a little better/cleaner. Users can now use !slot -or- !slots interchangeably, as a lot of users kept typing !slots instead of !slot.

A few people have been asking me for the Slot Machine that I have been using in my Twitch channel at twitch.tv/Blasman13 . I am using a combination of mIRC and AnkhBot for use with my Twitch bot. What this slot machine script does is use the currency database from AnkhBot for adding and removing points, so you do not need a separate point system for the slot machine.

Step 1: Download and install mIRC. UNCHECK EVERYTHING except "Scripts" and "Help Files" on the "Choose Components" section of the install, as you don't need most of it. http://www.mirc.com/get.html

Step 2: Get your bot's Twitch account up and running with mIRC, and set up your Twitch channel as an auto-join channel as well. See http://help.twitch.tv/customer/portal/articles/1302780-twitch-irc#mIRC%20guide or https://www.youtube.com/watch?v=k7ULgVCZ3Ns

Step 3: Put all the files from the mircslots.rar file into your mIRC's script directory. By default, it should be your mIRC's root directory, something like C:\Users\USERNAME\AppData\Roaming\mIRC\ ... replace "USERNAME" with your Windows username... an easy way to get to this directory is by typing %APPDATA% in your Windows Folder titlebar and opening the mIRC directory.

Step 4: Edit the slot.mrc file in a text editor. Change the variables at the top to what they need to be. The only one that you need to change is the path to your AnkhBot's CurrencyDB.sqlite file. Also, just in case anything would happen to go wrong, make a back-up of your CurrencyDB.sqlite file.

Step 5: Load all the scripts that are needed by typing the following commands in mIRC's Status window. Blindly agree to any prompts that may pop-up. If mIRC says "no such file," then you did something wrong, such as putting the files in the wrong directory.

/load -rs JSON.mrc
/load -rs mTwitch.mrc
/load -rs msqlite.mrc
/load -rs slot.mrc

Step 6: Profit. Type "!slot on" and "!slot off" to activate and deactivate the slots. Test them out. Make sure that the points are being added/removed. You can view the sections of my mIRC YouTube video that talk about having mIRC be as unobtrusive as possible and running automatically if you want as well. https://www.youtube.com/watch?v=k7ULgVCZ3Ns

Credits (and most recent versions of scripts):
The JSON.mrc script: http://hawkee.com/snippet/10194/
The mTwitch.mrc script: http://hawkee.com/snippet/16487/
The msqlite.mrc script: http://hawkee.com/scripts/11648275/
AnkhBot: http://marcinswierzowski.com/Code/AnkhBotR2/

The script displayed below is the copy of slot.mrc in the mIRCslots.rar file.

It's also worth noting that I ran the script through a 1,000,000 times loop to get an idea of the overall odds of winning and losing. The variance was less than 0.1% in favor of the user. It only seems like the users win a lot simply because it's very easy to win 1x, 2x, and even 5x. However, it is very rare to get any of the other combinations of symbols.

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; VARIABLES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

/*
HEY!  LOOK HERE!  This is what you need to change in this script...
Where it says "SET %CurrencyDB" below, change the path to the path of
YOUR AnkhBot's CurrencyDB.sqlite file.  Leave the quotation marks in!
It is likely the same path as the example listed, with the exception of
your Windows username.

Change the %minbet and %maxbet to the minimum and maximum amount of
points that must be spent in order to use the !slot.  The %slotcd
variable is the per user cooldown time (in seconds) that a user must
wait before being able to use !slot again.  The %curname variable
is the name of your channel currency.

You can just leave the %slotsym variables or you can change them to the
emotes that you want to use for the slot machine.  The %slotsym.0 emote
is the emote that will appear 50% of the time, and the other five appear
more rarely the higher that the number is. http://i.imgur.com/ch5vQZ2.png

You will need to UNLOAD and RE-LOAD this script for any changes to the
variables below to take effect.  This can be done by pressing ALT-R in
mIRC > Select "View" > Select "slot.mrc" > Click on "File" > "Unload."
Then, click on "File" and "Load..." and select the slot.mrc file again.

If you want to edit what the bot replies for the slot machines win and
losses, you can likely figure that out by looking closely at the script.

Have fun!!!
*/

ON *:LOAD: {
  SET %CurrencyDB "C:\Users\USERNAME\AppData\Roaming\AnkhHeart\AnkhBotR2\Twitch\Databases\CurrencyDB.sqlite"
  SET %curname points
  SET %minbet 50
  SET %maxbet 500
  SET %slotcd 1800
  SET %slotsym.0 bleedPurple
  SET %slotsym.1 duDudu
  SET %slotsym.2 riPepperonis
  SET %slotsym.3 ShibeZ
  SET %slotsym.4 OSrob
  SET %slotsym.5 deIlluminati
}

ON *:UNLOAD: {
  UNSET %CurrencyDB
  UNSET %curname
  UNSET %minbet
  UNSET %maxbet
  UNSET %slotcd
  UNSET %slotsym.*
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ALIASES ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

alias twitch_name {

  if (%tn == 1000) %tn = 0
  inc %tn
  JSONOpen -ud twitch_name $+ %tn https://api.twitch.tv/kraken/channels/ $+ $1
  return $json(twitch_name $+ %tn $+ , display_name)
  JSONClose twitch_name $+ %tn
}

alias addpoints {

  set %ankhbot_currency $sqlite_open(%CurrencyDB)
  if (!%ankhbot_currency) {
    echo 4 -a Error: %sqlite_errstr
    return
  }
  var %sql_points = SELECT Points FROM CurrencyUser WHERE Name = ' $+ $1 $+ ' COLLATE NOCASE
  var %request_points = $sqlite_query(%ankhbot_currency, %sql_points)
  if (!%request_points) {
    echo 4 -a Error: %sqlite_errstr
    return
  }
  $sqlite_fetch_row(%request_points, row)
  var %ankhbot_points = $hget(row, Points)

  SET %newpoints = $calc(%ankhbot_points + $2)
  sqlite_exec %ankhbot_currency UPDATE CurrencyUser SET Points %newpoints WHERE Name = ' $+ $1 $+ ' COLLATE NOCASE
  sqlite_free %request_points
  UNSET %newpoints
}

alias removepoints {

  set %ankhbot_currency $sqlite_open(%CurrencyDB)
  if (!%ankhbot_currency) {
    echo 4 -a Error: %sqlite_errstr
    return
  }
  var %sql_points = SELECT Points FROM CurrencyUser WHERE Name = ' $+ $1 $+ ' COLLATE NOCASE
  var %request_points = $sqlite_query(%ankhbot_currency, %sql_points)
  if (!%request_points) {
    echo 4 -a Error: %sqlite_errstr
    return
  }
  $sqlite_fetch_row(%request_points, row)
  var %ankhbot_points = $hget(row, Points)

  SET %newpoints = $calc(%ankhbot_points - $2)
  sqlite_exec %ankhbot_currency UPDATE CurrencyUser SET Points %newpoints WHERE Name = ' $+ $1 $+ ' COLLATE NOCASE
  sqlite_free %request_points
  UNSET %newpoints
}

alias checkpoints {

  set %ankhbot_currency $sqlite_open(%CurrencyDB)
  if (!%ankhbot_currency) {
    echo 4 -a Error: %sqlite_errstr
    return
  }
  var %sql_points = SELECT Points FROM CurrencyUser WHERE Name = ' $+ $1 $+ ' COLLATE NOCASE
  var %request_points = $sqlite_query(%ankhbot_currency, %sql_points)
  if (!%request_points) {
    echo 4 -a Error: %sqlite_errstr
    return
  }
  if ($sqlite_num_rows(%request_points) == 0) { return false }
  else {
    $sqlite_fetch_row(%request_points, row)
    var %ankhbot_points = $hget(row, Points)
    if (%ankhbot_points < $2) { return false }
    elseif (%ankhbot_points >= $2) { return true }
    sqlite_free %request_points
  }
}

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SLOT MACHINE ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ON $*:TEXT:/^!slot(s)?\s(on|off)/Si:#: {

  IF ($nick isop $chan) {
    IF ($2 == on) {
      IF (!%GAMES_SLOT_ACTIVE) {
        SET %GAMES_SLOT_ACTIVE On
        MSG $chan $twitch_name($nick) $+ , !slot is now enabled!  Have fun!  PogChamp
      }
      ELSE MSG $chan $twitch_name($nick) $+ , !slot is already enabled.  FailFish
    }
    ELSEIF ($2 == off) {
      IF (%GAMES_SLOT_ACTIVE) {
        UNSET %GAMES_SLOT_ACTIVE
        MSG $chan $twitch_name($nick) $+ , !slot is now disabled.
      }
      ELSE MSG $chan $twitch_name($nick) $+ , !slot is already disabled.  FailFish
    }
  }
}

ON $*:TEXT:/^!slot(s)?/Si:#: {

  IF (!$2) || ($2 == help) {
    IF ($($+(%,floodSLOTSPAM1.,$nick),2)) halt
    SET -u6 %floodSLOTSPAM1. $+ $nick On
    MSG $chan You may bet any amount of %curname from %minbet to %maxbet on !slot.  ▌  Example:  !slot %minbet  ▌  See this link to see the payouts for each combination of symbols.  http://i.imgur.com/ch5vQZ2.png
  }
  ELSEIF (!%GAMES_SLOT_ACTIVE) {
    IF ((%floodSLOT_ACTIVE) || ($($+(%,floodSLOT_ACTIVE.,$nick),2))) halt
    SET -u15 %floodSLOT_ACTIVE On
    SET -u120 %floodSLOT_ACTIVE. $+ $nick On
    MSG $chan $twitch_name($nick) $+ , the !slot game is currently disabled.
  }
  ELSEIF ($timer(.SLOT. $+ $nick)) {
    IF ($($+(%,floodSLOTCD.,$nick),2)) halt
    SET -u180 %floodSLOTCD. $+ $nick On
    MSG $nick Be patient, $twitch_name($nick) $+ !  You still have $duration($timer(.SLOT. $+ $nick).secs) left in your !slot cooldown.
  }
  ELSEIF ($2 isnum) {
    IF (%SlotGameRunning) halt
    ELSEIF ($2 !isnum %minbet - %maxbet) {
      IF ($($+(%,floodSLOTSPAM1.,$nick),2)) halt
      SET -u6 %floodSLOTSPAM1. $+ $nick On
      MSG $chan $twitch_name($nick) $+ , please enter a valid wager between %minbet and %maxbet %curname $+ .  ▌  Example:  !slot %minbet  ▌  See this link to see the payouts for each combination of symbols.  http://i.imgur.com/ch5vQZ2.png
    }
    ELSE {
      VAR %slotbet = $floor($2)
      IF ($checkpoints($nick, %slotbet) == false) {
        IF ($($+(%,floodSLOTSPAM2.,$nick),2)) halt
        SET -u6 %floodSLOTSPAM2. $+ $nick On
        MSG $chan $twitch_name($nick) $+ , you do not have %slotbet %curname to play slots.  FailFish
        halt
      }
      ELSE removepoints $nick %slotbet
      VAR %nick $twitch_name($nick)
      SET %SlotGameRunning On
      .timer.SLOT. $+ $nick 1 %slotcd MSG $nick %nick $+ , your !slot cooldown has expired.  Feel free to play again.  BloodTrail
      MSG $chan %nick pulls the slot machine lever...
      VAR %x = 1
      WHILE (%x <= 3) {
        VAR %random $rand(1,100)

        IF (%random isnum 1-50) VAR %slot. $+ %x %slotsym.0
        ELSEIF (%random isnum 51-65) VAR %slot. $+ %x %slotsym.1
        ELSEIF (%random isnum 66-79) VAR %slot. $+ %x %slotsym.2
        ELSEIF (%random isnum 80-88) VAR %slot. $+ %x %slotsym.3
        ELSEIF (%random isnum 89-95) VAR %slot. $+ %x %slotsym.4
        ELSEIF (%random isnum 96-100) VAR %slot. $+ %x %slotsym.5
        INC %x
      }

      IF ((%slot.1 == %slot.2) && (%slot.2 == %slot.3)) {
        IF (%slot.1 == %slotsym.0) VAR %payout = %slotbet * 5
        ELSEIF (%slot.1 == %slotsym.1) VAR %payout = %slotbet * 10
        ELSEIF (%slot.1 == %slotsym.2) VAR %payout = %slotbet * 15
        ELSEIF (%slot.1 == %slotsym.3) VAR %payout = %slotbet * 25
        ELSEIF (%slot.1 == %slotsym.4) VAR %payout = %slotbet * 50
        ELSEIF (%slot.1 == %slotsym.5) VAR %payout = %slotbet * 100
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   OMG, %nick $+ , you might win this!  FeelsGoodMan
        .timer.slotsym3 1 18 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  You WON %payout %curname $+ , %nick $+ !!!  PogChamp
        .timer.slotpayout 1 18 ADDPOINTS $nick %payout | .timer.slotpayout2 1 18 UNSET %SlotGameRunning
      }

      ELSEIF ((%slot.1 == %slot.2) && (%slot.2 != %slot.3) && (%slot.3 == %slotsym.0)) {
        VAR %payout = %slotbet
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   OMG, %nick $+ , you might win this!  FeelsGoodMan
        .timer.slotsym3 1 18 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  Well, %nick $+ , at least you won %payout %curname $+ !  MingLee
        .timer.slotpayout 1 18 ADDPOINTS $nick %payout | .timer.slotpayout2 1 18 UNSET %SlotGameRunning
      }

      ELSEIF ((%slot.1 == %slot.2) && (%slot.2 != %slot.3) && (%slot.3 != %slotsym.0)) {
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   OMG, %nick $+ , you might win this!  FeelsGoodMan
        .timer.slotsym3 1 18 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  You Lose, %nick $+ !  :tf:
        .timer.slotstop 1 18 UNSET %SlotGameRunning
      }

      ELSEIF ((%slot.2 == %slotsym.0) && (%slot.3 == %slotsym.0)) {
        VAR %payout = %slotbet * 2
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   Well, %nick $+ , best of luck getting another %slotsym.0  ...
        .timer.slotsym3 1 15 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  You WON %payout %curname $+ , %nick $+ !!!  PogChamp
        .timer.slotpayout 1 15 ADDPOINTS $nick %payout | .timer.slotpayout2 1 15 UNSET %SlotGameRunning
      }

      ELSEIF (%slot.2 == %slotsym.0) && (%slot.3 != %slotsym.0) {
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   Well, %nick $+ , best of luck getting another %slotsym.0  ...
        .timer.slotsym3 1 15 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  You Lose, %nick $+ ! :tf:
        .timer.slotstop 1 15 UNSET %SlotGameRunning
      }

      ELSEIF (%slot.3 == %slotsym.0) {
        VAR %payout = %slotbet
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   Well, %nick $+ , best of luck getting at least a %slotsym.0  ...
        .timer.slotsym3 1 15 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  You WON %payout %curname $+ , %nick $+ !!!  PogChamp
        .timer.slotpayout 1 15 ADDPOINTS $nick %payout | .timer.slotpayout2 1 15 UNSET %SlotGameRunning
      }

      ELSEIF ((%slot.1 != %slot.2) && (%slot.3 != %slotsym.0)) {
        .timer.slotsym1 1 4 DESCRIBE $chan  ▌ %slot.1 ▌  :::  Good Luck, %nick $+ .  BloodTrail
        .timer.slotsym2 1 9 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌   :::   Well, %nick $+ , best of luck getting at least a %slotsym.0  ...
        .timer.slotsym3 1 15 DESCRIBE $chan  ▌ %slot.1 ▌ %slot.2 ▌ %slot.3 ▌   :::  You Lose, %nick $+ ! :tf:
        .timer.slotstop 1 15 UNSET %SlotGameRunning
      }
    }
  }
}

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.