Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Library: Fruit tree that rezzes fruit through a growth cycle

Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
06-11-2008 01:27
Hi everyone, as promised here is my fruit tree script you all helped me with these last two weeks. There are two distinct scripts as explained in the script comments.

For a look at the working model, here is a SLURL for you all:

http://slurl.com/secondlife/Bishara%20Island/220/196/23

One more thing - growth is controlled by changing the value of 'Growth' and timing is controlled by changing the values of 'zee' for ripeness and 'zat' for rotteness.

I commented everything I could to prevent anyone from accidentally leaving uncommented instructions within their cut and paste action. Most comments can be removed to a notecard and the scripts cleaned up accordingly. The SLURL has a working example of the scripts shown as the Bishara Melon Tree.

Cheers,

Dumi


// Fruit Rezzing Tree Scripts

//
//Fruit script modifications and amendments by Dumisani Ah with lots of help from the SL Scripting Tips Forum.
//Based in part on the Growth Script By Floog Stuart and Cid Jacob's Photosynthesis Script.

// The initial script is to link the rezzing object to a tree branch you made so that when you rezzed the complete tree (trunk, branches, foilage and these fruit rezzing orbs) it will start the growth of the fruit immediately.
//
// The prims you should create should be at least two, one being the little fruit rezzing orb described first below, and the other being the actual fruit, a creation of yours, that you wish to 'grow' from your tree. The rest, the tree and
// foilage, you can see from my own version, how to build up. If you need help with the tree trunk prim just IM me, but my foilage sucks so best you try your own hand at it
//
// The position of the fruit rezzing orb or object or prim is important as it needs to be near enough to the end of the branch you made to look like the fruit is grwing from the tree, and far enough from the tree branch so that the growing
// fruit do not grow into the branch and spoil the look. I would recommend you place the fruit rezzer or rezzing orb just below the branch, about 0.350 below or at least 0.05 MORE than your maximm growth number you are using in the
// script. For the standard version below 0.350 is enough of a distance for the fruit to still grow and 'hang' from the branch.
//
// This fruit rezzing orb is the only part that you LINK to your tree object, and you can link as many versions as you want fruit on it. Just keep in mind that rezzing objects does impact the region's performance where you are.
//
// Once you have the rezzing orb and the fruit created and you have placed the script for each inside the content tabs of the objects, you need to copy them into your inventory or take them into inventory. Then drag one rezzing orb out
// of your inventory and place it. Open its Content tab and then drag one copy of the fruit object from your inventory into this Content tab of the fruit rezzing orb. That;s all you need to do, except to rename the versions of your
// creation in your inventory so that you don't get mixed up with which are which
//
// The rezzing action works as follows - the fruit rezzing orb 'rezzes' a new fruit and then passes it a copy of the fruit. On completion of the fruit script the fruit object rezzes a new fruit, turns physical to fall from the tree and dies.

// Fruit rezzing orb script - copy below this line
//__________________________________________________ __________
default
{
state_entry()
{
llSetText("",<1,1,1>,1);
rotation rot = llGetRot();
llRezAtRoot("fruit", llGetPos() + <0.0,0.0,0.0>, <0.0,0.0,0.0>, rot, 1000);
}
on_rez(integer start_param)
{
// Reset script when the object is rezzed
llResetScript();
}
object_rez(key child)
{
llGiveInventory(child, llKey2Name(child));
}
}

//__________________________________________________ ___________
// Copy only until above this line

// Paste this little script into a small semi transparent sphere that you place 0.350 below the end of your branch where you wish to have your fruit growing.
// Set the script to not run until you have completed your entire build.


// Growth, Color and Die script- copy below this line
//__________________________________________________ __________
//
//Makes a fruit grow on it's X and Z axis when the sun is out. Starts growth when the fruit is rezzed. Fruit ripens and rots to fall from the tree.


vector direction; //States the variables used in the script
vector scale;
float growth;
vector pos;
float zee = 0.250;
float zat = 0.270;

default
{
state_entry()
{
llSetText("",<1,1,1>,1); //Clears Text above prim.
}

on_rez(integer num_detected)
{
llSetTimerEvent(15); //Starts growth in 15 seconds
}
timer()
{
//Growth Timer
float FloatValue = llFrand(60); //Creates a random value between 60 and 0 to be used to decide how many seconds to delay between growth
if (FloatValue < 10) //if the random value is below 10 seconds
{
float AddedValue = FloatValue + 15; //it adds 15 more seconds
llSetTimerEvent(AddedValue); //Sets the new growth delay to AddedValue
}
else //If the random Value was above 10.
{
llSetTimerEvent(FloatValue); //Set the new growth delay to FloatValue
}


//Growth
growth = 0.005; //Decides how much to make it grow each time.
direction = llGetSunDirection(); //Checks to make sure the sun is up.
if ( direction.z > 0 ) //If the sun is up.
{
scale = llGetScale(); //Gets the size of the fruit.
llSetScale(<scale.x + growth,scale.y,scale.z + growth>;); // Adds the amount it will grow to the X and Z axis.

//Growth Percentage
// float growth_percent = scale.z / .100; //Finds the percentage it is to it's max size.
// llSetText("",<1,1,1>,1.0); //Adds the Growth Percentage above the fruit should you wish to use this. Percentage calculation in this script is only for the text comment so you may wish to comment this little section out completely as I have.
}

if(zee < scale.z) //Checks if the fruit is ripe. Again we only check Z axis as a guide to growth as the X axis would be the same value. You can use either if you wish.
{
llSetText("ripe",<1,1,1>,1); //Says that the fruit is ripe.
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1.0,0.0,0.0>, 1.0]);
}

if(zat < scale.z) //Checks if the fruit is max growth. Again we only check Z axis as a guide to growth as the X axis would be the same value. You can use either if you wish.
{
llSetText("full grown ",<1,1,1>,1); //Says that the fruit is full grown.
state fullgrown; //Goes to state fullgrown shown below
}

}
}

state fullgrown //state fullgrown is used to indicate the phase where one fruit dies and regrows another in its place
{
state_entry()
{
llSetText("",<1,1,1>,1);
llSetPrimitiveParams([PRIM_COLOR, ALL_SIDES, <1.0,1.0,1.0>, 1.0]);
rotation rot = llGetRot();

llRezAtRoot("fruit", llGetPos() + <0.0,0.0,0.0>, <0.0,0.0,0.0>, rot, 1000);
}
object_rez(key child)
{
llGiveInventory(child, llKey2Name(child));
llSetPrimitiveParams([PRIM_TEMP_ON_REZ, TRUE,
PRIM_PHYSICS, TRUE]);
}
}

// NOTES TO THE USER
// All llSetText(); can be completely deleted once you are happy with the way the fruit grows. I used them only for testing as I can insert into them different statements to show progression of the script.
// Please do not remove any comments from this script and always use it with full perms in your own creations as it is in this spirit that the code was made available to all of us in SL by Floog Stuart and Cid Jacob.
// Modify and change as much as you like and experiment experiment experiment. It is how I am learning and it will certainly be as gratifying to you to succeed at something using this script as it has been for me.

//__________________________________________________ ___________
// Copy only until above this line
_____________________
Screwdrivers are so 90's...
Nada Epoch
The Librarian
Join date: 4 Nov 2002
Posts: 1,423
Library bump
06-11-2008 06:41
:)
_____________________
i've got nothing. ;)
Dragger Lok
(loading ...)
Join date: 10 Sep 2006
Posts: 228
Oops
06-17-2008 16:54
Works flawlessly once the script is reset, but can't use llResetScript(); to get it to reset onrez, any clue?

----------------------------
Update:

My partner found what was missing;

state_entry()
{
// Script initialization here
}

on_rez(integer start_param)
{
// Reset script when the object is rezzed
llResetScript();


Works like a charm :-) thanks love
Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
06-18-2008 00:27
Hi Dragger,

You are quite correct. I discovered this after rezzing a second version to my test tree, and it did not start on rezz. I have also added the script reset and will update the library to include the latest version. I will post an additional section to it later this week that includes a single fruit plant, like a pumpkin or something, that grows and dies on the plant without falling off, and will rezz a slice or gift during its 'RIPE' state to who ever touches it (only once per fruit so as to prevent spam :p)

Then I will be adding a seasonal system that allows different states of growth in different seasons (emulated since SL does not have seasons as yet).

