Difference between revisions of "Drink script"

From Second Life Wiki
Jump to navigation Jump to search
(Make script handle an owner change gracefully)
m (<lsl> tag to <source>)
 
(One intermediate revision by one other user not shown)
Line 4: Line 4:


=== Okay, okay, let's get this script, then ===
=== Okay, okay, let's get this script, then ===
<lsl>//Emmas Seetan
<source lang="lsl2">
//1st November 2008
//Emmas Seetan
//21:59
 
integer flag = 0;


string animationToBePlayed = "drinking animation";
integer flag;


default
default
{
{
     state_entry()
     on_rez(integer start_param)
     {
     {
         llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); //asks the owner's permission
         llResetScript();
     }
     }


     run_time_permissions(integer parm)
     attach(key id)
     {
     {
         if(parm & PERMISSION_TRIGGER_ANIMATION) //triggers animation
    //  when being detached
         if(id == NULL_KEY)
         {
         {
             llSetTimerEvent(15); //how often it happens
             integer currentPerms = llGetPermissions();


             llStartAnimation("hold_R_handgun"); //animation to play
             if (currentPerms & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation(animationToBePlayed);
         }
         }
     }
     }


     on_rez(integer st)
     changed(integer change)
     {
     {
         llResetScript();
         if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
        {
        //  stop animation for old owner
            integer currentPerms = llGetPermissions();
 
            if (currentPerms & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation(animationToBePlayed);
 
        //  reset script to get new owner
            llResetScript();
        }
     }
     }


     attach(key id)
     state_entry()
     {
     {
         if(id == NULL_KEY)
         key owner = llGetOwner();
         {
         llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
            // we've been detached
            if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation("hold_R_handgun"); // stop if we have permission
        }
     }
     }


     changed(integer change)
     run_time_permissions(integer perm)
     {
     {
         if (change & CHANGED_OWNER)
         if(perm & PERMISSION_TRIGGER_ANIMATION)
         {
         {
             if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
             llStartAnimation(animationToBePlayed);
                llStopAnimation("hold_R_handgun"); // stop if we have permission
 
             llResetScript(); // re-initialize with new owner
             llSetTimerEvent(15.0);
         }
         }
     }
     }
Line 56: Line 63:
     {
     {
         if(flag & 1)
         if(flag & 1)
        {
             llStartAnimation(animationToBePlayed);
             llStartAnimation("drink"); //starts animation
        }


         flag = (flag + 1) % 4;
         flag = (flag + 1) % 4;
     }
     }
}</lsl>
}
</source>

Latest revision as of 19:06, 24 January 2015

A what?

A drink script, used in many parts of Second Life. Whether it's for food or drink, or roleplay potions and what-not, a drink script is always included. If it's not, it's rubbish.

Okay, okay, let's get this script, then

//Emmas Seetan

string animationToBePlayed = "drinking animation";
integer flag;

default
{
    on_rez(integer start_param)
    {
        llResetScript();
    }

    attach(key id)
    {
    //  when being detached
        if(id == NULL_KEY)
        {
            integer currentPerms = llGetPermissions();

            if (currentPerms & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation(animationToBePlayed);
        }
    }

    changed(integer change)
    {
        if (change & (CHANGED_OWNER | CHANGED_INVENTORY))
        {
        //  stop animation for old owner
            integer currentPerms = llGetPermissions();

            if (currentPerms & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation(animationToBePlayed);

        //  reset script to get new owner
            llResetScript();
        }
    }

    state_entry()
    {
        key owner = llGetOwner();
        llRequestPermissions(owner, PERMISSION_TRIGGER_ANIMATION);
    }

    run_time_permissions(integer perm)
    {
        if(perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStartAnimation(animationToBePlayed);

            llSetTimerEvent(15.0);
        }
    }

    timer()
    {
        if(flag & 1)
            llStartAnimation(animationToBePlayed);

        flag = (flag + 1) % 4;
    }
}