Don't click here unless you want to be banned.

LSL Wiki : LibraryEventLottery

HomePage :: PageIndex :: RecentChanges :: RecentlyCommented :: UserSettings :: You are crawl801.us.archive.org

Event Lottery Script

.
This is a simple script for randomly awarding money to event attendies. Everyone who wishes to enter simply clicks the object the script is on. To find a winner the owner of the object says 'Find Winner'. This can be repeated as often as needed to find as many winners as possible. After a name has 'won' it is removed from the pool. This is a simple script.

As a note, when I wrote this script I had little to no faith in llListFindList working, and so built my own, which as Ezhar pointed out, is probably not the optimal method at this point.
list names;
integer i;
integer j;
integer count;
string name;

integer find(string name)
{
    for (i=0;i<count;i++)
        if (llList2String(names,i) == name)
            return i;        
    return -1;
}

default
{
    state_entry()
    {
        llListen(0,"",llGetOwner(),"Find Winner");
        count = 0;
    }

    touch_start(integer total_number)
    {
        for (j=0;j<total_number;j++)
        {
            if (find(llDetectedName(j)) == -1)
            {
                name = llDetectedName(j);
                names += name;
                llSay(0,name + " has been entered.");
                count++;
            }
        }
    }
    
    listen(integer chan, string name, key id, string mes)
    {
        names = llListRandomize(names,1);
        i = llFloor(llFrand(llGetListLength(names)));
        llWhisper(0,"And the Winner is " + llList2String(names,i) + 
            "! There were " + (string)count + " participants.");
        names = llDeleteSubList(names,i,i);
    }
}

ScriptLibrary
Comments [Hide comments/form]
Attach a comment to this page: