CODE
//Growth Script
//By Floog Stuart
//Some parts of the script taken from Cid Jacob's Photosynthesis Script.
//
//Makes a prim grow on it's Z axis when the sun is out. Starts growth when touched.
//If you edit this script please give credit to Me and Cid Jacob
vector direction; //States the variables used in the script
vector scale;
float growth;
vector pos;
float repos;
default
{
state_entry()
{
llSetText("",<1,1,1>,1); //Clears Text above prim.
}
touch_start(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 = llFrand(.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 plant.
llSetScale(<scale.x,scale.y,scale.z + growth>); // Adds the amount it needs to grow to the Z axis.
//Growth Percentage
float growth_percent = scale.z / .100; //Finds the percentage it is to it's max height.
llSetText("Growth " + (string)growth_percent + "%",<1,1,1>,1.0); //Adds the Growth Percentage above the prim.
}
if(scale == <scale.x, scale.y, 10.00000>) //Checks if the prim is max height.
{
llSetText("Full Grown",<1,1,1>,1); //Says that the prim is full grown.
state fullgrown; //Goes to state fullgrown
}
//Reposition
pos = llGetPos(); // Gets current position
repos = growth / 2; //Sets the amount to reposition to half that of which it grew. To avoid the prim from sinking into the ground.
if ( direction.z > 0 )// Makes sure that it is still daytime
{
llSetPos(<pos.x,pos.y,pos.z + repos>);//Sets the new position.
}
}
}
state fullgrown //state fullgrown is used to keep the prim from repositioning when it doesnt need to anymore.
{
state_entry()
{
llSetText("Full Grown",<1,1,1>,1);
}
}