/////////////////////////////////////////////////////////////////////////// // 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(); } }