Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Possible to give random item on touch?

Lopayza Moonlight
Registered User
Join date: 31 Aug 2005
Posts: 9
06-22-2006 21:17
I'm basically looking for a script that would give someone left-clicking on an item one of twelve possible objects within the prim, the one object picked at random. So I'd have all twelve possibilities within the prim, but I only want each touch to give one of those items, not all of them, and the one that's chosen is chosen at random.

Any help is greatly appreciated. Thanks. :)
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
06-22-2006 22:14
This should be what you need:

CODE
default
{
touch_start(integer total_number)
{
llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_OBJECT, (integer)(llFrand(1) * 12)));
}
}
_____________________
Kokiri Saarinen
Quoted for truth
Join date: 7 Jan 2006
Posts: 44
06-23-2006 00:07
From: Kayla Stonecutter
This should be what you need:

CODE
default
{
touch_start(integer total_number)
{
llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_OBJECT, (integer)(llFrand(1) * 12)));
}
}


Actualy you could simplify this slightly:

CODE
default
{
touch_start(integer total_number)
{
llGiveInventory(llDetectedKey(0), llGetInventoryName(INVENTORY_OBJECT, (integer)llFrand(12)));
}
}
Angela Salome
Registered User
Join date: 6 Oct 2005
Posts: 224
06-23-2006 14:52
Actualy you could simplify this slightly:

For any number of objects in the inventory:
CODE
default
{
touch_start(integer total_number)
{
llGiveInventory (llDetectedKey(0), llGetInventoryName (INVENTORY_OBJECT,
(integer) llFrand (llGetInventoryNumber (INVENTORY_OBJECT))));
}
}
MeLight Korvin
Im on da Use
Join date: 4 Jun 2005
Posts: 99
06-23-2006 16:46
ha funneh
_____________________
Boobs are remote controls for the male brain. Lemmie push some buttons!!!
Kayla Stonecutter
Scripting Oncalupen
Join date: 9 Sep 2005
Posts: 224
06-23-2006 17:00
Read elsewhere on the forums (I believe from Strife) that

llFrand(n);

doesn't work as well as

llFrand(1) * n;

so that's why I wrote mine the way it was. *shrug*
_____________________
Lopayza Moonlight
Registered User
Join date: 31 Aug 2005
Posts: 9
06-23-2006 21:16
Thank you all for the replies, including the in-world one! I'll give them a try and see if I get the results I want. I appreciate the help. :)