Raffle
Created by Kira Komarov.
Introduction
The raffle system is meant for parties. A bunch of avatars touch the primitive this script is located in and at the end the owner can chose to draw a winner from the lot. This is similar to the more elaborate Notecard Raffle which uses a permanent and manual addition of agents. In this version however, there is no need for a notecard but at the cost of losing all the contestants in case the simulator goes down.
Features
- Automatic or manual payout: you can chose a manual payout and pay the amount yourself.
- Lists the contestants using llSetText (could be improved to anticipate limitations although the script will work regardless whether the llSetText text limit has been exceeded).
Setup
- Set the object's description to the amount of money to be paid to the winner.
- Drop the script below in a primitive.
... and you are good to go.
Code
<lsl> ////////////////////////////////////////////////////////// // [K] Kira Komarov - 2011, License: GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html // // for legal details, rights of fair usage and // // the disclaimer and warranty conditions. // //////////////////////////////////////////////////////////
list _contestK = []; key _owner = NULL_KEY;
default {
state_entry() { _owner = llGetOwner(); llSetText("♣ Click to join the contest! ♣", <1,1,1>, 1.0); }
touch_start(integer num) { key ct = llDetectedKey(0); if(ct == llGetOwner()) jump owner; if(llListFindList(_contestK, (list)ct) != -1) return; _contestK += ct; list pot = []; num = llGetListLength(_contestK)-1; do { pot += llKey2Name(llList2Key(_contestK, num)); } while(--num>=0); llSetText("♣ Raffle! ♣\n" + llDumpList2String(pot, "\n"), <1,1,1>, 1.0); return;
@owner;
if(llGetListLength(_contestK) == 0) return; integer comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF + (integer)("0x"+llGetSubString((string)_owner,-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF; llListen(comChannel, "", _owner, ""); llDialog(_owner, "\nPlease sleect from the options below:\n", [ "$ Payout $", "Manual" ], comChannel); } listen(integer channel, string name, key id, string message) { if(message == "$ Payout $") state payout; integer win = (integer)llFrand(llGetListLength(_contestK)); llShout(0, "The winner is: " + llKey2Name(llList2Key(_contestK, win)) + "!"); llResetScript(); } on_rez(integer pin) { _owner = llGetOwner(); } changed(integer change) { if(change & CHANGED_OWNER) _owner = llGetOwner(); }
}
state payout {
state_entry() { llRequestPermissions(_owner, PERMISSION_DEBIT); } run_time_permissions(integer perm) { if(perm & PERMISSION_DEBIT) { integer win = (integer)llFrand(llGetListLength(_contestK)); llSay(0, "The winner is: " + llKey2Name(llList2Key(_contestK, win)) + "!"); llGiveMoney(llList2Key(_contestK, win), (integer)llGetObjectDesc()); llResetScript(); } }
} </lsl>