Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Can a script rez an object from a box?

DrFran Babcock
Registered User
Join date: 30 Apr 2006
Posts: 69
11-08-2006 07:18
I am thinking about Holiday presents, and I would like to be able to have gifts *jump* out of a box when touched. Can that be done?
And, of course the obvious, does anyone have a script that can do this that they would share?
Aakanaar LaSalle
Registered User
Join date: 1 Sep 2006
Posts: 132
11-08-2006 07:42
llRezObject
Raeyan Aldrich
Registered User
Join date: 14 Oct 2006
Posts: 44
11-08-2006 08:30
here in the spirit of holliday joy i took a few minutes to write this to help you out and help you learn LSL :) plus... the grid is down right now so... lol
remember this though, when an object rezzes another object from inventory it will remove that object from it's inventory unless the object was flagged 'copy' in the item's inventory. I would suggest not having the items flagged copy. then you just give away this box to people and when they rez it, and click it... a bunch of presents pop up all around them.

CODE

//this code is not written in the most efficient manner
//it is writtin however in a manner which will help you to learn LSL :)
integer e = 0;
string newobject;
float newx;
float newy;
vector newposition;
vector myposition;

default
{
//object was rezzed
on_rez(integer rezzedme)
{
//get position of this object
myposition = llGetPos();
llSay(0, "HAPPY HOLLIDAYS! Click on me for a surprise!");
}

//Object was touched
touch_start(integer num_detected)
{
//reset e to 0
e = 0;
//loop through all 'object' items in inventory and rez them in a random pattern within 1-3m of the box
while((newobject = llGetInventoryName(INVENTORY_OBJECT,e)) != "")
{
//the 2 random functions below are designed to get 2 values
//one for x and one for y, we wanted to be able to place the new objects in
//a 1-3m radius, so we then pick a random number between 0 and 1 to see if
//we set the x and or y value to -(negative)
//set a new offset for the x-position of the new object
newx = llFrand(2.0) + 1.0;
//set a new offset for the y-position of the new object
newy = llFrand(2.0) + 1.0;
//set the new position for x
if(llRound(llFrand(1.0)) == 1)
{
newposition = (myposition + <newx,0,0>);
} else {
newposition = (myposition - <newx,0,0>);
}
//set new position for y
if(llRound(llFrand(1.0)) == 1)
{
newposition = (newposition + <0,newy,0>);
} else {
newposition = (newposition - <0,newy,0>);
}
//rez the object at the new position
llRezObject(newobject, newposition, ZERO_VECTOR, ZERO_ROTATION, 1);
//increment e for the next loop
e++;
}
}
}


remember to only put OBJECT items in the inventory of the box with this script!
an object spawning this many presents could hit a snag with the grey goo fence... it prevents objects from rezzing tons of stuff and self-replicating objects from reproducing too fast... if this becomes a problem, add a sleep timer to the 'while()' loop. see llSleep()

you will also need a script for the boxes that will actually give out the presents, it should be easier to script than this, see: llGiveInventory

If you can't figure it out, contact me in-game and maybe i'll lend ya a hand :D

-Raeyan Aldrich
DrFran Babcock
Registered User
Join date: 30 Apr 2006
Posts: 69
Thanks
11-08-2006 10:04
This is MORE than generous. My students at TeaZers will love this, and I can think of a million uses fo this script. I will try it the second I get home from work, AND if I use it, I will be sure to credit you in the class.