If you decide to use this in-world as-is, you must make the source and object available for free to anyone who requests it. Sell this code as-is and I'll eat your soul.
CODE
// BinSnipe Lotto Ball
// Copyright (C) 2007 Dragon Keen
float time = 900;
integer min_amt = 10;
float seconds_passed = 0.0;
list entries;
integer pot = 0;
float cpf = 0;
integer cpi = 0;
key lastperson = NULL_KEY;
float lastpercent = 0.20;
float ownerpercent = 0.10;
integer minutes_left;
string line1 = "PaySnipe Lotto Ball!!";
float setTime;
integer ON = 1;
integer SHOUT = 1;
// see if key is already in the list
integer isNameOnList( key name )
{
list single_name_list;
single_name_list += name;
return (-1 != llListFindList( entries, single_name_list ) );
}
// function to change the text
ChangeText ()
{
string string1;
string string2;
minutes_left = (integer)time / 60;
if (lastperson == NULL_KEY)
string1 = "No one has donated over $" + (string)min_amt + " yet!!\n";
else
string1 = llKey2Name(lastperson) + " is the last to donate, and will win $" + (string)cpi + "\n";
if (time > 120.0)
string2 = (string)minutes_left + " minutes left\n";
else if ((time <= 120.0) && (time >= 60.0))
{
string2 = "TWO MINUTE WARNING\n";
if (SHOUT) llShout (0, "YOUR RUNNING OUT OF TIME GET YOUR LAST BET IN SOON!!");
else llSay (0, "YOUR RUNNING OUT OF TIME GET YOUR LAST BET IN SOON!!");
}
else if (time < 60)
string2 = "ANY SECOND NOW... HURRY!!";
if (ON) llSetText(line1 + "\nTotal Prize Pool = $" + (string)pot + "\n" + string1 + string2, <0.0,1.0,0.0>, 1);
else llSetText("Ball Currently OFF", <0.0,1.0,0.0>, 1);
}
restart()
{
//start over reset timer
time = setTime;
pot = 0; //resets pot
lastperson = NULL_KEY; // clears last person
entries = []; // clears list
//minutes_left = 60;
llSetTimerEvent(60); // changes timer back
if (SHOUT) llShout(0, "New round has started, GET YOUR DONATIONS IN!!");
else llSay(0, "New round has started, GET YOUR DONATIONS IN!!");
ChangeText();
}
default
{
on_rez(integer start_param)
{
llResetScript();
}
state_entry()
{
llSetTimerEvent(60);
setTime = time;
minutes_left = (integer)time / 60;
ChangeText();
llTargetOmega(<0,0,1>,PI,1.0);
llRequestPermissions(llGetOwner(),PERMISSION_DEBIT);
if (SHOUT) llShout (0, "PaySnipe Lotto NOW Activated. Get your donations in");
else llSay (0, "PaySnipe Lotto NOW Activated. Get your donations in");
//listen for commands on channel 128
llListen(128, "", llGetOwner(), "");
}
timer()
{
// where code after time is up goes
if (time > 60.0) // if there is still more than 1 minutes remaining
{
time = time - 60; // minute has passed, subtract from time to run game
ChangeText();
}
else if (time == 60.0)
{
// randomize last seconds to prevent cheating
time = ((integer)llFrand(55.0)) + 3;
time = time - 1; //start subtracting seconds
llSetTimerEvent(1); // change timer to one second
// change floating text
ChangeText();
//announce final seconds
if (SHOUT) llShout (0, "PaySnipe Lotto in the final seconds!! Get your last donations in!!");
else llSay (0, "PaySnipe Lotto in the final seconds!! Get your last donations in!!");
}
else if ((time < 60) & (time != 0))
{
time = time - 1;
}
else if (time == 0)
{
if (pot == 0 || entries == [])
{
llSay(0, "No players, no winner... restarting round");
restart();
}
else
{
if (SHOUT) llShout (0, "DONATIONS CLOSED -- FINDING A WINNER");
else llSay (0, "DONATIONS CLOSED -- FINDING A WINNER");
llSleep (2);
// close out the cycle, find a winner, calculate payouts
//pay CPI to last bettor
llGiveMoney(lastperson, cpi);
if (SHOUT) llShout (0, llKey2Name(lastperson) + " has won $" + (string)cpi + " for betting last!!");
else llSay (0, llKey2Name(lastperson) + " has won $" + (string)cpi + " for betting last!!");
llSleep(2);
// calculate owner percentage
integer ownerpay = llFloor((float)pot * ownerpercent);
// randomize list, pay winner
pot = pot - ownerpay - cpi;
list randomlist = llListRandomize(entries, 1);
integer x = llFloor(llFrand(llGetListLength(randomlist)));
key winner_key = llList2Key(randomlist, x);
llGiveMoney(winner_key, pot);
if (SHOUT) llShout(0, "AND THE WINNER IS..... " + llKey2Name(winner_key) + "!!! Congrats!!!");
else llSay(0, "AND THE WINNER IS..... " + llKey2Name(winner_key) + "!!! Congrats!!!");
llSetTimerEvent(0);
restart();
}
}
}
touch_start(integer total_number) // if touched
{
llSay(0, "PaySnipe Lotto Ball - Last to bet wins a portion");
llSay(0, "Right click, and pay any amount");
llSay(0, "Must pay at least $" + (string)min_amt + " to be eligible for the snipe pot");
if (llDetectedKey(0) == llGetOwner())
{
integer foo;
integer foo1;
foo = llFloor(ownerpercent * 100);
foo1 = llFloor(lastpercent * 100);
llInstantMessage(llDetectedKey(0), "===================");
llInstantMessage(llDetectedKey(0), "Owner gets " + (string)foo + "%");
llInstantMessage(llDetectedKey(0), "Last Person gets " + (string)foo1 + "%");
llInstantMessage(llDetectedKey(0), "Random winner gets the rest");
if (SHOUT) llInstantMessage(llDetectedKey(0), "Shout is currently on");
else llInstantMessage(llDetectedKey(0), "Shout is currently off");
}
}
money(key giver, integer amount)
{
if(ON)
{
pot = pot + amount;
minutes_left = (integer)time / 60;
if ((amount >= min_amt) && (giver != llGetOwner())) lastperson = giver;
cpf = (float)pot * lastpercent; // calc percentage
cpi = (integer)cpf; // get it into integer format
// add to list if not already on it
if(( isNameOnList( giver ) == FALSE ) && (giver != llGetOwner()))
entries += [giver];
if (giver == llGetOwner())
if (SHOUT) llShout(0, "The owner has donated $" + (string)amount + " to the pot!!!");
else llSay(0, "The owner has donated $" + (string)amount + " to the pot!!!");
ChangeText();
}
else
{
llInstantMessage(giver, "Ball is off, refunding your payment");
llGiveMoney(giver, amount);
}
}
// Listen for commands
listen(integer channel, string name, key id, string message)
{
// get what was said
list said = llParseString2List(message, [" "], []);
if (llToLower(llList2String(said, 0)) == "set")
{
if (llToLower(llList2String(said, 1)) == "time")
{
// changes time on lotto ball
time = 60 * llList2Float(said, 2);
setTime = time;
minutes_left = (integer)time / 60;
ChangeText();
llSay (0, "Time changed to " + llList2String(said, 2) + " minutes");
ChangeText();
}
else if (llToLower(llList2String(said, 1)) == "lastplayer")
{
// changes percentage going to the last player
lastpercent = llList2Float(said, 2) / 100;
llSay (0, "Last Person Percentage changed to " + llList2String(said, 2) + "%");
}
else if (llToLower(llList2String(said, 1)) == "min")
{
// changes minimum amount to qualify for last bet
min_amt = llList2Integer(said, 2);
llSay (0, "Minimum bet to qualify for PaySnipe changed to L$" + llList2String(said, 2));
}
else if (llToLower(llList2String(said, 1)) == "owner")
{
// changes percentage going to the owner
ownerpercent = llList2Float(said, 2) / 100;
llSay (0, "Owner Percentage changed to " + llList2String(said, 2) + "%");
}
else if (llToLower(llList2String(said, 1)) == "line1")
{
// changes the first line
line1 = "";
integer x;
integer y = llGetListLength(said);
for (x = 2; x <= y; x++)
{
line1 = line1 + llList2String(said, x) + " ";
}
//line1 = llList2String(said, 2);
llSay (0, "First line changed to " + line1);
ChangeText();
}
else if (llToLower(llList2String(said, 1)) == "off")
{
ON = 0;
llSetTimerEvent(0);
ChangeText();
}
else if (llToLower(llList2String(said, 1)) == "on")
{
ON = 1;
restart();
}
else if (llToLower(llList2String(said, 1)) == "say")
{
SHOUT = 0;
llSay (0, "Normal chat will be used");
}
else if (llToLower(llList2String(said, 1)) == "shout")
{
SHOUT = 1;
llSay (0, "Shouting will be used");
}
} // end set statement
} // end listen for commands
} //end bracket