fixed leaving game
This commit is contained in:
parent
d96b92a989
commit
61ff39cee0
2 changed files with 35 additions and 0 deletions
30
Main.lsl
30
Main.lsl
|
|
@ -288,6 +288,36 @@ default {
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
// Handle leave game requests
|
||||||
|
if (num == 107) {
|
||||||
|
list parts = llParseString2List(str, ["|"], []);
|
||||||
|
if (llList2String(parts, 0) == "LEAVE_GAME") {
|
||||||
|
string leavingName = llList2String(parts, 1);
|
||||||
|
key leavingKey = (key)llList2String(parts, 2);
|
||||||
|
integer idx = llListFindList(players, [leavingKey]);
|
||||||
|
if (idx != -1) {
|
||||||
|
// Remove player's float
|
||||||
|
integer ch = -777000 + idx;
|
||||||
|
llMessageLinked(LINK_SET, MSG_CLEANUP_FLOAT, (string)ch, NULL_KEY);
|
||||||
|
// Remove from all lists
|
||||||
|
players = llDeleteSubList(players, idx, idx);
|
||||||
|
names = llDeleteSubList(names, idx, idx);
|
||||||
|
lives = llDeleteSubList(lives, idx, idx);
|
||||||
|
picksData = llDeleteSubList(picksData, idx, idx);
|
||||||
|
// Update helpers
|
||||||
|
updateHelpers();
|
||||||
|
llOwnerSay("👋 " + leavingName + " left the game");
|
||||||
|
// Check if game should end (less than 2 players)
|
||||||
|
if (llGetListLength(names) == 1) {
|
||||||
|
llSay(0, " " + llList2String(names, 0) + " is the last player standing and wins the game!");
|
||||||
|
resetGame();
|
||||||
|
} else if (llGetListLength(names) == 0) {
|
||||||
|
resetGame();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
listen(integer channel, string name, key id, string msg) {
|
listen(integer channel, string name, key id, string msg) {
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,11 @@ default {
|
||||||
llMessageLinked(LINK_SET, MSG_REGISTER_PLAYER, pname + "|" + (string)id, NULL_KEY);
|
llMessageLinked(LINK_SET, MSG_REGISTER_PLAYER, pname + "|" + (string)id, NULL_KEY);
|
||||||
llMessageLinked(LINK_SET, MSG_REZ_FLOAT, pname, id);
|
llMessageLinked(LINK_SET, MSG_REZ_FLOAT, pname, id);
|
||||||
}
|
}
|
||||||
|
else if (msg == "Leave Game") {
|
||||||
|
// Send leave game message to main controller
|
||||||
|
string pname = llKey2Name(id);
|
||||||
|
llMessageLinked(LINK_SET, 107, "LEAVE_GAME|" + pname + "|" + (string)id, NULL_KEY);
|
||||||
|
}
|
||||||
else if (msg == "Manage Picks") {
|
else if (msg == "Manage Picks") {
|
||||||
llMessageLinked(LINK_THIS, 202, "REQUEST_PLAYER_LIST", id);
|
llMessageLinked(LINK_THIS, 202, "REQUEST_PLAYER_LIST", id);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue