Jump to content
Sign in to follow this  
Erwin Solo

Roleplay script for perishable goods

Recommended Posts

A friend wanted a roleplay 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.  

// 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
            }
        }
    }
}
 

  • Like 2

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...