RMRK is retiring.
Registration is disabled. The site will remain online, but eventually become a read-only archive. More information.

RMRK.net has nothing to do with Blockchains, Cryptocurrency or NFTs. We have been around since the early 2000s, but there is a new group using the RMRK name that deals with those things. We have nothing to do with them.
NFTs are a scam, and if somebody is trying to persuade you to buy or invest in crypto/blockchain/NFT content, please turn them down and save your money. See this video for more information.
[RM2K/3] Pontoon/Blackjack Game

0 Members and 1 Guest are viewing this topic.

***
Rep:
Level 84
puking up frothing vitriolic sarcastic spittle
Gambling games are an easy way to add interesting minigames to a project that don't require a lot of backstory or explaination. This tutorial is for a simple "Pontoon" or "Blackjack" style game.

------

First of all, you need to make the game itself. The game is going to be a Common Event that is set to be Called, and later I'll show you how to code the Dealer to do this. It doesn't matter what you call the event, but for this example I'll just use "Pontoon" as the name.

Now make five Variables. These are the only Variables you're going to need for this game. Call them the following:

- Turns Taken.
- Amount Bet.
- Dealer Score.
- Player Score.
- Gold Held.

The first part of the code will deal with resetting these values each time the player starts a new game. This is kinda simple:

Code: [Select]
Change Variable: Var(xxxx:Turns Taken): Set to 0
Change Variable: Var(xxxx:Amount Bet): Set to 0
Change Variable: Var(xxxx:Dealer Score): Set to 0
Change Variable: Var(xxxx:Player Score): Set to 0
Change Variable: Var(xxxx: Gold Held): Set to Amount of Gold Held

After doing this, it's time to let the player choose how much they want to gamble. In this case, I've set a limit of 50 Gold; this is obviously optional.

Code: [Select]
Label #10
Show Message: "Dealer: How much do you want to gamble?"
Input Number: Digits = 2: Var(xxxx:Amount Bet)
If Var(xxxx:Amount Bet) > 50 Then
   Show Message: "Dealer: Sorry, the limit is 50 Credits.
   Go To Label 10
End Case
If Var(xxxx:Amount Bet) = 0 Then
   Show Message: "Dealer: Sorry, you cannot bet nothing."
   Go To Label 10
End Case
If Var(xxxx:Amount Bet) > Var(xxxx:Gold Held) Then
   Show Message: "Dealer: You don't have enough."
   Go To Label 10
End Case

The label above, Label #10, is simply a placeholder to let this process repeat over and over until the player enters an acceptable value. I prefer Labels to Loops, but if you are more comfortable with loops then use that.

The next part is where it gets interesting, the game itself. The section below outlines what the player needs to do in the game. Remember, you can set the random numbers to anything you want, but I'm going to use 1-10 in line with a normal deck of cards (assuming there is no ace - if you wanted to have an ace you could use 11 to detect it and then ask the player whether they wanted it to be a 1 or an 11...)

Code: [Select]
Label #12
Change Variable: Var(xxxx:Turns Taken): Plus 1
Show Message:"Dealer: Here is the card..."
Change Variable: Var(xxxx:Player Score): Plus Random Number (1-10)
Show Message:"\>Dealer: Here is the card...\ 21 Then
   Show Message: "Dealer: I'm sorry, you lost..."
   Change Gold Held: Remove Var(xxxx: Amount Bet)
   Go To Label 20
End Case
If Var(xxxx:Turns Taken)  21 Then
   Show Message: "Dealer: I'm sorry, you lost..."
   Change Gold Held: Remove Var(xxxx: Amount Bet)
   Go To Label 20
Else Case
   Show Message: "Dealer: Let's see what I can get..."
   Change Variable: Var(xxxx: Dealer Score): Set To Random Number (15-22)
   Show Message: "\>Dealer: Let's see what I can get...\ 21 Then
  Show Message: "Dealer: Looks like I went bust. You win!"
  Change Gold Held: Add Var(xxxx: Amount Bet)
  COMMENT: If you want to change the prize, then just multiply/divide/whatever the Variable "Amount Bet" and then Add it.
   If Var(xxxx:Dealer Score) > Var(xxxx:Player Score) Then
  Show Message: "Dealer: I'm sorry, you lost..."
  Change Gold Held: Remove Var(xxxx: Amount Bet)
  Go To Label 20
   Else
  Show Message: "Dealer: Looks like you got closer. You win!"
Change Gold Held: Add Var(xxxx: Amount Bet)
  COMMENT: If you want to change the prize, then just multiply/divide/whatever the Variable "Amount Bet" and then Add it.
   End Case
End Case
Label #20

And that's it for the game itself. Now for the Dealer who is going to play the game with you. Whichever map you want the game to be on, you should set the dealer up like this - it will both explain the game to people and check they actually have money to bet before getting them stuck in the "You can't bet nothing" loop above.

Set the dealer up like this, editing the dialogue as you see appropriate...

Code: [Select]
Label #1
Show Message: "Dealer: Do you want to play Pontoon?"
Show Choice: "Yes"/"No"/"Pontoon?"
(Yes) Case
   If Money >= 0 Then
  Call Event: Pontoon
   Else Case
  Show Message: "Dealer: You don't have any money to gamble with."
   End Case
(No) Case
   Show Message: "Dealer: Then please leave the table."
(Pontoon?) Case
   Show Message: "Dealer: Pontoon is a game where you have to get as close as you can to 21 in 5 cards. You are not allowed to go over 21 and you must also get closer than I do."
   Show Message:"Dealer: So..."
   Go To Label #1
End Case

And that's it. Very simple to make, and very editable to your own needs. For example, in "Sore Losers" I am making a game called "Lucky Thirteen" that runs on the same principle but only goes up to 13 and uses cards that number 1 to 13. It basically makes it a lot more difficult for the player to win.

Happy eventing. (Down with RGSS!)

*
Rep: +0/-0Level 62
RMRK Junior
Hi!
Can this be used in RpgMakerVX?
Thanks in advance!

*****
Rep:
Level 85
I am the wood of my broom
2010 Project of the YearProject of the Month winner for January 2009Project of the Month winner for January 2010Project of the Month winner for April 2010
You can convert it to VX by following the instructions on how the events were laid out.