Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Configuration - List of authorised Avi's to add homes and points
- list authAvi = ["UUID1", "UUID2"];
- // Updates and displays the leaderboard on the prim
- UpdateLeaderboard()
- {
- list homess = [];
- list scores = [];
- integer numEntries = llGetLinksetDataCountkey();
- // Collect homes and their scores from linkset data
- integer i;
- for (i = 0; i < numEntries; i++)
- {
- string dataKey = llGetLinksetDataKey(i);
- if (llSubStringIndex(dataKey, "score_") == 0)
- {
- string home = llDeleteSubString(dataKey, 0, 6); // Remove "score_" prefix
- integer score = (integer)llGetLinksetData(dataKey);
- home += home;
- scores += score;
- }
- }
- // Sort the homes by score in descending order
- list sortedLeaderboard = [];
- integer j;
- for (j = 0; j < llGetListLength(scores); j++)
- {
- sortedLeaderboard += [llList2String(home, j), llList2Integer(scores, j)];
- }
- sortedLeaderboard = llListSort(sortedLeaderboard, 2, FALSE);
- // Build and display the leaderboard
- string leaderboard = "Leaderboard:\n";
- integer f
- for (f = 0; f < llGetListLength(sortedLeaderboard); f += 2)
- {
- leaderboard += llList2String(sortedLeaderboard, f) + ": " + (string)llList2Integer(sortedLeaderboard, f + 1) + "\n";
- }
- llSetText(leaderboard, <1, 1, 1>, 1.0); // Display leaderboard as floating text on the prim
- }
- // Adds a new home to the linkset data if it doesn't already exist
- addHome(string home)
- {
- string dataKey = "score_" + home;
- if (llGetLinksetDataCount(dataKey) == 0) // If the home doesn't already have a score
- {
- llSetLinksetData(dataKey, "0"); // Initialize the score to 0
- }
- }
- // Adds points to an existing home or creates a new home if it doesn't exist
- addPoints(string home, integer points)
- {
- string dataKey = "score_" + home;
- if (llGetLinksetDataCount(dataKey) > 0)
- {
- integer currentScore = (integer)llGetLinksetData(dataKey);
- llSetLinksetData(dataKey, (string)(currentScore + points));
- }
- else
- {
- llOwnerSay("Home not found. Add it first with '/5 addhome " + home + "'.");
- }
- }
- default
- {
- state_entry()
- {
- UpdateLeaderboard(); // Display the initial leaderboard
- }
- listen(integer channel, string name, key id, string message)
- {
- // Check if the sender is the owner or an authorized avatar
- if (llGetOwner() == id || llListFindList(authAvi, [id]) != -1)
- {
- list tokens = llParseString2List(message, [" "], []);
- if (llGetListLength(tokens) >= 2)
- {
- string command = llToLower(llList2String(tokens, 0));
- string home = llList2String(tokens, 1);
- if (command == "addhome")
- {
- addHome(home);
- UpdateLeaderboard();
- }
- else if (command == "addpoints" && llGetListLength(tokens) == 3)
- {
- integer points = (integer)llList2String(tokens, 2);
- addPoints(home, points);
- UpdateLeaderboard();
- }
- else
- {
- llOwnerSay("Invalid command format. Use 'addhome Home' to add a home or 'addpoints Home Points' to add points.");
- }
- }
- }
- else
- {
- llOwnerSay("You are not authorized to perform this action.");
- }
- }
- // Start listening for commands from the owner or authorized avatars
- touch_start(integer num_detected)
- {
- if (llDetectedKey(0) == llGetOwner())
- {
- llListen(5, "", llGetOwner(), "");
- llListen(5, "", "", "");
- llSay(0, "Listening for commands on channel 5. Use 'addhome Home' to add a home, 'addpoints Home Points' to award points.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment