Drink script

From Second Life Wiki
Revision as of 11:06, 15 May 2009 by Sheridan Otoole (talk | contribs) (Make script handle an owner change gracefully)
Jump to navigation Jump to search

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>