ShyStorm

Untitled

Sep 7th, 2024
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Configuration - List of authorised Avi's to add homes and points
  2. list authAvi = ["UUID1", "UUID2"];
  3.  
  4. // Updates and displays the leaderboard on the prim
  5. UpdateLeaderboard()
  6. {
  7.     list homess = [];
  8.     list scores = [];
  9.     integer numEntries = llGetLinksetDataCountkey();
  10.  
  11.     // Collect homes and their scores from linkset data
  12.     integer i;
  13.     for (i = 0; i < numEntries; i++)
  14.     {
  15.         string dataKey = llGetLinksetDataKey(i);
  16.        
  17.         if (llSubStringIndex(dataKey, "score_") == 0)
  18.         {
  19.             string home = llDeleteSubString(dataKey, 0, 6); // Remove "score_" prefix
  20.             integer score = (integer)llGetLinksetData(dataKey);
  21.            
  22.             home += home;
  23.             scores += score;
  24.         }
  25.     }
  26.  
  27.     // Sort the homes by score in descending order
  28.     list sortedLeaderboard = [];
  29.     integer j;
  30.     for (j = 0; j < llGetListLength(scores); j++)
  31.     {
  32.         sortedLeaderboard += [llList2String(home, j), llList2Integer(scores, j)];
  33.     }
  34.     sortedLeaderboard = llListSort(sortedLeaderboard, 2, FALSE);
  35.  
  36.     // Build and display the leaderboard
  37.     string leaderboard = "Leaderboard:\n";
  38.     integer f
  39.     for (f = 0; f < llGetListLength(sortedLeaderboard); f += 2)
  40.     {
  41.         leaderboard += llList2String(sortedLeaderboard, f) + ": " + (string)llList2Integer(sortedLeaderboard, f + 1) + "\n";
  42.     }
  43.  
  44.     llSetText(leaderboard, <1, 1, 1>, 1.0);  // Display leaderboard as floating text on the prim
  45. }
  46.  
  47. // Adds a new home to the linkset data if it doesn't already exist
  48. addHome(string home)
  49. {
  50.     string dataKey = "score_" + home;
  51.     if (llGetLinksetDataCount(dataKey) == 0)  // If the home doesn't already have a score
  52.     {
  53.         llSetLinksetData(dataKey, "0");  // Initialize the score to 0
  54.     }
  55. }
  56.  
  57. // Adds points to an existing home or creates a new home if it doesn't exist
  58. addPoints(string home, integer points)
  59. {
  60.     string dataKey = "score_" + home;
  61.  
  62.     if (llGetLinksetDataCount(dataKey) > 0)
  63.     {
  64.         integer currentScore = (integer)llGetLinksetData(dataKey);
  65.         llSetLinksetData(dataKey, (string)(currentScore + points));
  66.     }
  67.     else
  68.     {
  69.         llOwnerSay("Home not found. Add it first with '/5 addhome " + home + "'.");
  70.     }
  71. }
  72.  
  73. default
  74. {
  75.     state_entry()
  76.     {
  77.         UpdateLeaderboard();  // Display the initial leaderboard
  78.     }
  79.  
  80.     listen(integer channel, string name, key id, string message)
  81.     {
  82.         // Check if the sender is the owner or an authorized avatar
  83.         if (llGetOwner() == id || llListFindList(authAvi, [id]) != -1)
  84.         {
  85.             list tokens = llParseString2List(message, [" "], []);
  86.             if (llGetListLength(tokens) >= 2)
  87.             {
  88.                 string command = llToLower(llList2String(tokens, 0));
  89.                 string home = llList2String(tokens, 1);
  90.  
  91.                 if (command == "addhome")
  92.                 {
  93.                     addHome(home);
  94.                     UpdateLeaderboard();
  95.                 }
  96.                 else if (command == "addpoints" && llGetListLength(tokens) == 3)
  97.                 {
  98.                     integer points = (integer)llList2String(tokens, 2);
  99.                     addPoints(home, points);
  100.                     UpdateLeaderboard();
  101.                 }
  102.                 else
  103.                 {
  104.                     llOwnerSay("Invalid command format. Use 'addhome Home' to add a home or 'addpoints Home Points' to add points.");
  105.                 }
  106.             }
  107.         }
  108.         else
  109.         {
  110.             llOwnerSay("You are not authorized to perform this action.");
  111.         }
  112.     }
  113.  
  114.     // Start listening for commands from the owner or authorized avatars
  115.     touch_start(integer num_detected)
  116.     {
  117.         if (llDetectedKey(0) == llGetOwner())
  118.         {
  119.             llListen(5, "", llGetOwner(), "");
  120.             llListen(5, "", "", "");
  121.             llSay(0, "Listening for commands on channel 5. Use 'addhome Home' to add a home, 'addpoints Home Points' to award points.");
  122.         }
  123.     }
  124. }
  125.  
Advertisement
Add Comment
Please, Sign In to add comment