Difference between revisions of "1st necessity of SL"

From Second Life Wiki
Jump to navigation Jump to search
m
m
Line 19: Line 19:
//
//
// Free to use, please use it. Improvements are welcome.
// Free to use, please use it. Improvements are welcome.
// // Thank you Norton Burns for the testing and feedback :)
//
//
// Beer Dailey
// Beer Dailey
//
// Don't reset this script or take it back in inventory when you're not within the set distance
// or you'll get unpredictable results !!
//
// modify below to suit your needs


// modify below to suit your needs
//////////////////////////////////
//////////////////////////////////
float  distance = 20; // scan range  
float  distance = 5;   // scan range  
integer delay = 2;      // repeat scan every 2 seconds.
integer delay = 5;      // repeat scan every 2 seconds.
list ignore_these = ["major script", "even worse script"];
//ignore specific scripts, some scripts need to be off after initial setups, thank you Norton Burns for the testing and feedback :)


// added
// ignore specific scripts, some scripts need to be off after initial setups
list ignore_scripts = ["major script", "even worse script"];
integer debug = FALSE;  // for debugging purposes, set it to TRUE to see what it's controlling
//////////////////////////////////////
// no need to modify the code below //
//////////////////////////////////////


// no need to modify the code below
///////////////////////////////////
integer g_active = FALSE;  // if FALSE disable all other scripts   
integer g_active = FALSE;  // if FALSE disable all other scripts   
                           // changed TRUE into FALSE cos of some bug with rezzing, thank you LordGregGreg Back :)
                           // changed TRUE into FALSE cos of some bug with rezzing, thank you LordGregGreg Back :)
list all_scripts;         // list for all scriptnames
list control_scripts;     // list for all scriptnames
 
active_scripts( integer active )
active_scripts( integer active )
{
{
     if(g_active == active) return;
     if(g_active == active) return; else g_active = active; //flip TRUE/FALSE
   
    g_active = active; //flip TRUE/FALSE
   
     integer a;
     integer a;
     for ( a = 0; a < llGetListLength(all_scripts); a++)
     for ( a = 0; a < llGetListLength(control_scripts); a++)
     {
     {
        llSetScriptState(llList2String(all_scripts, a),active); //(de)activate scripts  
        llSetScriptState(llList2String(control_scripts, a), g_active); //(de)activate scripts  
        if (debug) llOwnerSay("Changed: " + llList2CSV(control_scripts) + " to: " + (string)g_active );
     }     
     }     
}
}
 
default
default
{
{
     state_entry()
     state_entry()
     {
     {
         string myname = llGetScriptName(); //don't add myself into the list
         string myname = llGetScriptName(); //don't add myself into the list  
     
         control_scripts = [];   
         all_scripts = [];   
       
         integer i;
         integer i;
         integer n = llGetInventoryNumber(INVENTORY_SCRIPT); //count scripts
         integer n = llGetInventoryNumber(INVENTORY_SCRIPT); //count scripts
       
        if (n == 1) { llOwnerSay("No other scripts found!"); } else //dont be silly ;)
       
         for(i = 0; i < n; ++i)
         for(i = 0; i < n; ++i)
         {
         {
             string name = llGetInventoryName(INVENTORY_SCRIPT, i); //get all scriptnames
             string name = llGetInventoryName(INVENTORY_SCRIPT, i); //parse scriptnames  
             if(name != myname) //not my name then continue
             if(name != myname) //not my name then continue
             {
             {
               if (llListFindList(ignore_these, [name]) == -1) //not on ignore list? add it
               //if (llListFindList(ignore_these, [name]) == -1) &&
              if ( llGetScriptState(name) == TRUE) //not on ignore list & running add it
               {
               {
                   all_scripts += [name];   
                   control_scripts += [name];   
               }
               }
              else ignore_scripts += [name];
             }
             }
         }
         }
 
         if (debug) llOwnerSay("Controlling: " + llList2CSV(control_scripts) + "\nIgnoring: " + llList2CSV(ignore_scripts));
         //llSetTimerEvent(delay);  
         llSensorRepeat("", NULL_KEY, AGENT, distance, PI, delay); // how far and how often we scan for avatars
         llSensorRepeat("", NULL_KEY, AGENT, distance, PI, delay); // how far and how often we scan for avatars
     }
     }
   
     on_rez(integer s)  
     on_rez(integer s)  
     {  
     {  
         llResetScript(); //first time use
         if (llGetListLength(control_scripts)== 0 && g_active == TRUE) llResetScript();  
        //first time use or reset only when scripts are still active or they'll be added to the ignorelist
     }  
     }  
   
     changed(integer change)
     changed(integer change)
     {
     {
         if (change == CHANGED_INVENTORY) llResetScript(); // catch new scripts
         if (change & CHANGED_OWNER) llResetScript(); // catch new owner
        if (change & CHANGED_INVENTORY) llResetScript(); // catch new scripts
     }
     }
   
     sensor(integer num_detected)
     sensor(integer num_detected)
     {
     {
       active_scripts(TRUE); //activate the scripts
       active_scripts(TRUE); //activate the scripts
     }
     }
   
     no_sensor()  //no-one around? turn off all scripts except myself
     no_sensor()  //no-one around? turn off all controlled scripts except myself
     {
     {
       active_scripts(FALSE); //deactivate the scripts
       active_scripts(FALSE); //deactivate the scripts
     }
     }
   
}
}
</lsl>
</lsl>

