~Fiona's Script Library~
game-main.lsl
| 4.29 KB
// Fiona Sweet (_|_) Shakin' it baby
// ClawGame_Main_RLV.lsl - Main game logic with relay RLV lock, release, and owner override menu
list cooldownList;
list toys;
float loseChance = 0.6;
float cooldownPeriod = 15.0;
key currentLoser;
float loseEndTime = 0.0;
string lightPrimName = "TryAgainSign";
list getToyList() {
list toyList;
integer count = llGetInventoryNumber(INVENTORY_OBJECT);
for (integer i = 0; i < count; ++i) {
string name = llGetInventoryName(INVENTORY_OBJECT, i);
if (name != "") toyList += [name];
}
return toyList;
}
showStatus(integer remaining) {
integer totalLinks = llGetNumberOfPrims();
integer found = FALSE;
for (integer i = 1; i <= totalLinks && !found; ++i) {
if (llGetLinkName(i) == lightPrimName) {
if (remaining > 0) {
string message = "Try Again in " + (string)((integer)remaining) + "s";
llSetLinkPrimitiveParamsFast(i, [
PRIM_COLOR, ALL_SIDES, <1, 0, 0>, 1.0,
PRIM_GLOW, ALL_SIDES, 0.3,
PRIM_POINT_LIGHT, TRUE, <1, 0, 0>, 3.0, 0.5, 0.1,
PRIM_TEXT, message, <1, 1, 1>, 1.0
]);
} else {
llSetLinkPrimitiveParamsFast(i, [
PRIM_GLOW, ALL_SIDES, 0.0,
PRIM_POINT_LIGHT, FALSE, ZERO_VECTOR, 0, 0, 0,
PRIM_TEXT, "", ZERO_VECTOR, 1.0,
PRIM_COLOR, ALL_SIDES, <1, 1, 1>, 0.0
]);
llSetTimerEvent(0.0);
currentLoser = NULL_KEY;
loseEndTime = 0.0;
}
found = TRUE;
}
}
}
default {
state_entry() {
toys = getToyList();
llSetTouchText("Play!");
}
touch_start(integer total_number) {
key toucher = llDetectedKey(0);
float now = llGetUnixTime();
integer index = llListFindList(cooldownList, [toucher]);
if (index != -1) {
float lastTime = llList2Float(cooldownList, index + 1);
float elapsed = now - lastTime;
if (elapsed < cooldownPeriod) {
integer wait = (integer)(cooldownPeriod - elapsed);
llSay(0, "Please wait " + (string)wait + " more seconds before trying again.");
showStatus(wait);
return;
}
cooldownList = llListReplaceList(cooldownList, [now], index + 1, index + 1);
} else {
cooldownList += [toucher, now];
}
if (llFrand(1.0) < loseChance) {
currentLoser = toucher;
loseEndTime = now + cooldownPeriod;
llSetTimerEvent(1.0);
} else {
if (llGetListLength(toys) > 0) {
// Trigger particles on a separate prim
integer totalLinks = llGetNumberOfPrims();
integer lossFound = FALSE;
for (integer j = 1; j <= totalLinks && !lossFound; ++j) {
if (llGetLinkName(j) == "LossEffectPrim") {
llMessageLinked(j, 2001, "", toucher);
lossFound = TRUE;
}
}
string prize = llList2String(toys, (integer)llFrand(llGetListLength(toys)));
llGiveInventory(toucher, prize);
llInstantMessage(toucher, "YAY! You won a " + prize + "!");
} else {
//should never get here if you have toys!
llSay(0, "\2 NO TOYS");
}
}
}
timer() {
float now = llGetUnixTime();
float remaining = loseEndTime - now;
showStatus(remaining);
}
}