Randomly Rez Vegtable with Lifespan

Creating scripts
Post Reply
User avatar
Lunk Portal
Posts: 150
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 100 times
Been thanked: 151 times
Contact:

Randomly Rez Vegtable with Lifespan

Post by Lunk Portal »

Hey everyone, I've been looking for a script that will randomly rez an object within 0.5m of parent-prim, but only allow 1 to 5 objects before "killing" them off.

I'm making a garden and I need them to produce. Later I will work on scripts for RP that will allow them to replenish health, but for now just the basic grow and die script.

If anyone has something that would be great.

Thanks!
These users thanked the author Lunk Portal for the post (total 2):
Ilan TochnerGenavieve Page
Graham Mills
Posts: 1314
Joined: Sun Dec 23, 2012 2:26 pm
Has thanked: 1134 times
Been thanked: 1142 times

Re: Randomly Rez Vegtable with Lifespan

Post by Graham Mills »

Dunno if this helps. Put unscripted object "veg" in semi-transparent prim, add the script below and touch to start.

It runs a sensor event at 10 sec intervals (adjust ad lib), adds a veg if there are less than 5 and removes the nearest if there are 5 already.

NB Uses osDie which is allowed for the World Manager and Estate Managers. No attempt to manage world restarts etc.

Code: Select all

default
{
    touch_start(integer n)
    {
       llSensorRepeat("veg", NULL_KEY, PASSIVE, 0.5, PI, 10.0);//default is 10.0 sec sensing interval
    }
    
    no_sensor()
    {
        vector pos;
        pos = llGetPos();
        vector rpos;
        do
        {
            rpos = <pos.x -0.25 + llFrand(0.5), pos.y -0.25 + llFrand(0.5), pos.z>;
        }
        while (llVecDist(pos, rpos) > 0.5);
        llRezObject("veg", rpos, ZERO_VECTOR, ZERO_ROTATION, 0);
    }
        
    
    sensor(integer n)
    {
        if (n > 4) //kill
        {
            do
            {
                osDie(llDetectedKey(0));
                n = n - 1;
            }
            while (n > 4);
        }
        else //spawn
        {
            vector pos;
            pos = llGetPos();
            vector rpos;
            do
            {
                rpos = <pos.x -0.25 + llFrand(0.5), pos.y -0.25 + llFrand(0.5), pos.z>;
            }
            while (llVecDist(pos, rpos) > 0.5);
            llRezObject("veg",  rpos, ZERO_VECTOR, ZERO_ROTATION, 0);
        }
    }
}
These users thanked the author Graham Mills for the post (total 3):
Ilan TochnerLunk PortalGenavieve Page
User avatar
Lunk Portal
Posts: 150
Joined: Wed Jan 26, 2022 10:03 am
Location: Northern Michigan
Has thanked: 100 times
Been thanked: 151 times
Contact:

Re: Randomly Rez Vegtable with Lifespan

Post by Lunk Portal »

Graham Mills wrote:
Thu Apr 28, 2022 12:28 pm
Dunno if this helps. Put unscripted object "veg" in semi-transparent prim, add the script below and touch to start.

It runs a sensor event at 10 sec intervals (adjust ad lib), adds a veg if there are less than 5 and removes the nearest if there are 5 already.

NB Uses osDie which is allowed for the World Manager and Estate Managers. No attempt to manage world restarts etc.

Code: Select all

default
{
    touch_start(integer n)
    {
       llSensorRepeat("veg", NULL_KEY, PASSIVE, 0.5, PI, 10.0);//default is 10.0 sec sensing interval
    }
    
    no_sensor()
    {
        vector pos;
        pos = llGetPos();
        vector rpos;
        do
        {
            rpos = <pos.x -0.25 + llFrand(0.5), pos.y -0.25 + llFrand(0.5), pos.z>;
        }
        while (llVecDist(pos, rpos) > 0.5);
        llRezObject("veg", rpos, ZERO_VECTOR, ZERO_ROTATION, 0);
    }
        
    
    sensor(integer n)
    {
        if (n > 4) //kill
        {
            do
            {
                osDie(llDetectedKey(0));
                n = n - 1;
            }
            while (n > 4);
        }
        else //spawn
        {
            vector pos;
            pos = llGetPos();
            vector rpos;
            do
            {
                rpos = <pos.x -0.25 + llFrand(0.5), pos.y -0.25 + llFrand(0.5), pos.z>;
            }
            while (llVecDist(pos, rpos) > 0.5);
            llRezObject("veg",  rpos, ZERO_VECTOR, ZERO_ROTATION, 0);
        }
    }
}
Thank you! I will check this out and let you know. My work has been piling up lately and I was just elected VP for the area ministerial association, so I got 100% busier as of late LOL... I still plan on having the BETA TatooineRP up by May 1st, but I have not set a time frame or schedule for "fleshing" out the server. One way or another, I believe this script will work though, thank you!
These users thanked the author Lunk Portal for the post:
Graham Mills
Post Reply