Revision as of 01:20, 13 March 2010

Ever since I noticed that many sims contain 1000's of wonderful objects with fancy effects and 1000's active scripts that use valuable simresources while no-one is around to enjoy it, I wanted to script something simple to offload those resources and give the visitor a better experience.

That's why I made this little script: '1st necessity of SL' that could and should be used in any project that doesn't need to be active all the time.

We are building a better place, together :)

[Beer Dailey]

<lsl> // Improve SecondLife's performance! // Start with your own(ned) modifyable scripts/objects. // // This will disable your rootprim's script(s) when no-one is around to use/admire it // thus stop wasting valuable sim-resources // // Measured script time is 0.002 ms on average. // // - don't use it for rental stuff or sorts, not everything is suitable - // // Free to use, please use it. Improvements are welcome. // // Thank you Norton Burns for the testing and feedback :) // // Beer Dailey // // Don't reset this script or take it back in inventory when you're not within the set distance // or you'll get unpredictable results !! // // modify below to suit your needs

////////////////////////////////// float distance = 5; // scan range integer delay = 5; // repeat scan every 2 seconds.

// added // ignore specific scripts, some scripts need to be off after initial setups list ignore_scripts = ["major script", "even worse script"];

integer debug = FALSE; // for debugging purposes, set it to TRUE to see what it's controlling


////////////////////////////////////// // no need to modify the code below // //////////////////////////////////////

integer g_active = FALSE; // if FALSE disable all other scripts

                          // changed TRUE into FALSE cos of some bug with rezzing, thank you LordGregGreg Back :)

list control_scripts; // list for all scriptnames

active_scripts( integer active ) {

   if(g_active == active) return; else g_active = active;  //flip TRUE/FALSE

   integer a;
   for ( a = 0; a < llGetListLength(control_scripts); a++)
   {
       llSetScriptState(llList2String(control_scripts, a), g_active); //(de)activate scripts 
       if (debug) llOwnerSay("Changed: " + llList2CSV(control_scripts) + " to: " + (string)g_active );
   }    

}

default {

   state_entry()
   {
       string myname = llGetScriptName(); //don't add myself into the list 
       control_scripts = [];  
       
       integer i;
       integer n = llGetInventoryNumber(INVENTORY_SCRIPT); //count scripts
       
       if (n == 1) { llOwnerSay("No other scripts found!"); } else //dont be silly ;)
       
       for(i = 0; i < n; ++i)
       {
           string name = llGetInventoryName(INVENTORY_SCRIPT, i); //parse scriptnames 
           if(name != myname) //not my name then continue
           {
              //if (llListFindList(ignore_these, [name]) == -1) && 
              if ( llGetScriptState(name) == TRUE) //not on ignore list & running add it
              {
                  control_scripts += [name];  
              }
              else ignore_scripts += [name];
           }
       }
       if (debug) llOwnerSay("Controlling: " + llList2CSV(control_scripts) + "\nIgnoring: " + llList2CSV(ignore_scripts));
       llSensorRepeat("", NULL_KEY, AGENT, distance, PI, delay); // how far and how often we scan for avatars
   }

   on_rez(integer s) 
   { 
       if (llGetListLength(control_scripts)== 0 && g_active == TRUE) llResetScript(); 
       //first time use or reset only when scripts are still active or they'll be added to the ignorelist
   } 

   changed(integer change)
   {
       if (change & CHANGED_OWNER) llResetScript(); // catch new owner
       if (change & CHANGED_INVENTORY) llResetScript(); // catch new scripts
   }

   sensor(integer num_detected)
   {
      active_scripts(TRUE); //activate the scripts
   }

   no_sensor()  //no-one around? turn off all controlled scripts except myself
   {
      active_scripts(FALSE); //deactivate the scripts
   }

}

</lsl>