Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Access List Based on Notecard Example
- Notecard should be formatted with a name on each line.
- Lines starting with # are ignored.
- Example of what a notecard should look like:
- #List names below
- Bugs Larnia
- Ema Nymton
- Fig Ment
- Ima Genation
- */
- list glAccessList;
- string sNotecard;
- integer giCurrLineNo;
- key gkRequest;
- default
- {
- state_entry()
- {
- glAccessList = []; //Clear the list
- giCurrLineNo = 0; //Set the current line to read to 0
- //Check to see if a notecard is in inventory
- integer iNotecardCount = llGetInventoryNumber(INVENTORY_NOTECARD);
- if (iNotecardCount == 0)
- {
- llOwnerSay("Missing configuration notecard."); //No notecard; alert owner
- return; //Exit the state_entry event
- }
- //We now know we have a notecard, so let's get its name so we can read it
- sNotecard = llGetInventoryName(INVENTORY_NOTECARD, 0);
- //We have the name, now we send the request to read the first line (which has index 0)
- //This is an asynchronous event; the script sends the request to the server, but doesn't wait for the reply.
- gkRequest = llGetNotecardLine(sNotecard, giCurrLineNo);
- }
- //The dataserver is the listener for the asynchronous request; it listens to a reponse from a server.
- //When it receives one, the code in the event automatically fires, even if the script it doing something else at the time.
- dataserver(key pkRequest, string psResponse)
- {
- if (pkRequest != gkRequest) //Check if the answer matches the question we asked
- {
- return; //It does not, so exit the event
- }
- //We have the answer to our question, now we parse it.
- //First thing we go is check if the notecard is at its end. EOF (End Of File) is a constant that denotes that
- if (psResponse == EOF)
- {
- state ready; //Go to the "ready" state (see below)
- }
- //We are not yet at the end (or we'd be in state "ready"), so we read the line
- //First, we check if the line is not empty
- //BUT: we also check if the line starts with the # sign (often used for comments)
- //If it's empty or starts with #, then we skip it
- if ((llStringLength(psResponse) > 0) && (llGetSubString(psResponse, 0, 0) != "#"))
- {
- glAccessList += psResponse; //Add the response to the list
- }
- ++giCurrLineNo; //Increment the line number (++giCurrLineNo is the same as giCurrLineNo += 1)
- gkRequest = llGetNotecardLine(sNotecard, giCurrLineNo);
- }
- on_rez(integer piParam)
- {
- llResetScript();
- }
- }
- state ready
- {
- state_entry()
- {
- llOwnerSay("Configuration ready.");
- }
- touch_start(integer piNum)
- {
- key kId = llDetectedKey(0);
- string sName = llKey2Name(kId);
- if (~llListFindList(glAccessList, [sName])) //Difficult statement, but basically this means: if sName is on the list
- {
- llRegionSayTo(kId, 0, "You're on the list!!!");
- }
- else //else (so if it's not on the list)
- {
- llRegionSayTo(kId, 0, "You're not on the list :(");
- }
- }
- on_rez(integer piParam)
- {
- llResetScript();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement