User:Toady Nakamura/Hold Teddy Script

From Second Life Wiki
< User:Toady Nakamura
Revision as of 21:26, 5 August 2012 by Toady Nakamura (talk | contribs) (added state_entry & discussion of why needed !!)
Jump to navigation Jump to search

This script is useful for things like holding teddybears or sandwiches.

  • You need an animation to put in the same prim. Here I named the animation "Hold"
  • You have to change the animation name to the animation you include in the prim with the script.

<lsl>

string anim ="Hold"; // change this name to match the animation which is in the prim !

default {

   state_entry()
   {
       llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION); 
       // ask the owner for permission to trigger animations
       llStartAnimation(anim); // automatically trigger animation.
   }


   attach(key wearer)
   {
   if(wearer == NULL_KEY)
       {
         llStopAnimation(anim);
         llSetTimerEvent(0);
       }
       else
       {
        llRequestPermissions(wearer,PERMISSION_TRIGGER_ANIMATION);
       }
   }
   run_time_permissions(integer permissions)
   {
       if (PERMISSION_TRIGGER_ANIMATION & permissions)
       {
       llStartAnimation(anim);
       llSetTimerEvent(15);
       }
   }
  timer()
  {
       llStartAnimation(anim);
  }    

}

</lsl>

Credits & History

  • Script originally from a class by Minx Mousehold, modified by Toady Nakamura
    • Modded again 08/06/12 to add state_entry after getting massive script errors - but only when worn by tinies!!

Big Scary Script Error

Here's the script error that you get if you don't have that state entry in the script & you're tiny

  • Script trying to stop animations but PERMISSION_TRIGGER_ANIMATION permission not set

Because ... although the PERMISSION_TRIGGER_ANIMATION permission is automatically granted when sitting, a prior call to llRequestPermissions is required! (Thank you wiki_wakka!)