Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Pay and give random object?

Jenee Marten
Registered User
Join date: 9 May 2004
Posts: 16
04-12-2006 02:05
I've seen the give random object script in forums but I haven't seen and would like a script where an avatar pays and then it gives you a random object... Any help?

Jenee
Ordinal Malaprop
really very ordinary
Join date: 9 Sep 2005
Posts: 4,607
04-12-2006 02:19
Try something like this:
CODE
// Lucky dip script
// Ordinal Malaprop
// 2006-04-12

string random_object_name()
{
integer n = llGetInventoryNumber(INVENTORY_OBJECT);
integer random = llFloor(llFrand((float)n));
return llGetInventoryName(INVENTORY_OBJECT, random);
}

default
{
state_entry()
{
llSetText("Lucky Dip\nPay Me L$1", <1.0, 1.0, 1.0>, 1.0);
llSetPayPrice(PAY_HIDE, [1, PAY_HIDE, PAY_HIDE, PAY_HIDE]);
}

money(key giver, integer amount)
{
// amount should always be 1
llGiveInventory(giver, random_object_name());
}
}


That will pick a random object from the inventory and give it whenever it's paid.