Difference between revisions of "Drink script"

From Second Life Wiki
Jump to navigation Jump to search
(Make script handle an owner change gracefully)
Line 4: Line 4:


=== Okay, okay, let's get this script, then ===
=== Okay, okay, let's get this script, then ===
'''Note: This script does not handle change of owner.'''
<lsl>//Emmas Seetan
<lsl>//Emmas Seetan
//1st November 2008
//1st November 2008
Line 38: Line 35:
     attach(key id)
     attach(key id)
     {
     {
         if(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
         if(id == NULL_KEY)
             llStopAnimation("hold_R_handgun"); //stops when detached
        {
            // we've been detached
            if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation("hold_R_handgun"); // stop if we have permission
        }
    }
 
    changed(integer change)
    {
        if (change & CHANGED_OWNER)
        {
             if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
                llStopAnimation("hold_R_handgun"); // stop if we have permission
            llResetScript(); // re-initialize with new owner
        }
     }
     }



Revision as of 10:06, 15 May 2009

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

<lsl>//Emmas Seetan //1st November 2008 //21:59

integer flag = 0;


default {

   state_entry()
   {
       llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); //asks the owner's permission
   }
   run_time_permissions(integer parm)
   {
       if(parm & PERMISSION_TRIGGER_ANIMATION) //triggers animation
       {
           llSetTimerEvent(15); //how often it happens
           llStartAnimation("hold_R_handgun"); //animation to play
       }
   }
   on_rez(integer st)
   {
       llResetScript();
   }
   attach(key id)
   {
       if(id == NULL_KEY)
       {
           // we've been detached
           if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
               llStopAnimation("hold_R_handgun"); // stop if we have permission
       }
   }
   changed(integer change)
   {
       if (change & CHANGED_OWNER)
       {
           if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
               llStopAnimation("hold_R_handgun"); // stop if we have permission
           llResetScript(); // re-initialize with new owner
       }
   }
   timer()
   {
       if(flag & 1)
       {
           llStartAnimation("drink"); //starts animation
       }
       flag = (flag + 1) % 4;
   }

}</lsl>