Peril_Dice/RollConfettiModule.lsl
RebeccaNod1 89a364d2ec Summary of Today’s Work:
Issue Identified:

The main issue was that the floater was showing 0 as the player's pick even after they made a selection, and the correct pick was not being reflected in the float.

Steps Taken:

Improved Data Synchronization: We ensured that the picksData list, which holds player choices, was properly updated and synchronized across all parts of the system.

State Serialization: The game state, including updated picksData, was serialized correctly using the serializeGameState() function. This ensured that the floater was aware of the new state whenever a player's pick changed.

Immediate Float Updates: After updating a player's pick, we immediately sent the new game state (gameSync) to all linked objects to update their floats, ensuring the pick was reflected in the UI.

Key Modifications:

Main Peril Dice Controller: We improved the way we updated picksData and immediately synchronized this update with the floater using MSG_SYNC_GAME_STATE.

StatFloat: Adjustments were made to handle receiving and displaying updated pick data, ensuring that picks were displayed correctly on the float after each update.

Dialog Handling: Proper dialogs were shown to players for pick choices, and feedback on their picks was sent back to update the floats in real-time.

Outcome:

The game now correctly updates and displays the player’s picks on their respective floats immediately after making a choice.

The picks are reflected in the logs as well, with the correct updated pick being shown rather than 0.

Final Result:

The issue of picks not being displayed correctly has been resolved, and the flow of data between the scripts (game state synchronization, float updates, etc.) is working as intended.
2025-07-26 03:52:29 -05:00

89 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);
list parts = llParseString2List(entry, ["|"], []);
if (llList2String(parts, 0) == nameInput) {
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);
}
}
}