From e7b853600a1c47eaf5a86af2becede852289fc70 Mon Sep 17 00:00:00 2001 From: RebeccaNod1 Date: Fri, 1 Aug 2025 20:09:28 -0500 Subject: [PATCH] updated main and diolog for owner --- Main.lsl | 98 ++++++++++++++++++++++------- Owner and Player Dialog Handler.lsl | 60 +++++++++++------- 2 files changed, 112 insertions(+), 46 deletions(-) diff --git a/Main.lsl b/Main.lsl index 8646d2d..20f75b1 100644 --- a/Main.lsl +++ b/Main.lsl @@ -1,6 +1,12 @@ -// === Main Peril Dice Controller (Refactored with Game Helpers Integration) === +// === Main Peril Dice Controller (Refactored with Game Helpers Integration, with dynamic player join) === -// --- Variables --- +// +// This version of the main game controller includes support for players (including +// the owner) joining the game at runtime via a MSG_REGISTER_PLAYER message. When +// a new player registers, they are added to the internal lists (players, names, +// lives and picksData), a floating display is rezzed for them, and helpers are +// updated. This mirrors the behaviour used when adding a test player, but now +// applies to any avatar joining the game via the dialog handler. integer syncChannel = -77777; integer numberPickChannel = -77888; @@ -48,7 +54,8 @@ key currentPicker; // Forward game state to helpers when it changes updateHelpers() { - string serialized = llList2CSV(lives) + "~" + llList2CSV(picksData) + "~" + perilPlayer + "~" + llList2CSV(names); + string serialized = llList2CSV(lives) + "~" + llList2CSV(picksData) + + "~" + perilPlayer + "~" + llList2CSV(names); llMessageLinked(LINK_SET, MSG_SYNC_GAME_STATE, serialized, NULL_KEY); llMessageLinked(LINK_SET, MSG_SYNC_PICKQUEUE, llList2CSV(pickQueue), NULL_KEY); } @@ -81,7 +88,7 @@ resetGame() { pickQueue = []; currentPickerIdx = 0; llSay(syncChannel, "RESET"); - llOwnerSay("๐Ÿ”„ Game reset!"); + llOwnerSay(" Game reset!"); llSleep(0.2); llSetTimerEvent(0); updateHelpers(); @@ -89,21 +96,18 @@ resetGame() { startNextRound() { if (llGetListLength(names) == 1) { - llSay(0, "๐Ÿ† " + llList2String(names, 0) + " is the last player standing and wins the game!"); + llSay(0, " " + llList2String(names, 0) + " is the last player standing and wins the game!"); resetGame(); return; } - picksData = []; globalPickedNumbers = []; pickQueue = names; currentPickerIdx = 0; - integer j; for (j = 0; j < llGetListLength(names); j++) { picksData += [llList2String(names, j) + "|"]; } - updateHelpers(); // requestDiceType(); // Removed to avoid recursion loop } @@ -130,6 +134,8 @@ default { key toucher = llDetectedKey(0); integer idx = llListFindList(players, [toucher]); if (toucher == llGetOwner()) { + // Owner touches the prim: show menu for owner if already registered; else start as not starter + // Pass isStarter=0 because owner is never automatically starter until players join llMessageLinked(LINK_SET, MSG_SHOW_MENU, "owner|0", toucher); } else if (idx != -1) { integer isStarter = (idx == 0); @@ -138,6 +144,7 @@ default { } link_message(integer sender, integer num, string str, key id) { + // Player list and pick list handling remain unchanged if (num == 202 && str == "REQUEST_PLAYER_LIST") { string namesCSV = llList2CSV(names); llMessageLinked(LINK_SET, 203, namesCSV, id); @@ -166,24 +173,33 @@ default { } return; } + // Handle dice type result from helper if (num == MSG_DICE_TYPE_RESULT) { if (!roundStarted) { roundStarted = TRUE; diceType = (integer)str; - llOwnerSay("๐ŸŽฒ Dice type set to: " + str); + llOwnerSay(" Dice type set to: " + str); showNextPickerDialog(); } + return; } - else if (num == MSG_GET_PICKS_REQUIRED) { + if (num == MSG_GET_PICKS_REQUIRED) { integer picksRequired = (integer)str; - llOwnerSay("๐Ÿ“Œ Picks required: " + str); - } else if (num == MSG_GET_PICKER_INDEX) { + llOwnerSay(" Picks required: " + str); + return; + } + if (num == MSG_GET_PICKER_INDEX) { integer pickIndex = (integer)str; - llOwnerSay("๐Ÿ” Picker index: " + str); - } else if (num == MSG_SERIALIZE_GAME_STATE) { + llOwnerSay(" Picker index: " + str); + return; + } + if (num == MSG_SERIALIZE_GAME_STATE) { string serialized = str; - llOwnerSay("๐Ÿงพ Serialized game state: " + serialized); - } else if (num == 204) { + llOwnerSay(" Serialized game state: " + serialized); + return; + } + // Handle pick actions + if (num == 204) { list parts = llParseString2List(str, ["~"], []); string action = llList2String(parts, 0); list args = llParseString2List(llList2String(parts, 1), ["|"], []); @@ -216,25 +232,59 @@ default { return; } } + return; + } + // New: handle dynamic registration of players (owner or players) via MSG_REGISTER_PLAYER + if (num == MSG_REGISTER_PLAYER) { + // str is in the format "Name|" + list parts = llParseString2List(str, ["|"], []); + string newName = llList2String(parts, 0); + key newKey = (key)llList2String(parts, 1); + // Do not register if already present + integer existingIdx = llListFindList(players, [newKey]); + if (existingIdx == -1) { + // Add to local lists + players += [newKey]; + names += [newName]; + lives += [3]; + picksData += [newName + "|"]; + // Rez a float for the new player + llMessageLinked(LINK_SET, MSG_REZ_FLOAT, newName, newKey); + llSleep(0.2); + updateHelpers(); + // Notify owner of registration + llOwnerSay("๐Ÿ”” Added player: " + newName); + } + return; } } listen(integer channel, string name, key id, string msg) { if (channel == DIALOG_CHANNEL) { + // Owner-specific commands: only owner messages in the dialog should be processed here. if (id == llGetOwner()) { if (msg == "Reset Game") { resetGame(); - } else if (msg == "Start Game") { + return; + } + if (msg == "Start Game") { startNextRound(); requestDiceType(); - } else if (msg == "Dump Players") { - llOwnerSay("๐Ÿ“‹ Players: " + llList2CSV(names)); - } else if (msg == "Manage Picks") { - llOwnerSay("๐Ÿ“‹ Fetching list of players for pick management..."); + return; + } + if (msg == "Dump Players") { + llOwnerSay(" Players: " + llList2CSV(names)); + return; + } + if (msg == "Manage Picks") { + llOwnerSay(" Fetching list of players for pick management..."); llMessageLinked(LINK_SET, 202, "REQUEST_PLAYER_LIST", llGetOwner()); - } else if (msg == "Add Test Player") { + return; + } + if (msg == "Add Test Player") { string name = "TestBot" + (string)llGetUnixTime(); key fake = llGenerateKey(); + // Add the test player to lists and register them with floater manager players += [fake]; names += [name]; lives += [3]; @@ -244,11 +294,13 @@ default { llSleep(0.2); updateHelpers(); llMessageLinked(LINK_SET, MSG_SHOW_MENU, "owner|0", llGetOwner()); + return; } } + // If the message text matches a player name, request their pick list if (llListFindList(names, [msg]) != -1) { llMessageLinked(LINK_SET, 206, msg, id); } } } -} +} \ No newline at end of file diff --git a/Owner and Player Dialog Handler.lsl b/Owner and Player Dialog Handler.lsl index 5e51d96..91cd847 100644 --- a/Owner and Player Dialog Handler.lsl +++ b/Owner and Player Dialog Handler.lsl @@ -1,4 +1,6 @@ -// === Dialog Handler (Owner & Player) === +// === Dialog Handler (Owner & Player) with unified Ready/Leave menu === +// Owners and players share the same Ready/Leave dialog. +// Owners also get an "Owner" button to access advanced options. integer DIALOG_CHANNEL = -88888; integer MSG_SHOW_MENU = 201; @@ -7,25 +9,36 @@ integer MSG_PLAYER_LIST_RESULT = 203; integer MSG_PICK_LIST_RESULT = 205; integer MSG_LIFE_LOOKUP = 207; +// Owner-specific options shown when pressing the "Owner" button list ownerOptions = ["Join Game", "Leave Game", "Add Test Player", "Manage Picks", "Start Game", "Reset Game", "Dump Players"]; -list playerOptions = ["Start", "Ready"]; +// Display the debug/owner menu +showOwnerMenu(key id) { + llDialog(id, "๐Ÿ”ง Owner Menu", ownerOptions, DIALOG_CHANNEL); +} + +// Display the combined Ready/Leave menu for both players and owners +// If the caller is the starter, the first button is "Start"; otherwise "Ready". +// Owners receive an extra "Owner" button to access the advanced owner menu. +showReadyLeaveMenu(key id, integer isStarter, integer isOwner) { + list options; + if (isStarter) { + options = ["Start", "Leave Game"]; + } else { + options = ["Ready", "Leave Game"]; + } + if (isOwner) { + options += ["Owner"]; + } + // Display the combined menu + llDialog(id, "Select an option:", options, DIALOG_CHANNEL); +} + +// Manage picks UI helpers remain unchanged list currentPickList; string currentPickTarget; integer currentPickLimit = 3; -showOwnerMenu(key id) { - llDialog(id, "๐Ÿ”ง Debug Menu", ownerOptions, DIALOG_CHANNEL); -} - -showPlayerMenu(key id, integer isStarter) { - if (isStarter) { - llDialog(id, "You are the game starter. Click Start to begin when all are ready.", playerOptions, DIALOG_CHANNEL); - } else { - llDialog(id, "Click Ready when you are ready to begin.", ["Ready"], DIALOG_CHANNEL); - } -} - showPickManageMenu(key id, list playerNames) { list options = []; integer i; @@ -69,13 +82,12 @@ default { } string targetType = llList2String(args, 0); integer isStarter = (integer)llList2String(args, 1); - + // We treat owners and players the same for the Ready/Leave menu. + // If the targetType is "owner" we pass isOwner=TRUE and display the extra Owner button. if (targetType == "owner") { - llOwnerSay("๐Ÿ‘ค Showing owner menu"); - showOwnerMenu(id); + showReadyLeaveMenu(id, isStarter, TRUE); } else if (targetType == "player") { - llOwnerSay("๐Ÿ‘ฅ Showing player menu"); - showPlayerMenu(id, isStarter); + showReadyLeaveMenu(id, isStarter, FALSE); } } else if (num == MSG_PLAYER_LIST_RESULT) { @@ -105,7 +117,11 @@ default { } listen(integer channel, string name, key id, string msg) { - if (msg == "Manage Picks") { + // Handle menus: if the user selects "Owner" on the combined menu, display the owner options. + if (msg == "Owner") { + showOwnerMenu(id); + } + else if (msg == "Manage Picks") { llMessageLinked(LINK_THIS, 202, "REQUEST_PLAYER_LIST", id); } else if (llSubStringIndex(msg, "๐Ÿ›  ") == 0) { @@ -127,19 +143,18 @@ default { llSleep(0.2); llMessageLinked(LINK_THIS, 206, currentPickTarget, id); } + // Forward numeric picks to the game logic else if ((integer)msg > 0) { if (llGetListLength(currentPickList) >= currentPickLimit) { llOwnerSay("โš ๏ธ Reached pick limit of " + (string)currentPickLimit + " for " + currentPickTarget); showPickListMenu(id); return; } - if (llListFindList(currentPickList, [msg]) != -1) { llOwnerSay("โš ๏ธ Pick already exists: " + msg); showPickListMenu(id); return; } - integer i; for (i = 0; i < llGetListLength(currentPickList); i++) { if (llList2String(currentPickList, i) == msg) { @@ -147,7 +162,6 @@ default { return; } } - string payload = "ADD_PICK~" + currentPickTarget + "|" + msg; llMessageLinked(LINK_THIS, MSG_PICK_ACTION, payload, id); llSleep(0.2);