Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Basic slot machine script?

Snake Ornitz
Basic builder/scripter
Join date: 26 Oct 2005
Posts: 7
05-18-2006 07:26
Hi. I like to make a basic slot machine. What sort of thing should u use, Math? Plz post a basic Slot/Game script.
Nexus Nash
Undercover Linden
Join date: 18 Dec 2002
Posts: 1,084
05-18-2006 08:11
Since no one is touching this, I will.

I'm not gonna post a whole slot machine script because it's very simple. I'll post an example though.

The basic slot machine script. We will make a 50:50 (ie a coin toss)

CODE

default {
touch_start(integer num) {
float num = llFrand(1.0);
if(num > 0.5) {
//win
}
else {
//lose.
}
}
}


Pretty basic but that's how machines usually work. Some might have more then 1 winning condition. For a slot machine, you might be rolling 3 random number from 1 to 10 and have it so that if they are all the same if(num1 == num2 && num2 == num3). Anything bigger would probably take alot more time.
_____________________
Geuis Dassin
Filming Path creator
Join date: 3 May 2006
Posts: 565
05-18-2006 08:31
To add on to this, most random casino games are set so that the house wins at least 90% or more.

When you do llFrand(1), that will generate a random number between 0 and 1. This is also the same as between 0 and 100, aka percentages.

So if you want to make it so that the player has only a 97% chance of winning, you would do something like.

default {
touch_start(integer num) {
float num = llFrand(1.0);
if(num > 0.97) {
//win
}
else {
//lose.
}
}
}

All you have to realize is that a decimal is the same as a percentage, aka .5 = 50%, .9 = 90%, etc.
Draco18s Majestic
Registered User
Join date: 19 Sep 2005
Posts: 2,744
05-18-2006 11:20
From: Geuis Dassin

So if you want to make it so that the player has only a 97% chance of winning, you would do something like.

default {
touch_start(integer num) {
float num = llFrand(1.0);
if(num > 0.97) {
//win
}
else {
//lose.
}
}
}


That code is 97% LOSS.

And it isn't so much that you win 90% of the time, but you win 990% of your money. A "win" condition occurs about 50-70% of the time, but in varrying amounts.
Geuis Dassin
Filming Path creator
Join date: 3 May 2006
Posts: 565
05-18-2006 11:36
doh! yes, please change that to < instead of >
Eddy Stryker
libsecondlife Developer
Join date: 6 Jun 2004
Posts: 353
05-18-2006 14:14
Slot machines aren't quite that simple. They have wheels that spin (animation) for varying amounts of time, it has to take money, pay out money, show a little LCD with how much money it's currently holding, do the math on winning / losing, etc. I actually have a complete three wheel slot machine with five character LCD that looks similar to the ones you see all over SL, but I don't have access to in-game right now. Leave me an IM and I can get to it.