# DICE GAMBLING GAME

### Learn how to program a fully functional random chance game with prizes.

• pianotm
• 12/10/2017 09:00 AM
• 2769 views
Difficulty:

Moderate. It's not very difficult, but it requires patience and focus.

The Premise:

We're trying to use eventing to program a simple dice game, not exactly like, but similar to the game found in Suikoden.

The Goal:

The object is to make a fully versatile game, so a single win condition and lose condition is not a valid conclusion. With this random number generator, it should be perfectly viable to program larger versions of the game, like standard five-card draw poker, or more complex games like Blackjack. What we're making in this tutorial, is a simple game of dice, or, essentially, a slot machine.

Caveat:

There may be a simpler way to do what I'm about to show you. I don't know. Since we're not only trying to track specific number combinations, but trying to assign prizes based on certain conditions, I don't see how this could be more easily done, but is rewarding to see it finally working.

So let's begin.

What you need to know:

A cursory understanding of variables and labels is required.

Setup:

This game uses three variables. Create an event that uses these variables.
[0001] RN 1
[0002] RN 2
[0003] RN 3

Have them each SET for random number 1-6.

After your event calls the variables, have it call your first common event.

Obviously, you can actually use as many as like. For a game like five card draw, or if you needed five dice, you'd use five variables. You'll find that the more variables you use that the amount of event scripting you need to do will increase exponentially, so for more complex games, be sure you're willing to commit a bit of time. Three dice weren't too bad. It only took me roughly four hours. Considering how much the number of permutations increased when I added two dice, I'm sure it would have taken me two days had I gone with five dice, as originally intended (I wanted to include win conditions like "straights" and "full houses").

After this, you need to set up six common events. Set their triggers to "none".
Why six? How many sides are there to a standard die?

The Event Scripting:

This is just straight math and repetition, so it's best just to get into it.

The easiest part is tracking the numbers from your first variable.

In the first event, set up six conditional branches, each set to the variable [0001] RN 1. The first conditional branch should be set equal to one. The second one should be set equal to 2, and so on and so forth. In the first branch, enter the command to jump to label 1. In the subsequent branches, have them call the corresponding event.

1. Create six conditional branches numbered 1 through six for variable RN1.
4. Don't forget that event one is if variable one lands on one. If it lands on any other number, it just repeats the process in another event that you're establishing in this event.
5. For each number that calls a new event, don't forget to end event processing, because if you don't, it will cycle through all of the first variable's conditional branches.

```@> Conditional Branch: Variable [0001:RN1]==1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN1]==2
@>Call Event: Number 2
@>End Event Processing
@>
:Branch End
@> Conditional Branch: Variable [0001:RN1]==3
@>Call Event: Number 3
@>End Event Processing
@>
:Branch End
@> Conditional Branch: Variable [0001:RN1]==4
@>Call Event: Number 4
@>End Event Processing
@>
:Branch End
@> Conditional Branch: Variable [0001:RN1]==5
@>Call Event: Number 5
@>End Event Processing
@>
:Branch End
@> Conditional Branch: Variable [0001:RN1]==6
@>Call Event: Number 6
@>End Event Processing
@>
:Branch End```

Now, obviously, with jumping to label 1, we are preparing to set up what happens if the first variable lands on one. The next five numbers will get their own common event. The reason is because we want to be able to easily keep track of our numbers. We could put everything in a single event, but it will become absolute hell trying to keep track of all the dice on a single page.

So, after this first set, you should set a comment to separate your first dice cast from the first label. I like to fill it with pound signs (hashtags for the youngsters reading this). Makes it easier to see. Beneath this, put your first label. After that, you're going to variable RN 2. Set it up exactly as above.
Only this time, set up your labels for all of them. Labels 2 through 7.

1. Set Label 2.
2. Assign six conditional branches labeled 1 through 6 for variable RN 2.

```COMMENT: ###############################################
###############################################
###############################################
###############################################
@>Label: 1
@> Conditional Branch: Variable [0001:RN2]==1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==2
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==3
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==4
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==5
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==6
@>
:Branch End```

Now, at this point, the first dice has landed on one, which leads us to find out what this dice will land on. Landing on one, it will jump to label 2. Landing on two, it will jump to label 3 and so on and so forth. For each one of these labels, you need to set up the roll for the third dice. That is one through six and will have to be done for each label. We are also going to start assigning prizes. Remember at this point, your roll is thus far 1 1 , so you already have a pair. For this example, I am assigning a prize 250 gold for three of a kind, and 100 gold for a pair. Since the first branch in label three will be 1 1 1, it will get the biggest prize.

