Advertisement
Gayngel

Play animations in list randomly/consecutively with sleeps

Jul 10th, 2023 (edited)
1,442
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // This script only works with non-looped animations that have a known uuid.
  2.  
  3. // Non-full perm animations will return NULL_KEY when checking with llGetInventoryKey in the inventory of an object and you can't copy the asset uuid from your own avatar inventory if the animation is not full perm.
  4.  
  5. //There is however a workaround...
  6.  
  7. // llGetAnimationsList will show uuids of all currently playing animations, even non full perm animations. By process of elimination you can match the uuid to the animation name.
  8.  
  9. // The easiest way to match the uuid is take off all items on your avatar that would play animations (AOs, etc) so you have as few animations playing as possible and then run llOwnerSay(llList2CSV(llGetAnimationsList())) in a timer while playing the animation you want to match. Then try match the uuid to the animation name.
  10.  
  11. // Once you have the correct uuids you can use the following script to play animations from a list randomly/consecutively without messing with sleeps:
  12.  
  13. string current_animation;
  14.  
  15. list animations = ["sipping sl","758547a2-7212-d533-43e3-1666eda1705e", "HX Pick Up Anim 1"," c9d0ef97-2c7b-4293-a197-f4f64e0eb5ec" ,"throw", "d292a068-1dd7-e97d-97c5-dab9dbc87775" ]; // these are example animations, replace with your own. Remember to add them to the contents of the object this script is in.
  16.  
  17. // add an animation name and it's uuid as a pair to the list. You can get the uuid by right clicking it in your inventory (your inventory, not the object's inventory) and selecting copy asset uuid.
  18.  
  19.  
  20. integer i;
  21.  
  22. integer len;
  23.  
  24. integer switch;
  25.  
  26. default
  27. {
  28.    
  29.    
  30.    touch_end(integer i)
  31.     {
  32.         switch = !switch;
  33.         if(switch) // switch on
  34.            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
  35.         else // switch off
  36.         {
  37.          llSetTimerEvent(0.0);  
  38.         llStopAnimation(current_animation);  
  39.         }
  40.     }
  41.  
  42.    run_time_permissions(integer perm) {
  43.         if(perm & PERMISSION_TRIGGER_ANIMATION)
  44.         {
  45.             len = llGetListLength(animations);
  46.             i = llRound(llFrand(len));
  47.             if(i == len) i = i-1; // in case i is out of bounds
  48.            
  49.            
  50.             // we need the name of the animation to play, not its uuid, so if frand lands on the uuid, just subtract 1 to get its name
  51.            
  52.             if(i % 2 == 1)  // if i is odd
  53.             i = i -1;
  54.            
  55.             current_animation = llList2String(animations,i);
  56.            
  57.             llStartAnimation(current_animation);
  58.            
  59.             llSetTimerEvent(1.0);
  60.            
  61.                  
  62.            
  63.            
  64.            
  65.         }
  66.     }
  67.    
  68.     timer()
  69.     {
  70.        
  71.          list playing = llGetAnimationList(llGetPermissionsKey());
  72.          
  73.          // since llGetAnimationList returns keys of currently playing animations we need to check if the uuid of the current_animation we are playing is in the list
  74.  
  75.      
  76.         // llOwnerSay(llList2CSV(playing));
  77.          integer idx = llListFindList(playing,[llList2Key(animations, i + 1)]);
  78.          
  79.          if(idx == -1) // if current_animation is not in the list play the next animation in the animations list
  80.          {
  81.            i = llRound(llFrand(len));
  82.          
  83.             if(i == len) i = i-1; // in case i is out of bounds
  84.            
  85.             if(i % 2 == 1)  // if i is odd
  86.             i = i -1;
  87.            
  88.             current_animation = llList2String(animations,i);
  89.            
  90.             llStartAnimation(current_animation);  
  91.              
  92.          }
  93.          
  94.          
  95.        
  96.     }
  97. }
  98.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement