Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Random Object Rez

Zapoteth Zaius
Is back
Join date: 14 Feb 2004
Posts: 5,634
06-13-2005 18:20
Ok, I've made most of a script myself, and just need help with this last little bit...

This is what I have at the moment.

CODE

integer g_iCurrent;

default
{
state_entry()
{
g_iCurrent = 0;
}

touch_start(integer total_number)
{


integer number = llGetInventoryNumber(INVENTORY_OBJECT);
string name = llGetInventoryName(INVENTORY_OBJECT, g_iCurrent);

if (name != "") {

llRezObject(name, llGetPos() + <-0.7, -0.2, -0.5>, ZERO_VECTOR, ZERO_ROTATION, 42);

}

g_iCurrent++;
if ( g_iCurrent >= number )
g_iCurrent = 0;

}
}


Which works, but it rezzes the objects inside in order and I was wondering how to do it randomly? Or as random as is possible lol. It just has to be so its not in the same order all the time.

Thanks in advance!

Zap
_____________________
I have the right to remain silent. Anything I say will be misquoted and used against me.
---------------
Zapoteth Designs, Temotu (100,50)
---------------
Bret Hornet
Registered User
Join date: 6 Jun 2005
Posts: 29
06-13-2005 20:48
You just want to use llFrand to generate a random floating point number and then use llFloor or llCeiling to make it an integer.

This should work:

CODE

float randBetween(float min, float max)
{
return llFrand(max - min) + min;
}

default
{
touch_start(integer total_number)
{
string name = llGetInventoryName(INVENTORY_OBJECT,
llFloor(randBetween(0, llGetInventoryNumber(INVENTORY_OBJECT)));


llRezObject(name, llGetPos() + <-0.7, -0.2, -0.5>, ZERO_VECTOR,
ZERO_ROTATION, 42);
}

}
Jeffrey Gomez
Cubed™
Join date: 11 Jun 2004
Posts: 3,522
06-13-2005 20:48
Well, you could always add all of the stuff to a list and run llListRandomize.

Seems simple enough to me.
_____________________
---
Bret Hornet
Registered User
Join date: 6 Jun 2005
Posts: 29
06-13-2005 20:52
If you really want to be brief:

CODE

float randBetween(float min, float max)
{
return llFrand(max - min) + min;
}

default
{
touch_start(integer total_number)
{
llRezObject(llGetInventoryName(INVENTORY_OBJECT,
llFloor(randBetween(0, llGetInventoryNumber(INVENTORY_OBJECT))),
llGetPos() + <-0.7, -0.2, -0.5>, ZERO_VECTOR,
ZERO_ROTATION, 42);
}

}
Zapoteth Zaius
Is back
Join date: 14 Feb 2004
Posts: 5,634
06-13-2005 21:44
Thanks guys!

Oh and a big thanks to CrystalShard Foo and Davy Flytrap too!
_____________________
I have the right to remain silent. Anything I say will be misquoted and used against me.
---------------
Zapoteth Designs, Temotu (100,50)
---------------