2. Assign six conditional branches numbered 1 through 6 for variable RN3
3. Assign prizes.
4. Jump to a final label (Label 8) and end event processing. Event processing has to end or it will cycle through all of the dice rolls.

```COMMENT: ###############################################
###############################################
###############################################
###############################################
@>Label: 3
@> Conditional Branch: Variable [0001:RN3]==1
@> Text: Congratulations!  You won 250 gold!
@> Change Gold: +250
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==2
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==3
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==4
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==5
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==6
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End```

To finish this common event off, repeat this process for each label. Remember, with the exception of the above label, two of a kind will only occur twice and three of a kind will not occur again. I'll show you one more label to fully clarify what it should look like.

```COMMENT: ###############################################
###############################################
###############################################
###############################################
@>Label: 4
@> Conditional Branch: Variable [0001:RN3]==1
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==2
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==3
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==4
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==5
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==6
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End```

Repeat this process for all labels up to seven. Now, set up label 8.

```COMMENT: ###############################################
###############################################
###############################################
###############################################
@>Label: 8
@>Play SE: 'Chime2'
@>End Event Processing```

Next, move on to the next event. You're simply continuing the sequence. You could do this on your first event. You're simply doing this to make it easier to keep track of labels and dice rolls. You won't need to repeat the process for variable 1, but for each subsequent event, you will need to repeat the process for variable two.

Common event 2:

```COMMENT: ###############################################
###############################################
###############################################
###############################################
@> Conditional Branch: Variable [0001:RN2]==1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==2
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==3
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==4
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==5
@>
:Branch End
@> Conditional Branch: Variable [0001:RN2]==6
@>
:Branch End```

Next, simply repeat the process you established for the previous event until you've gone through labels one through six. Remember, that you can reuse labels, and there's no need to assign a label to the second variable this time, since that's the one you're starting with, so you only need seven labels for this event.

```COMMENT: ###############################################
###############################################
###############################################
###############################################
@>Label: 1
@> Conditional Branch: Variable [0001:RN3]==1
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +250
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==2
@> Text: Congratulations!  You won 100 gold!
@> Change Gold: +100
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==3
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==4
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==5
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End
@> Conditional Branch: Variable [0001:RN3]==6
@> Text: At least you got a potion.
@> Change Items: [[]Potion[]] + 1
@>
:Branch End```

As before, rinse and repeat. One label for each number two can land on in all six events. All possible numbers that three can land on for each label that variable two calls. This will take several hours, but it will be well worth it.

It occurs to me that I can also assign the prizes to labels and have the dice rolls call those, but the difference this makes seem neglible.

Here is an image of my own event one when I was figuring this out. Some things are a little different because I was still figuring out how to do this, but it's essentially the same.

Remember, all five of your subsequent events should look like this, minus the first variable.

I worry that this tutorial might not be clear enough because of everything that goes into it and what you have to keep track of. Let me know if you need anything clarified.

## Posts

Pages: 1
Cool idea - I'd try to use arrays here. You will save yourself a lot of work and you really need only one common event ;)

This Rm2k-example implements the dice game for any number of dice. For each game of dice you call a small common event:

Explanation

• The array 0302*0307 stores the numbers of dice showing 1 through 6, respectively
• 0032:diceResultPtr = 301 is a pointer to the array above
• 0062:nDice contains the number of dice in the game the player has chosen before
• 0048:_throw contains an integer where each digit represents the number of one die

The loop cycles through all dice you throw - for each die, the array is updated (+1) and the biggest tuple you currently have is stored in _maxTuple.

After all dice are thrown, the player wins some gold, depending on the biggest tuple in the throw.
pianotm
The TM is for Totally Magical.
26973
author=CrazyL
Cool idea - I'd try to use arrays here. You will save yourself a lot of work and you really need only one common event ;)

This Rm2k-example implements the dice game for any number of dice. For each game of dice you call a small common event:

Explanation

• The array 0302*0307 stores the numbers of dice showing 1 through 6, respectively
• 0032:diceResultPtr = 301 is a pointer to the array above
• 0062:nDice contains the number of dice in the game the player has chosen before
• 0048:_throw contains an integer where each digit represents the number of one die

The loop cycles through all dice you throw - for each die, the array is updated (+1) and the biggest tuple you currently have is stored in _maxTuple.

After all dice are thrown, the player wins some gold, depending on the biggest tuple in the throw.

Oh, cool! Thank you! Not sure how I missed this comment...actually, the notification probably got buried.
really nice idea, thank you for sharing. I always wanted to create my own gambling game, but I was thinking that it's way to difficult. But now, when I have read all that, I understand that I was wrong! Thank you, good man! I was always a fan of this kind of games, I've been playing it on casino utan svensk licens. And now I can create a similar game by myself. wow, it's incredible!
Pages: 1