DORKLORD'S NOSCRIPT SLOT MACHINE

NoScript Slot Machine Tutorial with editable sample project fully commented

  • DorkLord
  • 03/18/2014 07:05 AM
  • 3842 views
DorkLord's VX Ace NoScript Slot Machine
(...or Fun With Variables)

(aka BossGalaga)

Download the Fully Editable Project File from:
Google Drive (2mb) or Steam Workshop



A video showing off the Slot Machine from my recent game, Cliche Quest.



FEATURES:

Fully commented event code
3 Reel Slot Machine, Fully animated!
Spins are randomized on each reel.
Controlled by one event, about 20 pages worth of event code but easier than it looks.
Fully configurable prize combinations, side prizes and random prizes.
Unique (one time) prizes! (prizes that can only be won once)
Configurable odds/payout rate by adding custom
Addicting!
*Now Ralph has a gambling problem*

WHAT IS IT?
This is a sample project showing off a no script 3 reel Slot Machine that I created for my new episodic game Cliche Quest. This Slot Machine was fully evented from scratch. Would it have been easier to script it instead? Probably...a little but still would have used the same method.

HOW IT WORKS
To understand how this works you should have at least a basic understanding of using switches, variables, labels and conditional branching. The slot machine uses 9 variables, 5 switches and 3 events.

Switches: FreePullUsed, SlotPrizeWon, UniquePrize1, 2 and 3.
Variables: Slot1position, 2, 3, Slot1random, 2, 3, Slot1spintime, 2, 3

1 event serves to reset the slot position variables when a player enters the room/map.
3 events are used to display the reels on the slot machine. These are empty events that only serve to display a graphic. 1 event controls the prize chest, which opens up and gives the player a prize if they've won a main prize and finally, the event attached to the lever is what controls the entire slot machine. 1 additional event is called animation-placeholder. This is an empty event that we use as a target for a Show Animation effect if the player gets a jackpot or 2 or 3 skulls in a row.

The machine uses an edited charset with the 8 slot symbols copy&pasted in each character set, that way when using Set Move Route to change the graphic, we don't have to use the Turn command to set it to a specific frame.

So our goal is to have a slot machine, with 3 reels with 8 symbols on each reel, that spin around and then stop at a random position and see if we won a prize or not. This is all done inside a loop until the machine has finished spinning and checking to see if a prize was won.

The machine starts by using Control Variable to set slot1/2/3random variables to a random number between 0 and 15.

Then those variables are set to equal our Slot1/2/3 spintime variables, which are used to determine how long to spin the reels for.

Since we want to spin the reels for more than 0-15 frames we also add 128, 144 and 160 extra spintime to each variable. This gives us a healthy amount of spin on the reels and also makes it so the first reel will countdown to 0 first, followed by the second and then the third.

Now, we want the machine to spin for more than 0-15 frames, so I'm going I add 128, 144 and 160 spins Conditional Branching which checks the Slot1/2/3position variables is used to update the graphics displayed on the reels. Then an increasing Wait time is added after the graphics update phase so the reels appear to slow down the closer they get to finishing their spins.

As long as the slotXspintime doesn't = 0, we increment the slot position. If it was at position 7, we add +1 and move it to position 8. If the position has reached 9 (remember we have 8 symbols) then we use Control Variable again and set that slotposition to 1, because it has completed a full revolution.

Finally, we -1 from each spintime variable.

After this is done, we enter the prize checking phase and use Conditional Branches to see if Slot1, 2 and 3 match any of the prize combinations that we have previously set. For instance, in this example 2, 2, 2 is 3 coins which is a jackpot.

If the player has won a main prize, I set the slotprize variable to the prize I want them to win, set the SlotPrizeWon switch to on and then tell the player they have won and can get their prize from the chest, then use a Jump to Label command to send them to the end of the event code and avoid checking for any other matches or side prizes. It's not necessary to use the chest to dole out prizes but that's just how I chose to make it. If you don't want to use the chest you can delete it and make some slight edits to the prize checking part of the event code.

I also have "side prizes" enabled on the machine. If the player doesn't have a winning combination from the set of main prize combinations then I check to see if they at least a side by side pair. If they do they get either a small prize or a random prize.

And that's basically it. I encourage you, if you're interested to download the project, check it out, play with it and study the event coding. The concepts used in this project can be applied to various other projects as well.

Extra Challenges: 2/2

Control the Reel Stops: By adding a conditional branch that checks for a keypress by the player, we can make it so the player has to press a key to stop each reel. After a keypress has been detected we can decide on how much longer that reel should spin and then stop it after that set amount of spintime.

Vegas Odds: By "rolling" a weighted random variable at the beginning we can increase the player's odds of getting a specific symbol on each reel. So for example, I would roll a random variable between 1 and 8. If it's a 1 or 2 then Slot X will be set to stop on a Skull. If it's a 3, 4 or 5 Slot X will be set to stop on a Potion. If it's a 6, 7, 8, 9 or 10 then slot X will be rolled again (1-8) and set to any random symbol. This way, the player will have a higher chance of getting either a skull or a potion on any given reel. This could increase the rate of smaller prizes won but also increase the danger of getting skulls. After we have predetermined what slotposition we want each reel to stop at we would simply add or subtract from the spintimer for each reel so it will end on that predetermined reel, after which we would enter into the actual reel spinning loop.

Think you can do better? imProve it!
Yes, there are some things here that could have been done more efficiently. Feel free to tinker with it, share back or post comments, suggestions and other feedback.

Terms of Use:

Free to use/modify/improve in Commercial/Non-Commercial Projects.
Give Credit to Richard Colletta aka DorkLord @ RPGMaker.Net/RPGMakerWeb
Do not redistribute as your own work.
Pages: 1