Difference between revisions of "Give random object"

From Second Life Wiki
Jump to navigation Jump to search
m (improved readability)
m
 
Line 3: Line 3:
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.
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>
<source lang="lsl2">
//Emmas Seetan
//Emmas Seetan


Line 22: Line 22:
     }
     }
}
}
</lsl>
</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);
    }
}