Join us in Outworldz at www.outworldz.com:9000 or follow us:

Search dozens of selected web sites for OpenSim and LSL script

New! Script Meta-Search will search thousands of scripts here and at other sites for LSL or Opensim scripts.
Loading

Want to add a script or a project? Upload it and a half million people will see it and your name here this year.

Home   Show All
Category: Contributor: Creator
Sensor 1st_necessity_of_SL  

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 :)

[Beer Dailey]

Category: Sensor
By : Beer Dailey
Created: 2011-01-22 Edited: 2014-02-15
Worlds: Second Life

the Zip file

Download all files for 1st_necessity_of_SL
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. 1st_necessity_of_SL_1.lsl
1 // Improve SecondLife's performance!
2 // Start with your own(ned) modifyable scripts/objects.
3 //
4 // This will disable your rootprim's script(s) when no-one is around to use/admire it
5 // thus stop wasting valuable sim-resources
6 //
7 // Measured script time is 0.002 ms on average.
8 //
9 // - don't use it for rental stuff or sorts, not everything is suitable -
10 //
11 // Free to use, please use it. Improvements are welcome.
12 // // Thank you Norton Burns for the testing and feedback :)
13 //
14 // Beer Dailey
15 //
16 // Don't reset this script or take it back in inventory when you're not within the set distance
17 // or you'll get unpredictable results !!
18 //
19 // modify below to suit your needs
20
21 //////////////////////////////////
22 float distance = 48.0; // scan range
23 integer delay = 10; // repeat scan every 10 seconds.
24
25 // added
26 // (gnore specific scripts, some scripts need to be off after initial setups
27 // There's a bug that resets scripts in off state after a sim restart, so when activated again they re-initialise.
28 // I've no fix for that.
29 //
30 list ignore_scripts = ["major script", "even worse script"];
31
32 integer debug = FALSE; // for debugging purposes, set it to TRUE to see what it's controlling
33
34
35 //////////////////////////////////////
36 // no need to modify the code below //
37 //////////////////////////////////////
38
39 integer g_active = FALSE; // if FALSE disable all other scripts
40 // changed TRUE into FALSE cos of some bug with rezzing, thank you LordGregGreg Back :)
41 list control_scripts; // list for all scriptnames
42
43 active_scripts( integer active )
44 {
45 if(g_active == active) return; else g_active = active; //flip TRUE/FALSE
46
47 integer a;
48 for ( a = 0; a < llGetListLength(control_scripts); a++)
49 {
50 llSetScriptState(llList2String(control_scripts, a), g_active); //(de)activate scripts
51
52 }
53 if(debug) llOwnerSay("Changed: " + llList2CSV(control_scripts) + " to: " + (string)g_active );
54 }
55
56 default
57 {
59 {
60 string myname = llGetScriptName(); //don't add myself into the list
61 control_scripts = [];
62
63 integer i;
65
66 if(n == 1) { llOwnerSay("No other scripts found!"); } else //dont be silly ;)
67
68 for(i = 0; i < n; ++i)
69 {
70 string name = llGetInventoryName(INVENTORY_SCRIPT, i); //parse scriptnames
71 if(name != myname) //not my name then continue
72 {
73 //catch states
74 if( llGetScriptState(name) == TRUE) //not on ignore list & running add it
75 {
76 control_scripts += [name];
77 }
78 else ignore_scripts += [name];
79 }
80 }
81 if(debug) llOwnerSay("Controlling: " + llList2CSV(control_scripts) + "\nIgnoring: " + llList2CSV(ignore_scripts));
82 llSensorRepeat("", NULL_KEY, AGENT, distance, PI, delay); // how far and how often we scan for avatars
83 }
84
85 on_rez(integer s)
86 {
87 if(llGetListLength(control_scripts)== 0 && g_active == TRUE) llResetScript();
88 //first time use or reset only when scripts are still active or they'll be added to the ignorelist
89 }
90
91 changed(integer change)
92 {
93 if(change & CHANGED_OWNER) llResetScript(); // catch new owner
94 if(change & CHANGED_INVENTORY) llResetScript(); // catch new scripts
95 }
96
97 sensor(integer num_detected)
98 {
99 active_scripts(TRUE); //activate the scripts
100 }
101
102 no_sensor() //no-one around? turn off all controlled scripts except myself
103 {
104 active_scripts(FALSE); //deactivate the scripts
105 }
106
107 }
108

Back to the Best Free Tools in Second Life and OpenSim.