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 words = [];
- list scores = [];
- integer numEntries = llGetLinksetDataCountkey();
- // Collect words and their scores from linkset data
- for (integer 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 words by score in descending order
- list sortedLeaderboard = [];
- for (integer i = 0; i < llGetListLength(scores); i++)
- {
- sortedLeaderboard += [llList2String(words, i), llList2Integer(scores, i)];
- }
- sortedLeaderboard = llListSort(sortedLeaderboard, 2, FALSE);
- // Build and display the leaderboard
- string leaderboard = "Leaderboard:\n";
- for (integer i = 0; i < llGetListLength(sortedLeaderboard); i += 2)
- {
- leaderboard += llList2String(sortedLeaderboard, i) + ": " + (string)llList2Integer(sortedLeaderboard, i + 1) + "\n";
- }
- llSetText(leaderboard, <1, 1, 1>, 1.0); // Display leaderboard as floating text on the prim
- }
- // Adds a new word to the linkset data if it doesn't already exist
- addHome(string home)
- {
- string dataKey = "score_" + word;
- 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 word or creates a new word if it doesn't exist
- addPoints(string home, integer points)
- {
- string dataKey = "score_" + word;
- 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 word = llList2String(tokens, 1);
- if (command == "addhome")
- {
- addHome(word);
- UpdateLeaderboard();
- }
- else if (command == "addpoints" && llGetListLength(tokens) == 3)
- {
- integer points = (integer)llList2String(tokens, 2);
- addPoints(word, points);
- UpdateLeaderboard();
- }
- else
- {
- llOwnerSay("Invalid command format. Use 'addhome Home' to add a word 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 word, 'addpoints Home Points' to award points.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment