User talk:Ugleh Ulrik/GiveBulkMoney

From Second Life Wiki
Jump to navigation Jump to search

run_time_permissions

Just a few notes. Feel free to tell me where to stick my advice. I don't want to be a pain. <lsl>integer perms_granted;

GiveBulkMoney(list u, integer am) {

   integer a = 0;
   integer l = llGetListLength(u); // Arguable. Only call the function once but needs a new local variable
   do
   llGiveMoney(llList2Key(u, a), am); // A "do while" loop (according to this wiki) is faster and...
   while((++a) < l); // ...requires fewer bytes than a "while" or a "for" loop.

}

default {

   changed(integer change)
   {
       if(change & CHANGED_OWNER)
       llResetScript(); // Don't want scripts with perms to debit your account getting away.
   }
   state_entry()
   {
        llRequestPermissions(llGetOwner(), PERMISSION_DEBIT); 
   }
   run_time_permissions(integer perm) // Triggered by answer to request for perms.
   {
       if(perm & PERMISSION_DEBIT) // Did we get the perms we asked for?
       perms_granted = TRUE; // Record the answer for future checks.
   }
   touch_start(integer total_number)
   {
       list users = ["00000000-0000-0000-0000-000000000000",
                     "00000000-0000-0000-0000-000000000000"]; // List of those to pay.
       integer ammount = 2; // Linden Dollars
       if(perms_granted) // Only attempt to pay out if we have permissions.
       GiveBulkMoney(users, ammount);
   }

}</lsl> -- Fred Gandt (talk|contribs) 02:04, 30 April 2010 (UTC)