I hope we inspire LOTS of new farmers and gardeners in SL now.

WOOOTTT!
_____________________
Screwdrivers are so 90's...
Klear Moonlight
Registered User
Join date: 4 Sep 2005
Posts: 5
Fruit Tree
06-27-2008 13:00
Great script, already have some ideas for it, and cant wait for the other parts, single fruit and take a slice.

i was wondering if it is possible to add a 3rd color to the fruits, so you could have one color for unripe (when growing), one color for ripe (before it drops) and one color for when it drops to the ground.

thank you for sharing.

edit: any way to get "ripe" fruit to stay on tree a bit before falling to ground? instead of instantly ripe and fall?
Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
06-28-2008 06:36
Hi Klear, I'm glad you're enjoying the script. If you want an open source example in-world let me know. My group already has access to it, but I will gladly send you a version to play with.

As for colors, there are actually three with this current script, one being the green when the object rezzes (predefined by the prim settings on rezz), and the red being ripe based on a certain size being reached during the growth cycle, and one being rotten, when the ripe fruit falls after being on the tree too long, and thats grey at the moment.

However you can add and remove conditions like these quite easily by playing with more or less if statements in this script version. Look for the next one I will post with more states to it as that will rezz different objects in different condition characteristics. Possibly that will be even easier for you to modify and use.
ZAT and ZEE within the script determines the timing for growth rates, so if you want the tree to hold its fruit for longer, just play with making these slightly longer, and change the factor of growth, look for the growth flag in the script - the lower this number is the longer the fruit take to grow as they only grow in size by this factor.


Best of luck with your creations. May farming and cultivation of greens become a HUGE industry through you and others :)
_____________________
Screwdrivers are so 90's...
Klear Moonlight
Registered User
Join date: 4 Sep 2005
Posts: 5
Fruit Tree
06-28-2008 11:12
Thank you, yes i am enjoying it.

I finally Got Colors how i like them, took me a bit. have to say this is a great script

i know this may be a bit much to add in, but what do you think of say... have as a choice of color and/or texture change at each stage? tho thinking about it that may be a bit much.
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
07-07-2008 13:36
From: Klear Moonlight
Thank you, yes i am enjoying it.

I finally Got Colors how i like them, took me a bit. have to say this is a great script

i know this may be a bit much to add in, but what do you think of say... have as a choice of color and/or texture change at each stage? tho thinking about it that may be a bit much.

you can add this line to each "growth" state before/after the primitive params line:

llSetTexture("texture uuid", ALL_SIDES);

or if it's a texture in the objects inventory (usefull if you're using a no-mod texture that's not your creation):

llSetTexture(llGetInventoryName(INVENTORY_TEXTURE, 0), ALL_SIDES);

just change the # in the inventory name call to the appropriate texture# of the object's inventory (ignoring all other inventory contents)
Klear Moonlight
Registered User
Join date: 4 Sep 2005
Posts: 5
07-08-2008 20:35
thank you Ruthven Willenov, just what i was looking to do, i will give that a try when i have a chance to.
Dumisani Ah
Pass me the hammer
Join date: 2 Dec 2006
Posts: 95
07-08-2008 23:51
From: Klear Moonlight
thank you Ruthven Willenov, just what i was looking to do, i will give that a try when i have a chance to.


Good call Ruthven.

Klear, you can also call a UUID instead of checking an object inventory for a texture, but here is some of the issues I had that you must take note of.

I tested several script options against one of my own sims in SL and used script time as my measure of the impact the scripted objects would have on the region or sim.

I initially created a plant object that started with a seed you place in the ground, and that then grows a single prim sculpted tree trunk over a period of time. Then using inspiration from the Builder's Buddy script (/54/2b/96792/1.html) in the library, I built it to first remember the position you wish the fruit pods to rezz at, and then after a bit of time to actually rezz the fruit pods in those fixed positions. Thereafter the fruit would grow as in the current script, but had shape changes to the fruit using a very simply sculpted texture change (if you're going to use sculptie textures preload them by hiding a cube in your design somewhere with the textures on each face like normal textures would be. It makes the changeover much smoother.).

Biggest impact by far was the use of LlSetLinkPrimitiveParams which I used to change several things including color and texture in the fruit and tree trunk options, especially when the scripts were checking the object inventories each time a changed state came up. Another big impact was the fruit going physical. Another serious impact were sensors as I had lots of interesting 'chat' commands at one stage including 'harvest' ;) what a mess, scary would be a better word here.

The result of all this experimentation was that I looked at my design and thought what can I sacrifice to give the best function and look versus sim impact, and the result was the script in the library. I did make that version available here on the scripting tips forum to allow experienced scripters time to suggest streamlining ideas, and then I submitted it to the library, so I think it currently offers a good foundation to encourage more change in the future. By the way I will resubmit the next version of the script soon to replace the current version in library, so any suggestions now help me smooth out the next one, and your experimentation makes a huge difference - thank you so much.

Final suggestion is to try and stop or minimise repeating inventory checks if you do decide to change the fruit's properties on the fly. I found Color changes to have the least impact, but again it may be due to my inexperience with LSL. I tended to end up with the best compromise, which was to design the fruit with its texture already set and only color and size changes made. Test all your work with more than one tree or plant as the impact becomes quite severe sometimes when you run two or three of these on one parcel ;)

O and one last change I did make to my current script was to replace the llSetText function with llWhisper so that residents standing close to the tree can follow what is happening by whispered comments from the script.
_____________________
Screwdrivers are so 90's...
Legacy Paine
Registered User
Join date: 30 Apr 2007
Posts: 6
12-15-2009 00:07
I've realy enjoyed playing with this script..but not sure if I'm just plain missing something and having a no brainer moment...

But I can't seem to get the fruit to grow on all axes, X, Y and Z...kinda hard having a flat apple, though it works well for other sculpts. Any ideas what I'm missing?
Ruthven Willenov
Darkness in your light
Join date: 16 Jan 2008
Posts: 965
12-15-2009 01:10
From: Legacy Paine
I've realy enjoyed playing with this script..but not sure if I'm just plain missing something and having a no brainer moment...

But I can't seem to get the fruit to grow on all axes, X, Y and Z...kinda hard having a flat apple, though it works well for other sculpts. Any ideas what I'm missing?

on this line in the Growth chunk of the script you simply need to add the growth amount to the y axis as well

CODE
llSetScale(< scale.x + growth,scale.y,scale.z + growth >); // Adds the amount it will grow to the X and Z axis.


becomes

CODE
llSetScale(< scale.x + growth,scale.y + growth,scale.z + growth >); // Adds the amount it will grow to the X and Z axis.
_____________________
Dark Heart Emporium

http://www.xstreetsl.com/modules.php?name=Marketplace&MerchantID=133020

want more layers for tattoos, specifically for the head? vote here
http://jira.secondlife.com/browse/VWR-1449?

llDetectedCollision* Functions similar to touch
http://jira.secondlife.com/browse/SVC-3369
Legacy Paine
Registered User
Join date: 30 Apr 2007
Posts: 6
12-15-2009 01:34
From: Ruthven Willenov

CODE
llSetScale(< scale.x + growth,scale.y + growth,scale.z + growth >); // Adds the amount it will grow to the X and Z axis.



Hmm, I've tried that, even rezed two together with the unchanged, and the modded..still no growth at all then with this change. Though the other chugs away blissfuly into a nice, flat, fat apple *chuckles* Might just be that it's 4am and I've been trying too much this eve.
Jo Manimbo
Registered User
Join date: 12 Feb 2009
Posts: 3
12-15-2009 07:08
From: Legacy Paine
Hmm, I've tried that, even rezed two together with the unchanged, and the modded..still no growth at all then with this change. Though the other chugs away blissfuly into a nice, flat, fat apple *chuckles* Might just be that it's 4am and I've been trying too much this eve.


Hi Legacy, I'm not sure why you have this problem except to check the axis of your prim in terms of it being a sculpty and often get imported weirdly. If you're using the library apple sculpt, I will be inworld in a moment and give it a try myself. There should be no problem with the growth code, but who knows. I've not played with this since leaving as Dumi way back when and have only very recently come back to SL. However, I will always check to see if any of my 'creations' are borked and see if we can get them fixed again. Since I'm working on some variations of the one you are playing with, I don't mind checking it out for you asap.