1 //originally written by Davide Byron
2 //this code is released under the GPLv3
4 // this script takes care of spawning tree fruits at random times, untill the branch dies.
5 // spawning of fruits is limited by the sim lag. If there is too much lag the fruits won't be spawned
6 // It's also possible to spawn a fruit upon user touch on the branch.
7 // in this case lag is not taken into account.
9 //dedicated to Mealea, thanks for the passion you put into things and for being able to pass it on to me :)
16 //how long between a spawning and the other
17 float FruitSpawningCycle
= 240.0;
19 float FruitSpawningCycleBias
= 45.0;
20 //max lag above which spawning is not permitted
21 float SpawningLagTreshold
= 0.95;
22 //two vars to keep track of sim lag
23 float AverageSimLagSum
= 0;
24 float AverageSimLagSamples
= 0;
29 //generates a random float number ranging from -range to range
30 float myRand( float range
)
32 float sign
= llFrand(2.1);
33 float random
= llFrand( range
+ 0.1 );
56 //delay the spawning of the fruit after the branch rezzing
57 //if the branch is eaten no fruit should be spawned
58 //(this should already work, but keep an eye on it...)
59 FRUIT_NAME
= llGetInventoryName(INVENTORY_OBJECT
, 0);
60 llSetTimerEvent( FruitSpawningCycle
+ myRand( FruitSpawningCycleBias
) );
61 AverageSimLagSum
= llGetRegionTimeDilation();
62 AverageSimLagSamples
= 1;
70 AverageSimLagSum
+= llGetRegionTimeDilation();
71 AverageSimLagSamples
+= 1;
72 //the only restrain is the lag of the sim
73 if( AverageSimLagSum
/AverageSimLagSamples
>= SpawningLagTreshold
74 && llGetRegionTimeDilation() >= SpawningLagTreshold
)
76 //if the lag is low, let's spawn the fruit
77 llRezObject(FRUIT_NAME
,llGetPos(),<0,0,0>,ZERO_ROTATION
,1);
83 touch_start(integer touched
)
85 //if a user touch the branch, spawn the fruit, its kinda gratifying...
86 llRezObject(FRUIT_NAME
,llGetPos(),<0,0,0>,ZERO_ROTATION
,1);