Advertisement
salahzar

script poseball

Dec 14th, 2013
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //  Sit Pose Ball
  2. //  Created by Water Rogers for IBM/Opensource
  3.  
  4. //  Purpose
  5. //  --------------------------------------------------------------
  6. //  Pose Balls are popular for many applications, most noteable are
  7. //  furniture.  This script will show you the basics of how to set
  8. //  up a pose ball ready object.
  9.  
  10. //  Requirements
  11. //  --------------------------------------------------------------
  12. //  A single prim is all that is necessary for this example.
  13.  
  14. //  Usage
  15. //  --------------------------------------------------------------
  16. //  We set up this particular object with "When Left Clicked: Sit on
  17. //  Object" to make it easier on other users.  Otherwise, you could
  18. //  always right click and from the pie menu choose "Sit".
  19.  
  20. //  GLOBALS
  21. //  --------------------------------------------------------------
  22. string      g_SitText       ; //  The text to replace "sit" in the pie menu
  23. string      g_Animation;     //  The animation we use (note that this is a default animation)
  24. vector      g_SitOffset     = <0.00, 0.00, 0.001>;  //  The sit offset can't be ZERO_VECTOR
  25. key         g_LastAvatar    = NULL_KEY; //  Stores the last avatar to sit on the object
  26.  
  27. //  EVENTS
  28. //  --------------------------------------------------------------
  29. stopAnimations()
  30. {
  31.         list l=llGetAnimationList(g_LastAvatar);
  32.         integer i;
  33.         for(i=0;i<llGetListLength(l);i++){
  34.            // llSay(0,"stopping "+llList2String(l,i));
  35.             llStopAnimation(llList2String(l,i));
  36.         }
  37. }    
  38.  
  39.  
  40. default
  41. {
  42.     state_entry()
  43.     {
  44.         //  First we set up the sit text in the pie menu, and determine
  45.         //  where the sit offset should be.
  46.         g_SitText = llGetObjectDesc();  
  47.         g_Animation=llGetInventoryName(INVENTORY_ANIMATION,0);
  48.         llSetSitText(g_SitText);
  49.         llSetAlpha(1,ALL_SIDES);
  50.         llSitTarget(g_SitOffset, ZERO_ROTATION);
  51.         llSetText(g_SitText,<1,1,1>,1);
  52.     }
  53.  
  54.     changed(integer change)
  55.     {
  56.         //  In the changed() event, we are looking for a change in the link
  57.         //  of the object.  When someone sits on an object, they actually
  58.         //  become a part or link of the object, which is why this event is
  59.         //  raised.  From here, we can determine who is sitting on the object
  60.         //  request permissions, animate the avatar, or stop any animations
  61.         //  if they are getting off the object.
  62.         key id = llAvatarOnSitTarget();
  63.         if(change & CHANGED_LINK)
  64.         {
  65.             if (id != NULL_KEY && g_LastAvatar == NULL_KEY)
  66.             {
  67.                 //  An avatar sat on the object.  Or a link was added to the
  68.                 //  object, to be more specific.
  69.                 g_LastAvatar = id;
  70.                
  71.                 //  Check and Request permissions from the avatar.
  72.                 if (!(llGetPermissions() & PERMISSION_TRIGGER_ANIMATION))
  73.                 {
  74.                     llRequestPermissions(id, PERMISSION_TRIGGER_ANIMATION);
  75.                 }
  76.                 llSetText("",<1,1,1>,1);
  77.                 llSetAlpha(0,ALL_SIDES);
  78.             }
  79.            
  80.             // Avatar is getting off the object.
  81.             if (id == NULL_KEY && g_LastAvatar != NULL_KEY)
  82.             {
  83.                 //  Make sure we have permissions to animate the avatar
  84.                 if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
  85.                 {
  86.                     //  Since we have permissions, we will stop whatever
  87.                     //  animations were applied to the avatar initialy
  88.                     llStopAnimation(g_Animation);
  89.                 }
  90.                
  91.                 // Reset the script to release any permissions
  92.                 llResetScript();
  93.             }
  94.         }
  95.     }
  96.      
  97.     run_time_permissions(integer perm)
  98.     {
  99.         if (!(perm & PERMISSION_TRIGGER_ANIMATION))
  100.         {
  101.             //  Since the avatar is sitting, animation permissions are automaticaly
  102.             //  applied.  But we still have to go through the logic in the script
  103.             //  to activate animations.
  104.             llInstantMessage(g_LastAvatar, "Permissions are Required.");
  105.             llUnSit(g_LastAvatar);
  106.         }
  107.        
  108.         //  Permissions were accepted, so we start the animation.  If you want
  109.         //  to use a custom animation, then the animation has to be located within
  110.         //  the inventory of the object, and spelled the exact way it looks.
  111.         //llSay(0,"starting animation "+g_Animation);
  112.         stopAnimations();
  113.         //llSay(0,"start "+g_Animation);
  114.         llStartAnimation(g_Animation);
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement