Advertisement
Bugs_Larnia

LSL: Access List Based on Notecard Example

Jan 13th, 2021 (edited)
939
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* Access List Based on Notecard Example
  2. Notecard should be formatted with a name on each line.
  3. Lines starting with # are ignored.
  4.  
  5. Example of what a notecard should look like:
  6.  
  7. #List names below
  8. Bugs Larnia
  9. Ema Nymton
  10. Fig Ment
  11. Ima Genation
  12. */
  13.  
  14. list glAccessList;
  15. string sNotecard;
  16. integer giCurrLineNo;
  17. key gkRequest;
  18.  
  19.  
  20. default
  21. {
  22.     state_entry()
  23.     {
  24.         glAccessList = []; //Clear the list
  25.         giCurrLineNo = 0; //Set the current line to read to 0
  26.        
  27.         //Check to see if a notecard is in inventory
  28.         integer iNotecardCount = llGetInventoryNumber(INVENTORY_NOTECARD);
  29.         if (iNotecardCount == 0)
  30.         {
  31.             llOwnerSay("Missing configuration notecard."); //No notecard; alert owner
  32.             return; //Exit the state_entry event
  33.         }
  34.        
  35.         //We now know we have a notecard, so let's get its name so we can read it
  36.         sNotecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
  37.        
  38.         //We have the name, now we send the request to read the first line (which has index 0)
  39.         //This is an asynchronous event; the script sends the request to the server, but doesn't wait for the reply.
  40.         gkRequest = llGetNotecardLine(sNotecard, giCurrLineNo);
  41.     }
  42.    
  43.     //The dataserver is the listener for the asynchronous request; it listens to a reponse from a server.
  44.     //When it receives one, the code in the event automatically fires, even if the script it doing something else at the time.
  45.     dataserver(key pkRequest, string psResponse)
  46.     {
  47.         if (pkRequest != gkRequest) //Check if the answer matches the question we asked
  48.         {
  49.             return; //It does not, so exit the event
  50.         }
  51.        
  52.         //We have the answer to our question, now we parse it.
  53.         //First thing we go is check if the notecard is at its end. EOF (End Of File) is a constant that denotes that
  54.         if (psResponse == EOF)
  55.         {
  56.             state ready; //Go to the "ready" state (see below)
  57.         }
  58.        
  59.         //We are not yet at the end (or we'd be in state "ready"), so we read the line
  60.        
  61.         //First, we check if the line is not empty
  62.         //BUT: we also check if the line starts with the # sign (often used for comments)
  63.         //If it's empty or starts with #, then we skip it
  64.         if ((llStringLength(psResponse) > 0) && (llGetSubString(psResponse, 0, 0) != "#"))
  65.         {
  66.             glAccessList += psResponse; //Add the response to the list
  67.         }
  68.         ++giCurrLineNo; //Increment the line number (++giCurrLineNo is the same as giCurrLineNo += 1)
  69.         gkRequest = llGetNotecardLine(sNotecard, giCurrLineNo);
  70.     }
  71.    
  72.     on_rez(integer piParam)
  73.     {
  74.         llResetScript();
  75.     }
  76. }
  77.  
  78. state ready
  79. {
  80.     state_entry()
  81.     {
  82.         llOwnerSay("Configuration ready.");
  83.     }
  84.    
  85.     touch_start(integer piNum)
  86.     {
  87.         key kId = llDetectedKey(0);
  88.         string sName = llKey2Name(kId);
  89.         if (~llListFindList(glAccessList, [sName])) //Difficult statement, but basically this means: if sName is on the list
  90.         {
  91.             llRegionSayTo(kId, 0, "You're on the list!!!");
  92.         }
  93.         else //else (so if it's not on the list)
  94.         {
  95.             llRegionSayTo(kId, 0, "You're not on the list :(");
  96.         }
  97.     }
  98.    
  99.     on_rez(integer piParam)
  100.     {
  101.         llResetScript();
  102.     }
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement