Peril_Dice/RollConfettiModule.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

88 lines
3.3 KiB
Text

// === Roll and Confetti Module ===
integer MSG_SHOW_DIALOG = 101;
integer MSG_ROLL_RESULT = 102;
integer MSG_UPDATE_FLOAT = 103;
integer MSG_CLEANUP_FLOAT = 104;
integer MSG_REZ_FLOAT = 105;
integer MSG_SYNC_GAME_STATE = 107;
list names = [];
list lives = [];
list picksData = [];
string perilPlayer = "";
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, ["|"], []);
return llParseString2List(llList2String(parts, 1), [","], []);
}
}
return [];
}
integer rollDice(integer diceType) {
return 1 + (integer)llFrand(diceType);
}
confetti() {
llParticleSystem([
PSYS_SRC_PATTERN, PSYS_SRC_PATTERN_EXPLODE,
PSYS_PART_START_COLOR, <1,1,1>, PSYS_PART_END_COLOR, <1,1,1>,
PSYS_PART_START_ALPHA, 1.0, PSYS_PART_END_ALPHA, 0.0,
PSYS_PART_START_SCALE, <0.2,0.2,0>, PSYS_PART_END_SCALE, <0.5,0.5,0>,
PSYS_PART_MAX_AGE, 2.0, PSYS_SRC_MAX_AGE, 2.0,
PSYS_SRC_ACCEL, <0,0,-0.4>,
PSYS_SRC_BURST_RATE, 0.01, PSYS_SRC_BURST_PART_COUNT, 50,
PSYS_SRC_BURST_RADIUS, 0.2,
PSYS_SRC_BURST_SPEED_MIN, 1.0, PSYS_SRC_BURST_SPEED_MAX, 2.0,
PSYS_PART_FLAGS, PSYS_PART_INTERP_COLOR_MASK | PSYS_PART_INTERP_SCALE_MASK | PSYS_PART_EMISSIVE_MASK
]);
}
default {
link_message(integer sender, integer num, string str, key id) {
if (num == MSG_ROLL_RESULT) {
integer diceType = (integer)str;
integer result = rollDice(diceType);
string resultStr = (string)result;
llSay(0, "🎲 " + perilPlayer + " rolled a " + resultStr + "!");
string newPeril = "";
integer matched = FALSE;
integer i;
for (i = 0; i < llGetListLength(names); i++) {
string pname = llList2String(names, i);
list picks = getPicksFor(pname);
if (llListFindList(picks, [resultStr]) != -1) {
matched = TRUE;
if (pname != perilPlayer && newPeril == "") {
newPeril = pname;
}
}
}
if (matched && newPeril != "") {
llSay(0, "🎯 " + newPeril + " matched the roll and becomes the new peril player!");
perilPlayer = newPeril;
llMessageLinked(LINK_SET, MSG_REZ_FLOAT, newPeril, NULL_KEY);
} else {
integer pidx = llListFindList(names, [perilPlayer]);
if (pidx != -1) {
integer currentLives = llList2Integer(lives, pidx);
lives = llListReplaceList(lives, [currentLives - 1], pidx, pidx);
llSay(0, "💀 " + perilPlayer + " was hit and lost a life!");
confetti();
llMessageLinked(LINK_SET, MSG_REZ_FLOAT, perilPlayer, NULL_KEY);
}
}
// Send updated game state to floats
string gameSync = llList2CSV(lives) + "~" + llList2CSV(picksData) + "~" + perilPlayer;
llMessageLinked(LINK_SET, MSG_SYNC_GAME_STATE, gameSync, NULL_KEY);
llSleep(0.2);
}
}
}