This is an older article but is kept here for posterity's sake. Ankhbot is now Streamlabs Chatbot and does not function in the same matter. This code will not work.
Followers come to your channel to interact with you and your community, but it doesn’t hurt to have something else for them to do while there. Many broadcasters have adapted the Ankhbot (or other) heist program for their channels in varying ways to fit their channel’s theme (mine being an !ambush), but as we all know a little variety goes a long way.
So, following the lead of Moobot, a popular Twitch channel bot, I created a dice game that allows my followers to quickly gain (and lose) supplies. Where an !ambush allows them to gain/lose a larger sum of Supplies (my currency), the !dice command allows them to gain/lose smaller amounts. It is a faster, easier way for followers to win smaller amounts and get their fix because they don’t have to wait on other followers to join or the system to countdown to start.
That said, let’s take a look at how I made my dice game in Ankhbot.
HOW IT WORKS
On the surface it may seem that there’s a lot going on with calculations of dice and currency, but in reality there are only a couple of things being done when the !dice command is entered. 1) Ankhbot randomly chooses one line from 36 lines of code saved in a .txt document which match up to a dice combination 2) Ankhbot calculates how many supplies to give or take away.
HOW TO MAKE IT
First, in the !dice command you must have Ankhbot read the .txt file in which you have the code (coming up). So, in my command I have:
$user, you roll the dice and… $readrandline(C:\users\…\dice.txt)
The first part refers to the $user who uses the command followed by some filler text telling the user what he or she is doing and then linking the dice.txt with the $readrandline() parameter. It’s that simple!
Next, we have to work on the code inside of the .txt file.
My game is a two dice game so there are a total of 36 numerical combinations for the dice which are the following:
(1,1) (1,2) (1,3) (1,4) (1,5) (1,6)
(2,1) (2,2) (2,3) (2,4) (2,5) (2,6)
(3,1) (3,2) (3,3) (3,4) (3,5) (3,6)
(4,1) (4,2) (4,3) (4,4) (4,5) (4,6)
(5,1) (5,2) (5,3) (5,4) (5,5) (5,6)
(6,1) (6,2) (6,3) (6,4) (6,5) (6,6)
To have these choices available to the user all we have to do is create a .txt document giving you a result for each of the combinations above. As I stated, in my game evens and doubles win, and odds lose. Therefore, for evens and doubles we are going to use the parameter $addpoints(“target”,”min”,”max”,”succeed”,”fail”) and for odds we are going to apply the $removepoints(“target”,”min”,”max”,”succeed”,”fail”,”forceremove”) parameter.
So, my .txt document (which I labeled dice.txt) has 36 entries in a row that look like:
$addpoints(“$user”,”100",”100",”You rolled snake eyes (1,1)! 100 Supplies have been added to your inventory!”,”You gained nothing”)
$removepoints(“$user”,”25",”100",”You rolled odds (1,2)! $value Supplies have been removed from your inventory!”,”You don’t have enough to roll!”,”false”)
$addpoints(“$user”,”25",”100",”You rolled evens (1,3)! $value Supplies have been added to your inventory!”,”You gained nothing”)
The $addpoints() parameter I use for the rolls that land on evens and doubles. It has the following information in it:
"$user" — leave as is to define who the activating user is.
"min”,”max” — I put this at “25”,”100″ so they win anywhere from 25–100 supplies randomly on roll. On doubles I multiply a single die by 100 so a pair of threes would be “300”,”300″ for example earning a player 300 supplies.
“succeed” — “You rolled snake eyes! blah blah” This just tells the user what they rolled, that they won and how many supplies they won.
“fail” — This is not needed as our fail state is in the $removepoints() paramater (coming up next), but must have some text in it to function.
The $removepoints() parameter I use for the rolls that land on odds. It has the following in it:
“$user” — leave as is to define who the activating user is.
“min”,”max” — Again, this is at “25”,”100″ but because of the parameter the player loses anywhere from 25–100 supplies instead of gains.
“succeed” — This is actually fail text… “You rolled odds (1,2)! $value Supplies have been removed from your inventory!” What they rolled and how much they lost.
“fail” — This is needed if they do not have enough currency so a simple message like, “You do not have enough to roll!” works.
“forceremove” — “False” so if they can’t lose any more than 0 currency.
That’s it for the game. Roll away and relish in your gains (and losses)! You may want to consider putting it on a cooldown per user if they get a little too spammy with the command, but it should be all aces from here!
IS THERE MORE?
Sadly, there are limitations to Ankhbot, as in any program. Also, I am no expert at Ankhbot. I learned everything from YouTube videos and posts on Reddit and other forums, but what I do know I try to share. If you have any questions about this article, my previous article, “Ankhbot — Creating an (almost) completely autonomous user-created custom welcome message program” or any ideas you have for things you would like to do with Ankhbot just let me know here in the comments or on social media!