User:Trinity Coulter/Inventory Giver, Access List

From Second Life Wiki
< User:Trinity Coulter
Revision as of 10:50, 7 November 2009 by Trinity Coulter (talk | contribs) (Created page with 'This is a little script to give all items in inventory via a folder, when someone touches the object, the folder is named after the object. It uses a notecard that you make, to ...')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This is a little script to give all items in inventory via a folder, when someone touches the object, the folder is named after the object. It uses a notecard that you make, to provide security, so that only people listed in the notecard can access it. The default name of the notecard is 'access'.

<lsl> integer NOT_FOUND = -1; string config_notecard_name = "access"; integer config_line_current = 0; key config_data_request;

list AccessList = [];

list gInventoryList;

list getInventoryList() {

   list       result = [];
   integer    n = llGetInventoryNumber(INVENTORY_ALL);

   while(n)
   {
       string current_name = llGetInventoryName(INVENTORY_ALL, --n);
       // exclude access notecard and current script from inventory list
       if ( current_name != config_notecard_name && current_name != llGetScriptName())
       {
           result = current_name + result;
       }
   }

   return result;

}


default {

   state_entry()
   {
       llSay(0, "Checking for Access Notecard.... must be named \'" + config_notecard_name +"\'.");
       if ( llGetInventoryType(config_notecard_name) != NOT_FOUND )
       {
           //config notecard found... process it
           llSay(0, "Reading access notecard...");
           AccessList = [];
           config_line_current = 0;
           config_data_request = llGetNotecardLine(config_notecard_name,config_line_current);
       }
       else
       {
           llSay(0, "Access notecard not found, must be named \'" + config_notecard_name +"\'.");
       }
           
           
   }
   
   on_rez(integer start_param)
   {
       llResetScript();
   }
   
   changed(integer change)
   {
       if (change & CHANGED_INVENTORY)
       {
           llSay(0, "Checking for Access Notecard.... must be named \'" + config_notecard_name +"\'.");
           if ( llGetInventoryType(config_notecard_name) != NOT_FOUND )
           {
               //config notecard found... process it
               llSay(0, "Reading access notecard...");
               AccessList = [];
               config_line_current = 0;
               config_data_request = llGetNotecardLine(config_notecard_name,config_line_current);
           }
           else
           {
               llSay(0, "Access notecard not found, must be named \'" + config_notecard_name +"\'.");
           }
       }
   }
   touch_start(integer total_number)
   {
       integer x;
       for (x = 0; x < total_number; x++)
       {
       
           if( llListFindList(AccessList, [llDetectedName(x)]) != NOT_FOUND )
           {
               gInventoryList = getInventoryList();
               if (gInventoryList == [])
               {
                   llSay(0,"Nothing to give.");
               }
               else
               {
                   integer i = 0;
                   string folder = llGetObjectName();
                   llGiveInventoryList(llDetectedKey(x), folder, gInventoryList );
                   llSay(0, "You will find your items in a folder named \'" + folder + "\'.");
               }
           }
       
       }
   }
   
   dataserver(key queryid, string data)
   {
       if (config_data_request == queryid && data != EOF)
       {
           AccessList = AccessList + [data];
           config_line_current++;
           config_data_request = llGetNotecardLine(config_notecard_name,config_line_current);
       }
       else
       {
           llSay(0,"Access notecard read.");
       }
   }

}

</lsl>