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
Rental PrimaryRental  

PrimaryRental

PrimaryRental

Category: Rental
By : Encog Dod
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for PrimaryRental
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. PrimaryRental_1.lsl
1 // From the book:
2 //
3 // Scripting Recipes for Second Life
4 // by Jeff Heaton (Encog Dod in SL)
5 // ISBN: 160439000
6 X// Copyright 2007 by Heaton Research, Inc.
7 //
8 // This script may be freely copied and modified so long as this header
9 // remains unmodified.
10 //
11 // For more information about this book visit the following web site:
12 //
13 // http://www.heatonresearch.com/articles/series/22/
14
15 // constants
16 float TIMER_CLOSE = 5.0;
17 integer DOOR_OPEN = 1;
18 integer DOOR_CLOSE = 2;
19 integer DAYSEC = 86400;
20
21 // configuration
22 integer config_rentwarning = 3;
23 integer config_graceperiod = 3;
24 integer config_rate = 43;
25 integer config_min_days = 7;
26
27 // data about renter
28 string data_rented;
29 key data_rented_key;
30 integer data_leased_until;
31
32 // other variables
33 vector originalPos;
34 string text;
35 list allow;
36
37 integer warningSent = FALSE;
38 integer reminderSent = FALSE;
39
40
41 // simple function to open or close the door
42 // this works by rotating the door
43 door(integer what)
44 {
45 vector scale = llGetScale();
46
47
49
50 if( what == DOOR_OPEN )
51 {
52 llTriggerSound("doorOpen", 1);
53 scale.x = 1;
54 vector pos = llGetPos();
55 pos.x+=2.5;
56 llSetPos(pos);
57 } else if( what == DOOR_CLOSE)
58 {
59 llTriggerSound("doorClose", 1);
60 scale.x = 5;
61 }
62
63 llSetScale(scale);
64 }
65
66 integer validateUser(string who)
67 {
68 integer shouldOpen = FALSE;
69 if( who==llKey2Name(llGetOwner()) )
70 shouldOpen = TRUE;
71
72 if( data_rented==who )
73 shouldOpen = TRUE;
74
75 string name = llToUpper(who);
76 if( llListFindList(allow,[name]) != -1 )
77 shouldOpen = TRUE;
78
79 return shouldOpen;
80 }
81
82
83 string rentalInfo()
84 {
85
86 return llGetRegionName() + " @ " + (string)llGetPos() + " (Leaser: \"" + data_rented;
87 }
88
89 updateText()
90 {
91 string display = "";
92 if( llStringLength(data_rented)>0 )
93 {
94 display = "Rented by: " + data_rented;
95 display+= "\nExpires in: " + timespan(data_leased_until - llGetUnixTime());
96 llSetTexture("rental-rented",3);
97 }
98 else
99 {
100 display = "Not rented\n";
101 display+="Rent for " + (string)(config_rate*config_min_days) + "L/";
102 if( config_min_days!=7 )
103 {
104 display+=(string)config_min_days+" day(s).";
105 }
106 else
107 {
108 display+="week.";
109 }
110
111 llSetTexture("rental-forrent",3);
112 display+="\nTo rent, right-click and choose pay.";
113 }
114 llSetText(display,<0,0,0>,1.0);
115 }
116
117 string pop()
118 {
119 string result;
120 integer i = llSubStringIndex(text, " ");
121
122 if( i!=-1 )
123 {
124 i -=1;
125 result = llGetSubString(text,0,i);
126 text = llGetSubString(text,i+2,-1);
127 return result;
128 }
129 else
130 {
131 result = text;
132 text = "";
133 }
134
135 text = llStringTrim(text, STRING_TRIM);
136 result = llStringTrim(result, STRING_TRIM);
137
138 return result;
139 }
140
141
142 string timespan(integer time)
143 {
144 integer days = time / DAYSEC;
145 integer curtime = (time / DAYSEC) - (time % DAYSEC);
146 integer hours = curtime / 3600;
147 integer minutes = (curtime % 3600) / 60;
148 integer seconds = curtime % 60;
149
150 return (string)llAbs(days) + " days, " + (string)llAbs(hours) + " hours, "
151 + (string)llAbs(minutes) + " minutes, " + (string)llAbs(seconds) + " seconds";
152
153 }
154
155 default
156 {
158 {
160 }
161
162 run_time_permissions (integer perm)
163 {
164 if(perm & PERMISSION_DEBIT)
165 {
166 state ready;
167 }
168 }
169 }
170
171
172 state ready
173 {
175 {
176 integer amount = config_rate * config_min_days;
177 llSetPayPrice(PAY_HIDE,[amount,amount*2,amount*3,amount*4]);
178 originalPos = llGetPos();
179 llListen(0, "", NULL_KEY, "");
180 llListen(72, "", NULL_KEY, "");
181 updateText();
183 }
184
185 money(key giver, integer amount)
186 {
187 if( data_rented == "" )
188 {
189 llSay(0,"Thanks for renting! You may now open the doors.");
190 llGiveInventory(giver,"Encogia Beach Apartments");
191 data_rented = llKey2Name(giver);
192 data_rented_key = giver;
193 allow = [];
194
195 if((amount % config_rate ) != 0)
196 {
197 llSay(0,"You overpaid. Here is a partial refund");
198 llGiveMoney(giver,(amount % config_rate));
199 }
200 integer credit = (amount - (amount % config_rate))/config_rate;
201 data_leased_until = llGetUnixTime() + (credit * (24*60*60));
202 llInstantMessage(llGetOwner(), "NEW LEASE - $" + (string)(amount - (amount % config_rate)) + "L - " + rentalInfo());
203 reminderSent = FALSE;
204 warningSent = FALSE;
205 }
206 else
207 {
208 string who = llKey2Name(giver);
209
210 if( who==data_rented )
211 {
212 integer credit = (amount - (amount % config_rate))/config_rate;
213 data_leased_until = data_leased_until + (credit * (24*60*60));
214 llSay(0,"Your lease has been extended.");
215 reminderSent = FALSE;
216 warningSent = FALSE;
217 }
218 else
219 {
220 llGiveMoney(giver,amount);
221 llSay(0,"This unit is already rented, please find another to rent.");
222 }
223 }
224
225 updateText();
226 }
227
228 touch_start(integer total_number)
229 {
230 key who = llDetectedName(0);
231 integer shouldOpen = validateUser(who);
232
233 if( shouldOpen == TRUE )
234 {
235 llSay(0,"Hello " + llDetectedName(0) );
236 door(DOOR_OPEN);
237 state open_state;
238 }
239 else
240 {
241 if( data_rented=="" )
242 {
243 llGiveInventory(llDetectedKey(0),"Encogia Beach Apartments");
244 }
245 else
246 {
247 llSay(0,llDetectedName(0) + " is at the door." );
248 llTriggerSound("doorbell", 0.8);
249 }
250 }
251 }
252
253 timer()
254 {
255 if( data_rented!="" )
256 {
257 if(data_leased_until > llGetUnixTime() && data_leased_until - llGetUnixTime() < config_rentwarning * DAYSEC)
258 {
259 if(!reminderSent)
260 {
261 llInstantMessage(data_rented_key, "Your rent is due in "+(string)config_rentwarning+" days! - " + rentalInfo());
262 llSetTexture("lease-ex",ALL_SIDES);
263 reminderSent = TRUE;
264 }
265 }
266 else if(data_leased_until < llGetUnixTime() && llGetUnixTime() - data_leased_until < config_graceperiod * DAYSEC)
267 {
268 if(!warningSent)
269 {
270 llInstantMessage(data_rented_key, "Your rent is due! - " + rentalInfo());
271 llInstantMessage(llGetOwner(), "RENT DUE - " + rentalInfo());
272 warningSent = TRUE;
273 }
274 llSetTexture("lease-ex",ALL_SIDES);
275 }
276 else if(data_leased_until < llGetUnixTime())
277 {
278 llInstantMessage(data_rented, "Your lease has expired. Please clean up the space or contact the space owner.");
279 llInstantMessage(llGetOwner(), "LEASE EXPIRED: CLEANUP! - " + rentalInfo());
280 data_rented = "";
281 data_rented_key = "";
282 allow = [];
283 reminderSent = FALSE;
284 warningSent = FALSE;
285 }
286 updateText();
287 }
288
289 }
290
291 moving_end()
292 {
293 originalPos = llGetPos();
294 }
295
296 listen(integer channel, string name, key id, string message)
297 {
298 if( channel==72 )
299 {
300 list l = llCSV2List(message);
301 string n = llList2String(l,0); // name
302 string w = llList2String(l,1); // who
303 string c = llList2String(l,2); // code
304 if( name==llGetObjectName() )
305 {
306
307 if( validateUser(w)==TRUE )
308 {
309 llSay(72,c);
310 }
311 else
312 {
313 llSay(0,"To rent an apartment please visit the door located on the balcony.");
314 }
315 }
316
317 }
318 else if( (channel == PUBLIC_CHANNEL) && (id==llGetOwner() || llKey2Name(id)==data_rented) )
319 {
320
321 text = message;
322 string prefix = llToLower(pop());
323
324 if( prefix=="door" )
325 {
326 string command = pop();
327 if( command=="" )
328 {
329 llSay(0,"I am the smart door!");
330 }
331 else if( command=="clear" )
332 {
333 llSay(0,"Clearing access list.");
334 allow = [];
335 }
336 else if( command=="add" )
337 {
338 if( llStringLength(text)> 0 )
339 {
340 text = llToUpper(text);
341 allow+=[text];
342 llSay(0,"Adding " + text );
343 }
344 else
345 {
346 llSay(0,"You must also specify an avatar when using add.");
347 }
348 }
349 else if( command=="list" )
350 {
351 integer length = llGetListLength(allow);
352 if( length==0 )
353 {
354 llSay(0,"No one, other than my owner, may open me.");
355 }
356 else
357 {
358 integer i;
359 llSay(0,"The following people have access to open me:");
360 for (i = 0; i < length; ++i)
361 {
362 llSay(0,llList2String(allow, i));
363 }
364 }
365 }
366 else
367 {
368 llSay(0,"I did not understand that command, say \"door\" for a list of commands.");
369 }
370 }
371 }
372
373 }
374
375
376
377
378 }
379
380 state open_state
381 {
383 {
384 llSetTimerEvent(TIMER_CLOSE);
385 }
386
388 {
389 door(DOOR_CLOSE);
390 llSetPos(originalPos);
391 state ready;
392 }
393
394 timer()
395 {
396 door(DOOR_CLOSE);
397 llSetPos(originalPos);
398 state ready;
399 }
400
402 {
403 door(DOOR_CLOSE);
404 state ready;
405 }
406 }

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