User:Auryn Beorn/GiveScriptForMLPv2

From Second Life Wiki
Jump to navigation Jump to search

My very own modification to the ~give script that we may use in MLPv2.
Starting point: The script from Chaz Longstff. <lsl> // Add-on by Chaz Longstff for MLPV2 by Lear Cale. June 2008. // Function: gives object to someone on an MLPV2 ball // MLP button: LINKMSG MyButtonName | 1,-4,987789,NamesOfObjectToOffer##MsgToPerson##FolderName

/*

   - Few memory optimizations
   - Sending item or folder depending upon the total of items to send
   - Checks if the item is copy AND transfer for next owner, not raising a runtime error
     in the rare event of a server hiccups not acknowledging the item in inventory
     Auryn Beorn, 2012-03-27
  • /


/*

   In a menu card, format a menu button like this, for example:
       LINKMSG TieMeUp | 1,-4,987789,Cuff1#Cuff2#Cuff3#Cuff4##Wear these four cuffs##Cuffs
   In this example, TieMeUp is the button name
       1 means whether to make the MLPV2 menu go away or not.
           Generally set it to 1 as per the example, as otherwise the user
           might not see the accept prompt for the inventory being given.
       -4 is the value of LINK_THIS, meaning, send this message to this prim only.
           (Use -1 if the ~give script is in a different prim.)
       987789 -- don't change this, this is the link message number
       Cuff1#Cuff2#Cuff3#Cuff4##Wear these four cuffs##Cuffs
           The items separated by # are the items to give,
               Cuff1, Cuff2, Cuff3, Cuff4
           followed by a message to be instant messaged to the recipient
           of the object.
               Wear these four cuffs
           It's good to include a msg, so that they don't think
           it's a griefer trying to hand them something. Notice that the list
           of objects to give and the accompanying msg are separated by ##
           Then finally, the name of a folder to create in inventory,
               Cuffs
           in case we're sending more than one item
  • /


default {

   state_entry()
   {
       llSetMemoryLimit(8192);
   }
   link_message(integer from, integer num, string str, key id)
   {
       if(num == 987789)
       {
           list    TempList = llParseStringKeepNulls(str, ["##"], []);
           string  FolderName = llStringTrim(llList2String(TempList, 2), STRING_TRIM);
           string  message  = llStringTrim(llList2String(TempList, 1), STRING_TRIM);
           string  Objects  = llStringTrim(llList2String(TempList, 0), STRING_TRIM);
           list    ObjectsToGive = llParseStringKeepNulls(Objects, ["#"], []);
           integer GiveLength = (ObjectsToGive != []);
           if(GiveLength)  // If there are objects to give
           {
               if(message != "")
               {
                   llInstantMessage(id, message + " - " + FolderName);
               }
               if(GiveLength > 1)
               {
                   integer x;
                   list    ItemsToGive = [];
                   for(x = 0; x < GiveLength; ++x)
                   {
                       string ObjectToGive = llStringTrim(llList2String(ObjectsToGive, x), STRING_TRIM);
                       if(~llGetInventoryType(ObjectToGive))       // Same as asking if != INVENTORY_NONE
                       {
                           if  (
                                   (llGetInventoryPermMask(ObjectToGive, MASK_NEXT) & PERM_COPY)
                                   && (llGetInventoryPermMask(ObjectToGive, MASK_NEXT) & PERM_TRANSFER)
                               )
                           {
                               ItemsToGive += [ObjectToGive];
                           }
                       }
                   }
                   if(ItemsToGive != [])
                   {
                       llGiveInventoryList(id, FolderName, ItemsToGive);
                   }
               }
               else
               {
                   string ObjectToGive = llStringTrim(llList2String(ObjectsToGive, 0), STRING_TRIM);
                   if(~llGetInventoryType(ObjectToGive))       // Same as asking if != INVENTORY_NONE
                   {
                       if  (
                               (llGetInventoryPermMask(ObjectToGive, MASK_NEXT) & PERM_COPY)
                               && (llGetInventoryPermMask(ObjectToGive, MASK_NEXT) & PERM_TRANSFER)
                           )
                       {
                           llGiveInventory(id, ObjectToGive);
                       }
                   }
               } // if(GiveLength > 1)
           } // if(GiveLength)
       } // if(num == 987789)
   } // link_message

} </lsl>