Peril_Dice/StatFloat.lsl
RebeccaNod1 f895f9851c
✅ Today's Completed Tasks Summary
🎯 Refactored the Game Architecture
We modularized the original Peril Dice controller into separate cohesive components:

Main Peril Dice Controller

Handles core logic: player join/leave, peril selection, game sync, and communication routing.

Broadcasts updates via MSG_SYNC_GAME_STATE after major state changes.

Applies llSleep(0.2) to improve message delivery reliability.

Dialog Handler Module

Manages the number-picking dialog.

Tracks player picks and updates picksData accordingly.

Sends state sync after every valid pick.

Fixed pick serialization bugs and ensured updates trigger correctly.

Float Rezzer Module

Registers player data and rezzes a StatFloat object beside each participant.

Applies llSetObjectDesc(name); before rezzing for easier identification.

On update, broadcasts llRegionSay messages including current lives, peril, and picks.

StatFloat (HUD Script)

Listens on assigned channel to receive floating text updates.

Parses synced game state from link_message to extract lives, picks, and peril data.

Dynamically follows the avatar.

Enhanced parsing reliability and fixed index mapping for correct player display.

Roll and Confetti Module

Performs dice rolls and checks for matches.

Transfers peril role on match or removes a life otherwise.

Triggers confetti on a miss and updates floats for all players.

🛠 Debugging and Enhancements
Added llOwnerSay debug statements across all modules.

Resolved multiple name not defined within scope (nndws) issues.

Verified and cleaned up serialized game data formats across modules.

Ensured consistent use of player indexing and life count mapping.
2025-07-21 03:22:32 -05:00

81 lines
2.7 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// === StatFloat Enhanced ===
key target;
string displayText;
string myName;
integer MSG_SYNC_GAME_STATE = 107;
list lives;
list picksData;
string perilPlayer;
list names;
list getPicksFor(string nameInput) {
integer i;
for (i = 0; i < llGetListLength(picksData); i++) {
string entry = llList2String(picksData, i);
if (llSubStringIndex(entry, nameInput + "|") == 0) {
list parts = llParseString2List(entry, ["|"], []);
if (llGetListLength(parts) >= 2) {
return llParseString2List(llList2String(parts, 1), [","], []);
}
}
}
return [];
}
default {
state_entry() {
llSetText("⏳ Waiting...", <1,1,1>, 1.0);
llSetTimerEvent(1.0);
}
on_rez(integer start_param) {
llListen(start_param, "", NULL_KEY, "");
myName = llGetObjectDesc();
llOwnerSay("📱 Listening on channel " + (string)start_param + " for " + myName);
}
listen(integer channel, string name, key id, string message) {
if (llSubStringIndex(message, "FLOAT:") == 0) {
list parts = llParseString2List(message, ["|"], []);
if (llGetListLength(parts) >= 2) {
target = (key)llGetSubString(llList2String(parts, 0), 6, -1);
displayText = llList2String(parts, 1);
llSetText(displayText, <1,1,1>, 1.0);
llOwnerSay("✅ StatFloat updated for: " + (string)target);
}
}
else if (message == "CLEANUP") {
llOwnerSay("🪟 Cleaning up...");
llDie();
}
}
link_message(integer sender, integer num, string str, key id) {
if (num == MSG_SYNC_GAME_STATE) {
list parts = llParseString2List(str, ["~"], []);
if (llGetListLength(parts) < 4) return;
lives = llParseString2List(llList2String(parts, 0), [","], []);
picksData = llParseString2List(llList2String(parts, 1), ["~"], []);
perilPlayer = llList2String(parts, 2);
names = llParseString2List(llList2String(parts, 3), [","], []);
integer nameIdx = llListFindList(names, [myName]);
if (nameIdx == -1) return;
list picks = getPicksFor(myName);
integer lifeCount = llList2Integer(lives, nameIdx);
string txt = "🎲 Peril Dice\n👤 " + myName + "\n❤️ Lives: " + (string)lifeCount + "\n🢍 Peril: " + perilPlayer + "\n🔢 Picks: " + llList2CSV(picks);
llSetText(txt, <1,1,1>, 1.0);
}
}
timer() {
if (target != NULL_KEY && llKey2Name(target) != "") {
vector pos = llList2Vector(llGetObjectDetails(target, [OBJECT_POS]), 0) + <1,0,1>;
llSetRegionPos(pos);
}
}
}