Page 1 of 1

Randomly Rez Vegtable with Lifespan

Posted: Tue Apr 26, 2022 12:48 pm
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!

Re: Randomly Rez Vegtable with Lifespan

Posted: Thu Apr 28, 2022 12:28 pm
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);
        }
    }
}

Re: Randomly Rez Vegtable with Lifespan

Posted: Thu Apr 28, 2022 8:55 pm
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!