Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. * Saya 2018
  3. *
  4. * Generic AO script for a tail
  5. *
  6. */
  7.  
  8. // All of the animation names go in their appropriate lists
  9. list standing = ["AvatarAction_StandingSet1","AvatarAction_StandingSet2","AvatarAction_StandingSet3"];
  10. list walking = ["AvatarAction_Walk1"];
  11. list sitting = ["AvatarAction_Crouch1","AvatarAction_Turn1","AvatarAction_Turn2"];
  12. list sitting_on_ground = ["AvatarAction_Crouch1","AvatarAction_Turn1","AvatarAction_Turn2"];
  13. list crouching = ["AvatarAction_Crouch1","AvatarAction_Turn1","AvatarAction_Turn2"];
  14. list crouch_walking = ["AvatarAction_Crouch1"];
  15. list landing = ["AvatarAction_Landing1"];
  16. list standing_up = ["AvatarAction_Landing1"];
  17. list falling = ["AvatarAction_Falling1"];
  18. list flying_down = ["AvatarAction_Falling1"];
  19. list flying_up = ["AvatarAction_FlyingUp1"];
  20. list flying = ["AvatarAction_StandingSet1"];
  21. list flying_slow = ["AvatarAction_StandingSet2"];
  22. list hovering = ["AvatarAction_WaterFloating1"];
  23. list jumping = ["AvatarAction_Landing1"];
  24. list pre_jumping = ["AvatarAction_Landing1"];
  25. list running =["AvatarAction_Running1"];
  26. list turning_right = ["AvatarAction_Turning1"];
  27. list turning_left = ["AvatarAction_Turning2"];
  28. list floating = ["AvatarAction_WaterFloating1"];
  29. list swimming_forward = ["AvatarAction_SwimingFoward1"];
  30. list swimming_up = ["AvatarAction_FlyingUp1"];
  31. list swimming_down = ["AvatarAction_Falling1"];
  32. list typing = [];
  33.  
  34.  
  35. // returns TRUE if agent in water, else FALSE
  36. integer agent_in_water()
  37. {
  38.     vector agent_pos = llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_POS]), 0);
  39.     float water_height = llWater(ZERO_VECTOR);
  40.     return (agent_pos.z < water_height); // returns TRUE if agent's position is below water level
  41.  
  42. }
  43.  
  44. string now_playing = ""; // currently playing animation, if any
  45.  
  46. // Start a random animation from a list of given animations
  47. // Must check permission to animate agent before calling!
  48. start_random_animation(list animations)
  49. {
  50.     string animation = llList2String(llListRandomize(animations, 1), 0); // choose a random animation from list of animations
  51.     llStartAnimation(animation); // star the animation
  52.     llSleep(0.1);
  53.     llStopAnimation(now_playing); // stop the old animation shortly afterwards (this is on purpose to prevent 'whitespace')
  54.     now_playing = animation;
  55. }
  56.  
  57. update_animations()
  58. {
  59.     integer permissions = llGetPermissions();
  60.     if (permissions & PERMISSION_TRIGGER_ANIMATION)
  61.     {
  62.         // have permission to animate
  63.         integer agent_info = llGetAgentInfo(llGetOwner());
  64.         if (agent_info & AGENT_CROUCHING)
  65.         {
  66.             // crouching, could be moving
  67.             float velocity = llVecMag(llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_VELOCITY]),0));
  68.             if (velocity < 1)
  69.             {
  70.                 // not moving
  71.                 start_random_animation(crouching);
  72.             }
  73.             else
  74.             {
  75.                 start_random_animation(crouch_walking);
  76.             }
  77.  
  78.         }
  79.         if (agent_info & AGENT_WALKING)
  80.         {
  81.             // walking or running
  82.             float velocity = llVecMag(llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_VELOCITY]),0));
  83.             if (velocity < 4)
  84.             {
  85.                 // walking
  86.                 start_random_animation(walking);
  87.                 return;
  88.             }
  89.             else
  90.             {
  91.                 // running
  92.                 start_random_animation(running);
  93.                 return;
  94.             }
  95.         }
  96.         if (agent_info & AGENT_SITTING)
  97.         {
  98.             if (agent_info & AGENT_ON_OBJECT)
  99.             {
  100.                 start_random_animation(sitting);
  101.                 return;
  102.             }
  103.             else
  104.             {
  105.                 // sitting on ground
  106.                 start_random_animation(sitting_on_ground);
  107.                 return;
  108.             }
  109.         }
  110.         if (agent_info & AGENT_IN_AIR)
  111.         {
  112.             // in the air or water
  113.  
  114.             vector velocity = llList2Vector(llGetObjectDetails(llGetOwner(), [OBJECT_VELOCITY]),0);
  115.             float speed = llVecMag(velocity);
  116.             if (agent_info & AGENT_FLYING)
  117.             {
  118.                 if (speed < 0.25)
  119.                 {
  120.                     // hovering or floating
  121.                     if (!agent_in_water())
  122.                     {
  123.                         start_random_animation(hovering);
  124.                         return;
  125.                     } else
  126.                     {
  127.                         start_random_animation(floating);
  128.                         return;
  129.                     }
  130.                 }
  131.                 else
  132.                 {
  133.                     // moving in some form
  134.                     if (llFabs(velocity.z) < 1)
  135.                     {
  136.                         // more or less flying/swimming at the same height
  137.                         if (agent_in_water())
  138.                         {
  139.                             start_random_animation(swimming_forward);
  140.                             return;
  141.                         }
  142.                         else
  143.                         {
  144.                             start_random_animation(flying);
  145.                             return;
  146.                         }
  147.                     }
  148.                     else
  149.                     {
  150.                         if (velocity.z < 5)
  151.                         {
  152.                             // probably falling
  153.                             start_random_animation(falling);
  154.                             return;
  155.                         }
  156.                         // either going upwards or downwards
  157.                         if (velocity.z > 0)
  158.                         {
  159.                             // upwards
  160.                             if (agent_in_water())
  161.                             {
  162.                                 start_random_animation(swimming_up);
  163.                                 return;
  164.                             }
  165.                             else
  166.                             {
  167.                                 start_random_animation(flying_up);
  168.                                 return;
  169.                             }
  170.                         }
  171.                         else
  172.                         {
  173.                             // downwards
  174.                             if (agent_in_water())
  175.                             {
  176.                                 start_random_animation(swimming_down);
  177.                                 return;
  178.                             }
  179.                             else
  180.                             {
  181.                                 start_random_animation(flying_down);
  182.                                 return;
  183.                             }
  184.                         }
  185.                     }
  186.  
  187.                 }
  188.             }
  189.             else
  190.             {
  191.                 // agent jumping
  192.                 start_random_animation(jumping);
  193.             }
  194.         }
  195.  
  196.         // if we got this far, we're probably just standing
  197.         start_random_animation(standing);
  198.  
  199.  
  200.     }
  201.     else
  202.     {
  203.         // no permission to animate, request it, if we're attached
  204.         if (llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS| PERMISSION_TRIGGER_ANIMATION | PERMISSION_OVERRIDE_ANIMATIONS);
  205.     }
  206.    
  207.  
  208. }
  209.  
  210. default
  211. {
  212.  
  213.     state_entry()
  214.     {
  215.         llSetTimerEvent(10); // Every 10 seconds, update the AO. Every 2 seconds, check if the agent moved into or out of water
  216.         if (llGetAttached()) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS| PERMISSION_TRIGGER_ANIMATION | PERMISSION_OVERRIDE_ANIMATIONS);
  217.     }
  218.  
  219.     attach(key id)
  220.     {
  221.         if (id) llRequestPermissions(llGetOwner(), PERMISSION_TAKE_CONTROLS| PERMISSION_TRIGGER_ANIMATION | PERMISSION_OVERRIDE_ANIMATIONS);
  222.     }
  223.  
  224.     // // fires every 10seconds and updates the animation override for the agent
  225.     // timer()
  226.     // {
  227.     //     if (!llGetAttached()) return; // don't do anything when not attached
  228.        
  229.     //     /*
  230.     //     *
  231.     //     * The following logic is disused because we're aiming for firestorm ao compatibility
  232.     //     * It could be reintroduced when, Firestorm supports multi-AO's
  233.     //     */
  234.     //     // if (llGetPermissions() & PERMISSION_OVERRIDE_ANIMATIONS)
  235.     //     // {
  236.  
  237.     //     //     // every couple of seconds, check if the avatar has moved into or out of water
  238.     //     //     if (agent_in_water() != in_water)
  239.     //     //     {
  240.     //     //         // agent moved into, or out of water, update AO's immediately (we 'trick' the logic into thinking 10 seconds has passed)
  241.     //     //         in_water = agent_in_water();
  242.     //     //         ticks = 10;
  243.     //     //     }
  244.  
  245.     //     //     ticks = ticks + 2;
  246.     //     //     if (ticks < 10) return; // don't do the following if 10 seconds hasn't passed
  247.     //     //     ticks = 0;
  248.     //     //     // if we got this far, 10 seconds has passed OR the agent just moved into or out of water
  249.  
  250.     //     //     llSetAnimationOverride("Crouching", random_animation(crouching));
  251.     //     //     llSetAnimationOverride("CrouchWalking", random_animation(crouch_walking));
  252.     //     //     llSetAnimationOverride("Falling Down", random_animation(falling));
  253.            
  254.            
  255.            
  256.     //     //     llSetAnimationOverride("Jumping", random_animation(jumping));
  257.     //     //     llSetAnimationOverride("Landing", random_animation(landing));
  258.     //     //     llSetAnimationOverride("PreJumping", random_animation(pre_jumping));
  259.     //     //     llSetAnimationOverride("Running", random_animation(running));
  260.     //     //     llSetAnimationOverride("Sitting", random_animation(sitting));
  261.     //     //     llSetAnimationOverride("Sitting on Ground", random_animation(sitting_on_ground));
  262.     //     //     llSetAnimationOverride("Standing", random_animation(standing));
  263.     //     //     llSetAnimationOverride("Standing Up", random_animation(standing_up));
  264.     //     //     llSetAnimationOverride("Striding", random_animation(standing));
  265.     //     //     llSetAnimationOverride("Soft Landing", random_animation(landing));
  266.     //     //     llSetAnimationOverride("Taking Off", random_animation(flying_up));
  267.     //     //     llSetAnimationOverride("Turning Left", random_animation(turning_left));
  268.     //     //     llSetAnimationOverride("Turning Right", random_animation(turning_right));
  269.     //     //     llSetAnimationOverride("Walking" , random_animation(walking));
  270.  
  271.     //     //     if (!agent_in_water())
  272.     //     //     {
  273.     //     //         // above water level
  274.     //     //         llSetAnimationOverride("Hovering", random_animation(hovering));
  275.     //     //         llSetAnimationOverride("Hovering Down", random_animation(flying_down));
  276.     //     //         llSetAnimationOverride("Hovering Up", random_animation(flying_up));
  277.     //     //         llSetAnimationOverride("Flying", random_animation(flying));
  278.     //     //         llSetAnimationOverride("FlyingSlow", random_animation(flying_slow));
  279.     //     //     }
  280.     //     //     else
  281.     //     //     {
  282.     //     //         // below water level
  283.     //     //         llSetAnimationOverride("Hovering", random_animation(floating));
  284.     //     //         llSetAnimationOverride("Hovering Down", random_animation(swimming_down));
  285.     //     //         llSetAnimationOverride("Hovering Up", random_animation(swimming_up));
  286.     //     //         llSetAnimationOverride("Flying", random_animation(swimming_forward));
  287.     //     //         llSetAnimationOverride("FlyingSlow", random_animation(swimming_forward));
  288.     //     //     }
  289.     //     // }
  290.     //     // else
  291.     //     // {
  292.     //     //     // no permission to override animations, request it
  293.     //     //     llSetTimerEvent(FALSE);
  294.     //     //     llRequestPermissions(llGetOwner(), PERMISSION_OVERRIDE_ANIMATIONS);
  295.     //     // }
  296.     //   }
  297.  
  298.       run_time_permissions(integer perm)
  299.       {
  300.           if (perm & PERMISSION_TAKE_CONTROLS)
  301.           {
  302.               llTakeControls(
  303.                             CONTROL_FWD |
  304.                             CONTROL_BACK |
  305.                             CONTROL_LEFT |
  306.                             CONTROL_RIGHT |
  307.                             CONTROL_ROT_LEFT |
  308.                             CONTROL_ROT_RIGHT |
  309.                             CONTROL_UP |
  310.                             CONTROL_DOWN |
  311.                             CONTROL_LBUTTON |
  312.                             CONTROL_ML_LBUTTON |
  313.                             0, TRUE, TRUE); // all control events are generated, but the control is not intercepted
  314.               // We react ONLY to the user starting or stopping pressing something, to provide snappy animation reactions
  315.               // we don't react to holding the control to avoid animation start spam
  316.  
  317.           }
  318.           if (perm & PERMISSION_OVERRIDE_ANIMATIONS)
  319.           {
  320.             llSetAnimationOverride("Turning Left", llList2String(turning_left, 0));
  321.             llSetAnimationOverride("Turning Right", llList2String(turning_right, 0));
  322.           }
  323.       }
  324.  
  325.       control(key id, integer level, integer edge)
  326.       {
  327.           if (edge == 0) return; // don't do anything if this event is not related to the moment a control is pressed or released
  328.           llSetTimerEvent(0.1); // slight delay to ensure correct response
  329.           update_animations(); // quickly respond to input
  330.          
  331.       }
  332.  
  333.       timer()
  334.       {
  335.           // every 10s, update animations
  336.           update_animations();
  337.       }
  338. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement