1st necessity of SL
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 :)
<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. // // Beer Dailey
// modify below to suit your needs ////////////////////////////////// float distance = 20; // scan range integer delay = 2; // repeat scan every 2 seconds.
// no need to modify the code below /////////////////////////////////// integer g_active = TRUE; // if FALSE disable all other scripts list all_scripts; // list for all scriptnames
active_scripts( integer active ) {
if(g_active == active) return; g_active = active; //flip TRUE/FALSE integer a; for ( a = 0; a < llGetListLength(all_scripts); a++) { llSetScriptState(llList2String(all_scripts, a),active); //(de)activate scripts }
}
default {
state_entry() { string myname = llGetScriptName(); //don't add myself into the list all_scripts = []; integer i; integer n = llGetInventoryNumber(INVENTORY_SCRIPT); //count scripts for(i = 0; i < n; ++i) { string name = llGetInventoryName(INVENTORY_SCRIPT, i); //get all scriptnames if(name != myname) all_scripts += [name]; //not my name? add it }
//llSetTimerEvent(delay); llSensorRepeat("", NULL_KEY, AGENT, distance, PI, delay); // how far and how often we scan for avatars } on_rez(integer s) { llResetScript(); //first time use } changed(integer change) { 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 scripts except myself { active_scripts(FALSE); //deactivate the scripts }
} </lsl>