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
Games AUTORAFFLER_version_1  

AUTORAFFLER_version_1

AUTORAFFLER version 1.lsl

Category: Games
By : Johnson Earls
Created: 2010-01-10 Edited: 2010-01-10
Worlds: Second Life

the Zip file

Download all files for AUTORAFFLER_version_1
Contents are in zip format, with .LSL (text) source code and LSLEdit (text + Solution) formats.
Get file # 1. AUTORAFFLER_version_1_1.lsl
1
2 // AUTORAFFLER version 1.1
3 // by Neo Rebus
4 // Copyright (c) 2004 by Johnson Earls, All Rights Reserved
5 // See end of file for license information
6 //
7 // This is an automatic raffling system. Once started, it will
8 // periodically conduct a raffle on its own and give the prize to the
9 // winner. The winner must accept the prize within 15 seconds or the
10 // autoraffler will choose a different winner. (This allows the owner
11 // of the object or property to decline accepting a prize)
12 //
13 // SETUP:
14 //
15 // Create an object that fills the volume in which the raffle attendees
16 // will be standing. The object can consist of multiple prims. Once
17 // the autoraffle script is put on the object, it will become phantom.
18 // The object should be named something descriptive (as it will say
19 // things to the world), and should be transparent since people will be
20 // standing inside it.
21 //
22 // Put the autoraffle script into the raffler object, then put the
23 // objects to be raffled in. Everything being raffled must be an
24 // *object*, not a texture or landmark or anything. If you want to
25 // raffle other types of things off, put them inside their own object
26 // and raffle that object. If you want to raffle money, make an object
27 // named "L$### ..." and the winner will be given ### linden dollars
28 // rather than the object itself.
29 //
30 // at this point, the autoraffler accepts voice commands to control it:
31 //
32 // autoraffle reset
33 // to reset the script
34 // autoraffle list
35 // to list the people entered in the raffle
36 // autoraffle list winners
37 // to list people who have won the raffle since it was reset
38 // autoraffle stop
39 // to stop an ongoing raffle
40 // autoraffle start [ <interval> [ <count> ] ]
41 // to start a raffle. <interval> and <count> are optional. If
42 // interval is not given, it will default to about 30 seconds.
43 // If count is not given, it will raffle off all the objects in
44 // the autoraffler's inventory.
45 //
46 // example: autoraffle start 20 5
47 // this will start the autoraffler with a raffle every 20 minutes
48 // (starting 20 minutes from now), raffling off 5 random prizes.
49 //
50
51 integer raffleAcceptTimeout = 15;
52
53 integer runningRaffleCount = 0;
54 integer runningRaffleInterval = 0;
55
56 integer runningRaffleListenerChat = 0;
57 integer runningRaffleListenerPrivate = 0;
58
59 list runningRaffleEntrants = [];
60 list runningRaffleWinners = [];
61
62 key thisRafflePrize = NULL_KEY;
63 string thisRafflePrizeName = "";
64 key thisRaffleWinner = NULL_KEY;
65 string thisRaffleWinnerAccepted = "";
66 list thisRaffleEntrants = [];
67
68 integer PRIVATE_CHAT = 1316110706 ;
69
70 list remove_from_list(list src, list what)
71 {
72 // find 'what'
73 integer idx = llListFindList(src, what);
74 if(idx > -1)
75 {
76 list pfx; // the list before 'what'
77 list sfx; // the list after 'what'
78 if(idx > 0)
79 {
80 pfx = llList2List(src, 0, idx - 1);
81 } else {
82 pfx = [];
83 }
84 if(idx < llGetListLength(src) - llGetListLength(what))
85 {
86 sfx = llList2List(src, idx + llGetListLength(what), -1);
87 } else {
88 sfx = [];
89 }
90 return pfx + sfx;
91 } else {
92 return src;
93 }
94 }
95
96 raffleWinner(key winner)
97 {
98
99 // if the winner is not NULL_KEY, give them the prize.
100 // if the winner *is* NULL_KEY, give the script owner the prize.
101 // remove the prize from the inventory, decrement the raffle count, and call nextRaffle().
102
103 if(winner == NULL_KEY)
104 {
105 llSay(0, "No one accepted the prize!");
106 if(llGetSubString(thisRafflePrizeName, 0, 1) != "L$")
107 {
108 llGiveInventory(llGetOwner(), thisRafflePrizeName);
109 }
110 } else {
111 if(llGetSubString(thisRafflePrizeName, 0, 1) == "L$")
112 {
113 llGiveMoney(winner, llList2Integer(llParseString2List(thisRafflePrizeName, [" ", "$"], []), 1));
114 } else {
115 llGiveInventory(winner, thisRafflePrizeName);
116 }
117 runningRaffleWinners = runningRaffleWinners + [ winner ];
118 }
119
120 llRemoveInventory(thisRafflePrizeName);
121
122 thisRafflePrize = NULL_KEY;
123 thisRafflePrizeName = "";
124 thisRaffleWinner = NULL_KEY;
125
126 runningRaffleCount -= 1;
127
128 nextRaffle();
129 }
130
131 nextRaffle()
132 {
133 llSetTimerEvent(0.0); // just in case
134
135 // if the raffle count is 0, announce the end of the raffle and reset running variables.
136 if(runningRaffleCount == 0)
137 {
138
139 runningRaffleInterval = 0;
140 thisRafflePrize = NULL_KEY;
141 thisRafflePrizeName = "";
142 thisRaffleWinner = NULL_KEY;
143 thisRaffleWinnerAccepted = "";
144 thisRaffleEntrants = [];
145 llSay(0, "The raffle is over! Thank you for attending!");
146
147 } else {
148
149 // compute the timer value. if < 5, set it to 5.
150 float timer_value = runningRaffleInterval - llGetTime();
151 if(timer_value < 30.0)
152 {
153 timer_value = 30.0;
154 }
155 llSetTimerEvent(timer_value);
156
157 // initialize raffle params.
158 thisRaffleWinner = NULL_KEY;
159 thisRafflePrize = NULL_KEY;
160 thisRafflePrizeName = "";
161
162 // announce the raffle.
163 if(timer_value < 120)
164 {
165 llSay(0, "The next raffle is coming up!");
166 } else {
167 llSay(0, "The next raffle will be in " + (string)(llFloor(timer_value / 60.0)) + " minutes.");
168 }
169
170 }
171 }
172
173 chooseWinner()
174 {
175
176 integer nument = llGetListLength(thisRaffleEntrants);
177
178 // if no valid entrants, call raffleWinner(NULL_KEY) to give item back to owner.
179 if(nument == 0)
180 {
181 raffleWinner(NULL_KEY);
182 } else {
183
184 // pick a random person from the entrants. Announce that they won.
185 // give them a dialog to allow them to decline the prize, and set a
186 // timer for the timeout.
187
188 integer winner = llCeil(llFrand(nument)) - 1;
189
190 thisRaffleWinner = llList2Key(thisRaffleEntrants, winner);
191 llSay(0, "The winner is " + llKey2Name(thisRaffleWinner) + "!");
192 llSetTimerEvent(raffleAcceptTimeout);
193 llDialog(thisRaffleWinner, "Do you wish to accept the raffle prize " + thisRafflePrizeName + "?", [ "Yes", "No" ], PRIVATE_CHAT);
194
195 }
196
197 }
198
199 default
200 {
201
203 {
204 // turn off the timer
205 llSetTimerEvent(0.0);
206
207 // get permission to give money
209
210 // reset the running raffle parameters
211 runningRaffleCount = 0;
212 runningRaffleInterval = 0;
213 runningRaffleEntrants = [];
214 runningRaffleWinners = [];
215
216 thisRafflePrize = NULL_KEY;
217 thisRafflePrizeName = "";
218 thisRaffleWinner = NULL_KEY;
219
220 // turn volume detect off, then back on, to force collision_start events
222 llSleep(0.1);
224
225 // remove listeners and re-add them
226 llListenRemove(runningRaffleListenerChat);
227 llListenRemove(runningRaffleListenerPrivate);
228 runningRaffleListenerChat = llListen(0, "", NULL_KEY, "");
229 runningRaffleListenerPrivate = llListen(PRIVATE_CHAT, "", NULL_KEY, "");
230 }
231
232 on_rez(integer start_code)
233 {
234 // reset script
236 }
237
238 collision_start(integer total_number)
239 {
240 integer i;
241 for (i=0; i<total_number; i++)
242 {
243 // in order to be an avatar, the detected item's key must = the item's owner.
245 {
246 // check if the detected person is already in Entrants. if not, add them.
247 if(llListFindList(runningRaffleEntrants, [ llDetectedKey(i) ]) == -1)
248 {
249 runningRaffleEntrants = runningRaffleEntrants + [ llDetectedKey(i) ];
250 }
251 }
252 }
253 }
254
255 collision_end(integer total_number)
256 {
257 integer i;
258 for (i=0; i<total_number; i++)
259 {
260 // remove the person from Entrants
261 runningRaffleEntrants = remove_from_list(runningRaffleEntrants, [ llDetectedKey(i) ]);
262 }
263 }
264
265 listen(integer channel, string name, key id, string msg)
266 {
267
268 // convert msg to lowercase
269 msg = llToLower(msg);
270
271 // on chat channel, listen for "autoraffle" commands.
272 if((channel == 0) && (id == llGetOwner()) && (llGetSubString(msg, 0, 10) == "autoraffle "))
273 {
274
275 if(msg == "autoraffle stop")
276 {
277
278 // turn autoraffle off by setting the runningRaffleCount to 0 and calling nextRaffle()
279 runningRaffleCount = 0;
280 nextRaffle();
281
282 } else if(msg == "autoraffle list")
283 {
284
285 // generate comma-separated list of entrants with 'and' between last two
286 integer i;
287 integer num;
288 string entrants = "";
289 num = llGetListLength(runningRaffleEntrants);
290 for (i=0; i<num; i++)
291 {
292 string name = llKey2Name(llList2Key(runningRaffleEntrants, i));
293 if(i == 0)
294 {
295 entrants = name;
296 } else if(i == num - 1)
297 {
298 if(i > 1)
299 {
300 entrants = entrants + ",";
301 }
302 entrants = entrants + " and " + name;
303 } else {
304 entrants = entrants + ", " + name;
305 }
306 }
307 llSay(0, "The current raffle entrants are " + entrants);
308
309 } else if(msg == "autoraffle list winners")
310 {
311
312 // generate comma-separated list of entrants with 'and' between last two
313 integer i;
314 integer num;
315 string winners = "";
316 num = llGetListLength(runningRaffleWinners);
317 for (i=0; i<num; i++)
318 {
319 string name = llKey2Name(llList2Key(runningRaffleWinners, i));
320 if(i == 0)
321 {
322 winners = name;
323 } else if(i == num - 1)
324 {
325 if(i > 1)
326 {
327 winners = winners + ",";
328 }
329 winners = winners + " and " + name;
330 } else {
331 winners = winners + ", " + name;
332 }
333 }
334 llSay(0, "The raffle winners so far have been " + winners);
335
336 } else if(msg == "autoraffle reset")
337 {
338
339 // reset script
341
342 } else if((msg == "autoraffle start") ||
343 (llGetSubString(msg, 0, 16) == "autoraffle start "))
344 {
345
346 // split message into params, set interval and count,
347 // and call nextRaffle()
348 list params = llParseString2List(msg, [" "], []);
349 integer npar = llGetListLength(params);
350 if(npar > 2)
351 {
352 runningRaffleInterval = llList2Integer(params, 2);
353 } else {
354 runningRaffleInterval = 0;
355 }
356 if(npar > 3)
357 {
358 runningRaffleCount = llList2Integer(params, 2);
359 } else {
360 runningRaffleCount = llGetInventoryNumber(INVENTORY_OBJECT);
361 }
363 nextRaffle();
364
365 }
366 }
367
368 if((channel == PRIVATE_CHAT) && (id == thisRaffleWinner))
369 {
370
371 // on the private chat, set the Accepted string and reset
372 // the timer to go off as quickly as possible
373 thisRaffleWinnerAccepted = msg;
374 llSetTimerEvent(0.1);
375
376 }
377
378 }
379
380 timer()
381 {
382
383 // unset the timer
384 llSetTimerEvent(0.0);
385
386 // if we don't have a winner, then we're still selecting one.
387 if(thisRaffleWinner == NULL_KEY)
388 {
389
390 // if we don't have a prize key, then we need to announce it.
391 if(thisRafflePrize == NULL_KEY)
392 {
393 // reset the time so the next raffle is based on this time.
395
396 // if we don't have any entrants, then skip this raffle attempt
397 if(llGetListLength(thisRaffleEntrants) == 0)
398 {
399
400 nextRaffle();
401
402 } else {
403
404 // if we have no items, let the raffle owner know via IM
406 if(n == 0)
407 {
408
410 ": No items left to raffle!");
411 nextRaffle();
412
413 } else {
414
415 n = llCeil(llFrand(n)) - 1;
416 thisRafflePrizeName = llGetInventoryName(INVENTORY_OBJECT, n);
417 thisRafflePrize = llGetInventoryKey(thisRafflePrizeName);
418 llSetTimerEvent(10.0);
419 llSay(0, "Now raffling: " + thisRafflePrizeName);
420
421 }
422 }
423
424 } else {
425
426 // we have a prize key, find a winner.
427 thisRaffleEntrants = runningRaffleEntrants;
428 chooseWinner();
429
430 }
431 } else {
432
433 // we have a winner. therefore they've already been offered
434 // the win dialog. if they accept, call raffleWinner(); otherwise,
435 // remove them from thisRaffleEntrants and call chooseWinner() again.
436 if(thisRaffleWinnerAccepted == "yes")
437 {
438 raffleWinner(thisRaffleWinner);
439 } else {
440 llSay(0, llKey2Name(thisRaffleWinner) + " did not accept the raffle prize.");
441 thisRaffleEntrants = remove_from_list(thisRaffleEntrants, [ thisRaffleWinner ]);
442 chooseWinner();
443 }
444 }
445
446 }
447
448 }
449
450
451 ////////////////////////////////////////////////////////////////////////
452 //
453 // Auto-Raffler version 1.0
454 // by Neo Rebus
455 // Copyright (c) 2004 by Johnson Earls
456 // All Rights Reserved
457 //
458 // Permission to Use and Redistribute
459 //
460 // Permission to use and redistribute the Auto-Raffler code, with or
461 // without modifications, is granted under the following conditions:
462 //
463 // + All redistributions must include this copyright notice and license.
464 // + All redistributions must give credit to the author, by real name
465 // (Johnson Earls) and by SL name (Neo Rebus). If distributed in a
466 // modified form, credit must still be given to Neo Rebus (Johnson
467 // Earls) as the original author.
468 // + All redistributions *should* include the setup information at the
469 // beginning of the script.
470 //
471 ////////////////////////////////////////////////////////////////////////// END //

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