//
// Slot Machine
//
integer CHANNEL = 13;
integer bet_amount = 0;
key bettor;
string owner;
integer lit = FALSE;
integer not_registered = TRUE;
integer wheel1_score;
integer wheel2_score;
integer wheel3_score;
integer PAYOUT_ONEBAR = 1;
integer PAYOUT_TWOSAME = 1;
integer PAYOUT_THREESAME = 20;
integer PAYOUT_THREEBAR = 100;
integer MAX_BET = 500;
integer MAX_PAYOUT_BEFORE_RESET = 10000;
integer needs_reset = FALSE;
integer in_play = FALSE;
integer ringer_countdown = 0;
integer num_plays = 0;
integer amount_bet = 0;
integer amount_paid = 0;
init()
{
reset_wheels();
llSay(0, "Click money button to register new machine to owner");
//llListen(CHANNEL, "Wheel 1", "", "");
//llListen(CHANNEL, "Wheel 2", "", "");
//llListen(CHANNEL, "Wheel 3", "", "");
llSetTimerEvent(0.5);
llStopSound();
}
reset_wheels()
{
wheel1_score = 0;
wheel2_score = 0;
wheel3_score = 0;
}
default
{
state_entry()
{
init();
}
on_rez( integer param )
{
init();
}
timer()
{
//
// Periodically blink red
//
if (!not_registered && !needs_reset)
{
if (lit == TRUE)
{
lit = FALSE;
llSetColor(<0.5, 0.5, 0.5>, -1);
}
else
{
lit = TRUE;
llSetColor(<1.0, 1.0, 1.0>, -1);
}
}
if (llFrand(1.0) < 0.02)
{
// llTriggerSound("trill", 0.2);
}
}
run_time_permissions(integer type)
{
if (type == PERMISSION_DEBIT)
{
llSay(0, "New Machine registered to " + owner);
not_registered = FALSE;
}
}
touch_start(integer total_number)
{
if ((not_registered == TRUE) && (!needs_reset))
{
owner = llDetectedName(0);
key agent = llDetectedKey(0);
llRequestPermissions(agent, PERMISSION_DEBIT);
llSay(0, "Requesting debit permission from owner: " + owner);
}
else
{
if (llGetOwner() == llDetectedKey(0))
{
llSay(0, "Num Plays = " + (string) num_plays);
llSay(0, "Amt bet = " + (string) amount_bet);
llSay(0, "Amt paid = " + (string) amount_paid);
}
else
{
if (!needs_reset)
{
llSound("switch", 1.0, FALSE, FALSE);
llSay(0, "Right click and 'pay' to play.");
llSay(0, "$1 bet... 1 Bar = $1, 2 same = $1, 3 same = $100");
}
else
{
llSay(0, "This machine is currently down for servicing");
}
}
}
}
money(key giver, integer amount)
{
if (in_play)
{
llSay(0, "Another bet is in play");
llGiveMoney(giver, amount);
return;
}
if (amount > MAX_BET)
{
llSay(0, "Max bet is $" + (string)MAX_BET);
llGiveMoney(giver, amount);
}
else
{
if (!needs_reset)
{
llSay(0, "$" + (string)amount + " bet!");
bet_amount = amount;
bettor = giver;
reset_wheels();
in_play = TRUE;
//llWhisper(CHANNEL, "wheel:spin");
llMessageLinked( LINK_SET,0,"wheel:spin",NULL_KEY);
llSound("handle", 1.0, FALSE, FALSE);
num_plays++;
amount_bet += amount;
}
else
{
llSay(0, "This machine currently down for servicing");
llGiveMoney(giver, amount);
}
}
}
//listen(integer channel, string name, key id, string message)
link_message( integer set, integer message , string name, key id )
{
//
// Accumulate wheel scores
//
//llSay(0, name);
if (name == "Wheel 1")
{
wheel1_score = (integer)message;
//llSay(0, "Wheel 1 " + (string) wheel1_score);
}
if (name == "Wheel 2")
{
wheel2_score = (integer)message;
//llSay(0, "Wheel 2 " + (string) wheel2_score);
}
if (name == "Wheel 3")
{
wheel3_score = (integer)message;
//llSay(0, "Wheel 3 " + (string) wheel3_score);
}
//
// Done spinning?
//
if ((wheel1_score > 0) && (wheel2_score > 0) && (wheel3_score > 0))
{
//
// Compute score
//
integer three_same = FALSE;
integer two_same = FALSE;
integer one_bar = FALSE;
integer three_bar = FALSE;
integer score;
score = wheel1_score + wheel2_score + wheel3_score;
if (score == 3) three_bar = TRUE;
if ((wheel1_score == wheel2_score) &&
(wheel2_score == wheel3_score)) three_same = TRUE;
if ((wheel1_score == wheel2_score) ||
(wheel2_score == wheel3_score) ||
(wheel3_score == wheel1_score)) two_same = TRUE;
if ((wheel1_score == 1) ||
(wheel2_score == 1) ||
(wheel3_score == 1) ) one_bar = TRUE;
//
// Compute payout
//
integer payout = 0;
if (three_bar == TRUE)
{
payout = PAYOUT_THREEBAR;
ringer_countdown = 6;
}
else if (three_same)
{
payout = PAYOUT_THREESAME;
ringer_countdown = 12;
}
else if (two_same)
{
payout = PAYOUT_TWOSAME;
ringer_countdown = 3;
}
else if (one_bar)
{
payout = PAYOUT_ONEBAR;
ringer_countdown = 1;
}
if (bet_amount > 0 && (payout > 0))
{
llTriggerSound("payout", 2.0);
llTriggerSound("bell", 1.0);
llGiveMoney(bettor, bet_amount * payout);
llSay(0, "winner");
llSay(0, "Winner! $" + (string) (bet_amount * payout));
amount_paid += (bet_amount * payout);
if (amount_paid > MAX_PAYOUT_BEFORE_RESET)
{
needs_reset = TRUE;
llEmail(llGetObjectDesc(), "Slot:limit exceeded", "");
}
}
else
{
//
// No win - play sound
//
llSay(0, "Thanks for playing!");
llTriggerSound("no_win", 1.0);
}
in_play = FALSE;
bet_amount = 0;
}
}
}