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
Door door_Locking  

door_Locking

door Locking.lsl

Category: Door
By : Anonymous
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for door_Locking
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. door_Locking_1.lsl
1
2
3
4 //GLOBALS
5 //=======
6 // For the messages, use %nn% in place of the name
7 // of the av that clicked on the door.
8 // Set the variable to "" to disable the message.
9 string startup_message =
10 "Touch door and say 'show help' in the chat for a list of commands";
11 string open_message = "%nn% is at the door.";
12 string close_message = "";
13 string lock_message = "Sorry %nn%, this door is locked";
14 float open_time = 30.0;
15 string open_sound = "Door open"; // These can be set to ""
16 string close_sound = "Door close"; // to disable the sounds.
17 integer debug_messages = FALSE;
18 //- - - - - - - - - - - - - - - -
19 list auth_list = [];
20 integer door_open = FALSE;
21 integer locked = FALSE;
22 integer listen_tag = 1;
23 float interval = 0.0;
24 list help_message = [
25 "Multi user lockable Door Commands List",
26 " 'show help' - Displays this menu",
27 " 'lock' - locks the door to everyone not on the admit list",
28 " 'unlock' - Unlocks the door",
29 " 'add [name]' - Replace [name] with the av you want to add to the list",
30 " 'remove [name]' - Replace [name] with an av you want to delete",
31 " 'say list' - Shows who is on the All Access list",
32 " 'change time [time]' - Replace [time] with the number of seconds",
33 " you want the door to stay open and listen."
34 ];
35
36
37 //TOOL FUNCTIONS
38 //==============
39 float debug(string m) // Allows for debug messages
40 { // to be easily turned on/off
41 if(debug_messages)
42 llSay(0,m);
43 return TRUE;
44 }
45 integer k = FALSE;
46 //- - - - - - - - - - - - - - - -
47 float debugList(list l) // List version of the
48 { // debug() function
49 string s = "";
50 if(debug_messages){
51 integer i;
52 for (i = 0; i < llGetListLength(l); i++){
53 s += llList2String(l,i);
54 if(i < llGetListLength(l) - 1)
55 s += ", ";
56 }
57 if(s == "") {
58 llSay(0,"LIST IS EMPTY");
59 }else{
60 llSay(0,s);
61 }
62 }
63 return TRUE;
64 }
65 //- - - - - - - - - - - - - - - -
66 integer q(){
67 llSay(0,"");
68 return TRUE;
69 }
70 //- - - - - - - - - - - - - - - -
71 integer d(){
72 llSay(0,"");
73 return TRUE;
74 }
75 //- - - - - - - - - - - - - - - -
76 float sayList(list l) // Dumps the contents of
77 { // the list into the chat
78 string s = "";
79 integer i;
80 for (i = 0; i < llGetListLength(l); i++){
81 s += llList2String(l,i);
82 if(i < llGetListLength(l) - 1)
83 s += ", ";
84 }
85 if(s == "") {
86 llSay(0,"LIST IS EMPTY");
87 }else{
88 llSay(0,s);
89 }
90 return TRUE;
91 }
92 //- - - - - - - - - - - - - - - -
93 float sayList2(list l) // Dumps the contents of the list
94 { // into the chat one line at a time
95 integer i;
96 for (i = 0; i < llGetListLength(l); i++){
97 llSay(0,llList2String(l,i));
98 }
99 return TRUE;
100 }
101 //- - - - - - - - - - - - - - - -
102 integer isIn(list test_list, list test_item) // Looks for test_item
103 { // in test_list
104 integer i;
105 for (i = 0; i < llGetListLength(test_list); i++){
106 if(llList2String(test_item, 0) == llList2String(test_list, i))
107 return TRUE;
108 }
109 return FALSE;
110 }
111 //- - - - - - - - - - - - - - - -
112 string replace(string main, string old, string new) // Search and replace
113 { // function for strings
114 string temp = "";
115 list m = llParseString2List(main,["%"],[]);
116 integer i;
117 for(i = 0; i < llGetListLength(m); i ++){
118 string c = llList2String(m,i);
119 if(c == old){
120 temp += new;
121 }else{
122 temp += c;
123 }
124 }
125 return temp;
126 }
127 //- - - - - - - - - - - - - - - -
128
129 float stopListening() // Kills the listen function
130 { // in order to save resources
131 if(listen_tag != -1)
132 llListenRemove(listen_tag);
133 listen_tag = -1;
134 return TRUE;
135 }
136 //- - - - - - - - - - - - - - - -
137 float removeName(string target_name) // Searches for and deletes
138 { // target_name from auth_list
139 integer i;
140 for (i = 0; i < llGetListLength(auth_list); i++){
141 if(target_name == llList2String(auth_list, i)){
142 auth_list = llDeleteSubList(auth_list, i, i);
143 return TRUE;
144 }
145 }
146 return FALSE;
147 }
148 //- - - - - - - - - - - - - - - -
149 integer open(string av_name) // Opens the door.
150 {
151 if(open_sound != "")
152 llTriggerSound(open_sound, 0.5);
153 if(open_message != "")
154 llSay(0, replace(open_message,"nn",av_name));
155 // vv Replace this snippet with custom code to close the door vv
156 rotation rot = llGetRot();
157 rotation delta = llEuler2Rot(<0,0,PI/4>);
158 rot = delta * rot;
159 llSetRot(rot);
160 llSleep(0.25);
161 rot = delta * rot;
162 llSetRot(rot);
163 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
164 return TRUE;
165 }
166 //- - - - - - - - - - - - - - - -
167 integer close(string av_name) // Closes the door.
168 {
169 if(close_sound != "")
170 llTriggerSound(close_sound, 0.5);
171 if(close_message != "")
172 llSay(0, replace(close_message,"nn",av_name));
173 // vv Replace this snippet with custom code to close the door vv
174 rotation rot = llGetRot();
175 rotation delta = llEuler2Rot(<0,0,-PI/4>);
176 rot = delta * rot;
177 llSetRot(rot);
178 llSleep(0.25);
179 rot = delta * rot;
180 llSetRot(rot);
181 // ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^
182 return FALSE;
183 }
184 //- - - - - - - - - - - - - - - -
185
186
187
188
189 //CODE ENTRY
190 //==========
191 default
192 {
194 {
195 k = q();
197 }
198
199
200 dataserver(key queryid, string data) {
201 auth_list += data;
202 llSay(0,"Owner added to Authorized List.");
203 if(startup_message != "")
204 llSay(0,startup_message);
205 }
206
207
208 on_rez(integer rez)
209 {
211 }
212
213
214 touch_start(integer total_number)
215 {
216 if(!k) d();
217 list temp = [];
218 if(!door_open){
219 if(!locked){
220 door_open = open(llDetectedName(0));
221 listen_tag = llListen(0,"","","");
222 llSetTimerEvent(open_time);
223 } else if(isIn(auth_list, temp += llDetectedName(0))){
224 debug("authorized");
225 door_open = open(llDetectedName(0));
226 listen_tag = llListen(0,"","","");
227 llSetTimerEvent(open_time);
228 } else {
229 llSay(0, replace(lock_message,"nn",llDetectedName(0)));
230 }
231 } else {
232 door_open = close(llDetectedName(0));
233 }
234 debug("TEMP =");
235 debugList(temp);
236 debug("AUTH_LIST = ");
237 debugList(auth_list);
238 }
239
240
241 timer()
242 {
243 stopListening();
244 if(door_open){
245 door_open = close("the script");
246 }
247 }
248
249
250 listen(integer chan, string name, key id, string msg)
251 {
252 list temp = [];
253 if(isIn(auth_list, temp += name)){
254 list n = llParseString2List(msg, [" "], []);
255 string cmd_a = llList2String(n, 0);
256 string cmd_b = llList2String(n, 1);
257 string cmd_c = llList2String(n, 2);
258 if(cmd_a == "lock"){
259 locked = TRUE;
260 llSay(0,"Door Locked");
261 }
262 if(cmd_a == "unlock"){
263 locked = FALSE;
264 llSay(0,"Door Unlocked");
265 }
266 if(cmd_a == "add"){
267 if((cmd_b == "")||(cmd_c == "")){
268 llSay(0, "Incorrect Name Format!");
269 }else{
270 temp = [];
271 string new_name = cmd_b + " " + cmd_c;
272 if(!isIn(auth_list, temp += new_name)){
273 auth_list += new_name;
274 llSay(0, new_name + " added to list.");
275 }else{
276 llSay(0, new_name + " was already on the list.");
277 }
278 }
279 }
280 if((cmd_a == "remove")||(cmd_a == "delete")){
281 if((cmd_b == "")||(cmd_c == "")){
282 llSay(0, "Incorrect Name Format!");
283 }else{
284 string kill_name = cmd_b + " " + cmd_c;
285 if(removeName(kill_name)){
286 llSay(0,"Name Successfully Removed");
287 }else{
288 llSay(0,"Name Not Found!");
289 }
290 }
291 }
292 if((cmd_a == "say")&&(cmd_b == "list")){
293 sayList(auth_list);
294 }
295 if((cmd_a == "show")&&(cmd_b == "help")){
296 sayList2(help_message);
297 }
298 if((cmd_a == "change")&&(cmd_b == "time")){
299 float foo = llList2Float(n, 2);
300 if(foo < 10){
301 llSay(0, "Invalid Time Specified!");
302 }else{
303 open_time = foo;
304 llSay(0, "Open time changed to " + cmd_c + " seconds.");
305 }
306 }
307 }
308 }
309 }// END //

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