L$ Gift Giver ( V2 )

Written by: Headmaster

TAKE CARE WITH THIS ONE. IT WILL DEDUCT L$ FROM YOUR ACCOUNT ONCE YOU GRANT PERMISSIONS.

 

 

The script will give a gift of the stated amount of L$ to whoever touches the object it is in. The money will be deducted from the object owner's account. Only one gift will be given to each agent and only if the total amount given since the last time permissions were granted has not been maxxed. Once the amount given is equal to the total stated, the script will enter a quiet state and wait to be reset.

// V2 //
 
integer total = 100; // Total amount the script is allowed to give away.
 
integer gift = 1; // Amount to give per gift.
 
/////////////////////////////////////////////
 
key owner; // Used to store the owners UUID.
 
integer perms; // Used to store if permissions were granted.
 
integer given; // Used to count the total amount given.
 
list agents = []; // Used to store the UUIDs of the agents who have had a gift.
 
default
{
    on_rez(integer param)
    {
        llResetScript(); // Clear all lists and reset all variables. This action will also clear the permissions.
    }
    changed(integer change)
    {
        if(change & CHANGED_OWNER) // If the script or object changes ownership the script will not be able
        llResetScript();           // to deduct cash from the previous owners account.
    }
    state_entry()
    {
        owner = llGetOwner(); // Store the owners key.
        llRequestPermissions(owner, PERMISSION_DEBIT); // !! THIS MEANS IT WILL TAKE YOUR MONEY !!
    }
    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_DEBIT) // Have we got the permissions we requested?
        perms = TRUE; // Store the result of success.
        else
        llRequestPermissions(owner, PERMISSION_DEBIT); // If not we ask for them again.
    }
    touch_start(integer nd)
    {
        while(nd && (given < total) && perms) // Have we got permissions? Have we given less than the total allowed?
        {
            key agent = llDetectedKey(--nd); // grab the UUID of the touching agent.
            if(llListFindList(agents, [agent]) == -1) // Have we already given a gift to this agent?
            {
                agents += [agent]; // Add the agent to the list.
                llGiveMoney(agent, gift); // Give the gift to the agent who touched us.
                if((given += gift) == total) // Increment the amount given by the amount just given and check if we have maxxed out yet.
                state maxxed_out; // If maxxed out, go to a state with no touch_ event so we are not repeatedly messaged.
            }
        }
    }
}
state maxxed_out
{
    state_entry()
    {
        llInstantMessage(owner, "The total amount this object can give away has been given." + // Contact the owner.
                                "\nTo allow more to be given the script must be reset.");
    }
}

 

Category: