Difference between revisions of "Give random object"

From Second Life Wiki
Jump to navigation Jump to search
m
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
== Yes, the random object giver ==
== Yes, the random object giver ==


Place this in an object with a big inventory (well, doesn't have to have LOTS in it) and touch to recieve any ole random object.
Place this in an object with a big inventory (well, doesn't have to have LOTS in it) and touch to receive a random object.


<lsl>//Emmas Seetan
<source lang="lsl2">
//21 September, 16:46
//Emmas Seetan
 
default
default
{
{
    touch_start(integer total_number)
    touch_start(integer num_detected)
    {
    {
        float totalobjects = llGetInventoryNumber(INVENTORY_OBJECT); //number of objects
    //  the key of the avatar touching
        totalobjects = llFrand(totalobjects); //Total objects
        key id = llDetectedKey(0);
        llGiveInventory(llDetectedKey(0),llGetInventoryName(INVENTORY_OBJECT, (integer)totalobjects)); //Give any random  object out of the total
 
    }
        integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
}</lsl>
    // random >> [0.0, max)
        randomIndex = (integer)llFrand(randomIndex);
 
        string itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);
 
        llGiveInventory(id, itemName);
    }
}
</source>

Latest revision as of 21:03, 24 January 2015

Yes, the random object giver

Place this in an object with a big inventory (well, doesn't have to have LOTS in it) and touch to receive a random object.

//Emmas Seetan

default
{
    touch_start(integer num_detected)
    {
    //  the key of the avatar touching
        key id = llDetectedKey(0);

        integer randomIndex = llGetInventoryNumber(INVENTORY_OBJECT);
    //  random >> [0.0, max)
        randomIndex = (integer)llFrand(randomIndex);

        string itemName = llGetInventoryName(INVENTORY_OBJECT, randomIndex);

        llGiveInventory(id, itemName);
    }
}