Jump to content

Perishable goods that age in inventory


Erwin Solo
 Share

You are about to reply to a thread that has been inactive for 1628 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

A friend wanted a script for perishable goods.  She's making flowers, milk, etc., food that requires cooking (mix of ingredients, etc.) for roleplay.  She wanted a script for which her products "age" and delete themselves, even if stored in inventory.  Additionally, she wants the 'lifetime' of the perishables to reset if give from one avatar to another.  Here is what I did for her.  

Some of you scripting black belts feel free to tell me what I could have consolidated or done better.  

// Erwin Solo 2019-05-23
// Autodelete script that remembers time spent in inventory.
// Uses Unix Clock, which will fail on 19-January-2038 for 32 bit integers.  
// See https://en.wikipedia.org/wiki/Year_2038_problem.
// I could hack around the 19-January-2038 bug, but hope we'll have generally agreed to solution.

integer TimeToLive = 7200; // enter time you want inventory to live in seconds

float gTimer = 3600; // timer runs every hour for low script load.  Okay to set lower for testing.

// enter UUID of person who you want to be immune from the timeouts
// Must be in quotes.  Example, "62d718f6-e00b-49ca-b434-338f712fd03a" for Erwin Solo
key SpecialPerson = "62d718f6-e00b-49ca-b434-338f712fd03a"; 

// ========================================
// Don't change anything below here
// ========================================


key Owner = NULL_KEY; // Owner determined by script at initialization

integer BirthTime = 0; // to be calculated at initialization

integer DieTime =0; // to be calculated at runtime

integer CurrentTime =0; // to be calculated at runtime


default
{
    state_entry()
    {
        Owner = llGetOwner(); 
        llSetTimerEvent (gTimer);
        BirthTime = llGetUnixTime(); 
        DieTime = BirthTime + TimeToLive; // Time object should die
    }

    on_rez( integer start_param )
    { 
        if (Owner != llGetOwner()) // if owner has changed, reset script to re-establish BirthTime and DieTime
        {
            llResetScript();
        }
        llSetTimerEvent (gTimer);
        if ( Owner != SpecialPerson ) // if owner is not the special person
        {
            CurrentTime = llGetUnixTime(); 
            
            if ( CurrentTime > DieTime ) 
            {
                llDie(); // object deletes itself
            }
        }

    }
    

    timer()
    {
        if ( Owner != SpecialPerson ) // if owner is not the special person
        {
            CurrentTime = llGetUnixTime(); 
            
            if ( CurrentTime > DieTime ) 
            {
                llDie(); // object deletes itself
            }
        }
    }
}
 

 

Edited by Erwin Solo
fixed spelling
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

2 hours ago, Wandering Soulstar said:

@Erwin Solo If the items being given are no mod, I'd store the initial Die Time in the Object description .. as things stand, the owner of the object just needs to reset the script themselves to avoid the object dying on them. If the object is modifiable  .. then you could consider using PRIM_TEXT for the same .

Oh, like duh!  You're right.  I'm glad I posted this. 

  • Like 2
Link to comment
Share on other sites

Alternatively, since the only "legit" reason state_entry would fire is when YOU (the scripter) compiled/reseted the script, you could trap state_entry in the event that the current owner isn't you.

Edited by Kyrah Abattoir
  • Like 2
Link to comment
Share on other sites

50 minutes ago, Kyrah Abattoir said:

Alternatively, since the only "legit" reason state_entry would fire is when YOU (the scripter) compiled/reseted the script, you could trap state_entry in the event that the current owner isn't you.

Aye. The object has to be no-mod, else the user can simply remove the script from the object. If the object is no-mod, the user can't reset the script.  The aspect of the conversation that has been very helpful to me is to know that I need to remind my customer that they have to make the objects no-mod.  

That being said, I like the idea of testing for "key SpecialPerson = <UUID>;" in the state_entry().  I believe that the no-reset of no-mod objects is enforced by the Region Server and not merely by the Third-Party Viewer Policy https://secondlife.com/corporate/tpv.php#priv2 so that even illicit/non-conforming Third Party Viewers can't circumvent.  

Correct me if I'm wrong, please. 

  • Like 1
Link to comment
Share on other sites

Okay, well this got moved from the script library to here, because we talked about it so much.  I ended up not changing anything.  It is really simple.  I guess if anyone needs it, they can find it here.

  • Like 1
  • Thanks 1
Link to comment
Share on other sites

@Erwin Solo

most probably the script got moved here because you requested comments and thoughts on it

if you are now happy with the script, I think it would now be ok to repost the script in the Library with out any further commentary other than a textual description about what it is intended for

Edited by Mollymews
intended
  • Thanks 1
Link to comment
Share on other sites

Yeah, but its not a good use of time.  I spent a few hours this week in the scripting forums and got nothing, whereas I got a six pack (and growing) of likes for a post that took me 5 minutes over in: 

 

  • Like 1
Link to comment
Share on other sites

18 minutes ago, Erwin Solo said:

Yeah, but its not a good use of time.  I spent a few hours this week in the scripting forums and got nothing, whereas I got a six pack (and growing) of likes for a post that took me 5 minutes over in: 

Solution: Don't post just for the imaginary internet points. Many people will read your post, like and agree with it, but not click the little button.

Just post because you enjoy it. 🙂

Edited by Wulfie Reanimator
  • Like 3
Link to comment
Share on other sites

  • 5 months later...
On 5/29/2019 at 12:38 AM, Mollymews said:

@Erwin Solo

most probably the script got moved here because you requested comments and thoughts on it

if you are now happy with the script, I think it would now be ok to repost the script in the Library with out any further commentary other than a textual description about what it is intended for

That worked!  

Thanks to all for the incredibly insightful comments. 

  • Like 1
Link to comment
Share on other sites

On 5/25/2019 at 2:58 AM, Erwin Solo said:

Aye. The object has to be no-mod, else the user can simply remove the script from the object. If the object is no-mod, the user can't reset the script.  The aspect of the conversation that has been very helpful to me is to know that I need to remind my customer that they have to make the objects no-mod.  

That being said, I like the idea of testing for "key SpecialPerson = <UUID>;" in the state_entry().  I believe that the no-reset of no-mod objects is enforced by the Region Server and not merely by the Third-Party Viewer Policy https://secondlife.com/corporate/tpv.php#priv2 so that even illicit/non-conforming Third Party Viewers can't circumvent.  

Correct me if I'm wrong, please. 

Yeah but with a trapped state entry a nomod object isn't strictly necessary.

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 1628 days.

Please take a moment to consider if this thread is worth bumping.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
 Share

×
×
  • Create New...