Difference between revisions of "User:Toady Nakamura/Give Anything"

From Second Life Wiki
Jump to navigation Jump to search
m (→‎More than one type of thing?: returned some parts to match the inworld student notes, while adding the revisions by Strife to show that both ways are correct.)
Line 83: Line 83:
         for (numma = 0; numma < bob; numma = numma + 1)// can also be written ...for (; numma < bob; ++numma)
         for (numma = 0; numma < bob; numma = numma + 1)// can also be written ...for (; numma < bob; ++numma)
         {
         {
             content += llGetInventoryName(INVENTORY_OBJECT, bob);
             content += llGetInventoryName(INVENTORY_OBJECT, numma);
         }
         }
     }
     }

Revision as of 14:49, 1 September 2014

There's five scripts on this page; three simple and one more complicated.

The top scripts are to be used if you only have *one* thing to give away. Use the bottom script if you have more than one thing to give away, even if they are of different types!

Place what you wish to give in the prim, and then select the appropriate script to give it!

Note: All givers will fail if you do not have permissions to give away the items.

Give Landmark

<lsl>

default {

   touch_start(integer total_number) 
   {         
       llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_LANDMARK, 0)); 
   } 

} </lsl>

Give Object

<lsl>

default {

   touch_start(integer total_number) 
   {         
       llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_OBJECT, 0)); 
   } 

} </lsl>

Give Notecard

<lsl>

default {

   touch_start(integer total_number) 
   {         
       llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_NOTECARD, 0)); 
   } 

} </lsl>

More than one type of thing?

This script hands all notecards and textures in a prim to anyone touching it - neatly packed in one folder, but it won't give away the script itself! Thanks to Foolish Frost for the initial version of this script!

<lsl> vector fcolor = < 1.0,1.0,1.0 >; // color for floating text string ftext = "Put your Floating Message Here"; string foldername = "Put the name of the Folder they will get Here.";

list content= []; // make empty list to hold data

default {

   state_entry()
   {   
       llSetText(ftext, fcolor, 1.0);
       // counts up and adds to content every landmark found 
       integer c = llGetInventoryNumber(INVENTORY_LANDMARK);
       integer i = 0;
       for (i = 0; i < c; i = i + 1)  // can also be written ... for (; i < c; ++i)
       {
           content += llGetInventoryName(INVENTORY_LANDMARK, i);
       }
       // counts up and adds to content every notecard found 
       integer d = llGetInventoryNumber(INVENTORY_NOTECARD);
       integer n = 0;
       for (n = 0; n < d; n = n + 1) // can also be written ... for (; n < d; ++n)
       {
           content += llGetInventoryName(INVENTORY_NOTECARD, n);
       }
       
       // counts up and adds to content every object found 
       integer bob = llGetInventoryNumber(INVENTORY_OBJECT);
       integer numma = 0;
       for (numma = 0; numma < bob; numma = numma + 1)// can also be written ...for (; numma < bob; ++numma)
       {
           content += llGetInventoryName(INVENTORY_OBJECT, numma);
       }
   }
   touch_start(integer total_number)
   {
       llGiveInventoryList(llDetectedKey(0), foldername, content);  // gives the contents to toucher
       llOwnerSay(llDetectedName(0) + "  got supplies."); // tells Owner toucher got stuff
   }

} </lsl>

Another No-script Giver

This is a slightly "fancier" scripting way to give all but not the script. It also checks that the giver has permissions to give away the object.

<lsl> list inventory = []; default {

   state_entry() 
   {
       integer i;
       for ( i = 0; i < llGetInventoryNumber(INVENTORY_ALL); i++) 
       {
           string item = llGetInventoryName(INVENTORY_ALL, i);
           if (llGetInventoryPermMask(item, MASK_OWNER) & PERM_COPY) 
           {
               inventory += [item];  // this adds all the giveable objects
           }
       }
       integer index =  llListFindList(inventory, [llGetScriptName()]); 
       inventory = llDeleteSubList(inventory, index, index); // this removes the script !!
   }
   touch_start(integer total_number)  
   { 
       llGiveInventoryList(llDetectedKey(0), llGetObjectName(), inventory); 
   } 

} </lsl>

Source of this one is from a gift box from Yadni Monde that I got in 2009. There's more simple scripts on my User page