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. In this version there is no need for a notecard but at the cost of losing all the contestants in case the simulator goes down.
llSetText
(could be improved to anticipate limitations although the script will work regardless whether the llSetText
text limit has been exceeded).… and you are good to go.
/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, 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); } 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); 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(); } } }
This is a short script that implements a tombola system to pay a randomly picked agent an certain amount of money.
In order to set this system up, you need to create a notecard called Winners
containing key and agent ID pairs. An example notecard could contain the following items:
1ad33407-a792-476d-a5e3-06007c0802bf#Morgan LeFay f0d95467-3e63-4dfe-bc1e-7b163c6e1006#Trend Clowes
Next, you need to create a primitive and drop the notecard in that primitive. You also need to set the primitive's description to the amount of money that will be paid to a randomly picked agent from that notecard.
Copy the script below and change the access list to contain the names of the agents that will be allowed to use the tombola system. The names have to be the user-names of the agents and not the display names.
* The tombola system generates channels from the object key which allows you to have several objects in-place.
/////////////////////////////////////////////////////////////////////////// // Copyright (C) Wizardry and Steamworks 2011 - License: GNU GPLv3 // // Please see: http://www.gnu.org/licenses/gpl.html for legal details, // // rights of fair usage, the disclaimer and warranty conditions. // /////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// // CONFIGURATION // ////////////////////////////////////////////////////////// // Change this to include names of avatars who will be // able to confiugure this tombola via a menu. list ACCESS_LIST = [ "Morgan LeFay" ]; ////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // INTERNALS // /////////////////////////////////////////////////////////////////////////// key nQuery = NULL_KEY; integer nLine = 0; list nList = []; //pragma inline string nName = "Winners"; default { state_entry() { integer itra = llGetInventoryNumber(INVENTORY_NOTECARD)-1; do { if(llGetInventoryName(INVENTORY_NOTECARD, itra) == nName) jump winners; } while(--itra>=0); llOwnerSay("Failed to find winners notecard."); return; @winners; nQuery = llGetNotecardLine(nName, nLine); } dataserver(key id, string data) { if(id != nQuery) return; if(data == EOF) { llSetText("♣ Ready to draw a winner! ♣", <1,1,1>, 1); return; } if(data == "") jump next; nList += data; @next; nQuery = llGetNotecardLine(nName, ++nLine); } touch_start(integer total_number) { if(llListFindList(ACCESS_LIST, (list)llDetectedName(0)) == -1) return; integer comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF; nQuery = llDetectedKey(0); llListen(comChannel, "", nQuery, ""); llDialog(nQuery, "\nPlease select from the options below:\n", [ "♣ Draw ♣" ], comChannel); } listen(integer channel, string name, key id, string message) { if(message != "♣ Draw ♣") return; nList = llParseString2List(llList2String(nList, (integer)llFrand(llGetListLength(nList))), ["#"], []); llOwnerSay(llList2String(nList, 1)); state win; } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer pin) { llResetScript(); } } state win { state_entry() { llSetText("The winner is " + llList2String(nList, 1) + "!", <1,1,1>, 1); } touch_start(integer total_number) { if(llListFindList(ACCESS_LIST, (list)llDetectedName(0)) == -1) return; integer comChannel = ((integer)("0x"+llGetSubString((string)llGetKey(),-8,-1)) & 0x3FFFFFFF) ^ 0xBFFFFFFF; nQuery = llDetectedKey(0); llListen(comChannel, "", nQuery, ""); llDialog(nQuery, "\nPlease select from the options below:\n", [ "$ Payout $", "✘ Reset ✘" ], comChannel); } listen(integer channel, string name, key id, string message) { if(message == "$ Payout $") { nQuery = id; state payout; } if(message == "✘ Reset ✘") llResetScript(); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer pin) { llResetScript(); } } state payout { state_entry() { llRequestPermissions(nQuery, PERMISSION_DEBIT); } run_time_permissions(integer perm) { if(perm & PERMISSION_DEBIT) { if((integer)llGetObjectDesc() > 0) { llGiveMoney(llList2Key(nList, 0), (integer)llGetObjectDesc()); llSetText("$ " + llList2String(nList,1) + " has been paid " + llGetObjectDesc() + " $", <1,1,1>, 1); return; } llSetText("Object description must be set to\na value to pay to the winner!\nSet the object description and touch me to reset!", <1,1,1>, 1); return; } } touch_start(integer num) { if(llListFindList(ACCESS_LIST, (list)llDetectedName(0)) == -1) return; llResetScript(); } changed(integer change) { if(change & CHANGED_INVENTORY) llResetScript(); } on_rez(integer pin) { llResetScript(); } }