list llGetAnimationList(key id)
Returns a list of keys of all playing animations for avatar id.
llStopAnimation or llStartAnimation may be useful here.
// stops all currently running animations when clicked
default {
touch_start(integer num_detected) {
llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);
}
run_time_permissions(integer perm) {
if(perm & PERMISSION_TRIGGER_ANIMATION)
{
list anims = llGetAnimationList(llGetPermissionsKey()); // get list of animations
integer len = llGetListLength(anims);
integer i;
llSay(0, "Stopping " + (string)len + llGetSubString(" animations",0,-1 - (len == 1)));//strip the "s" when there is only 1 to stop.
for (i = 0; i < len; ++i) llStopAnimation(llList2Key(anims, i));
llSay(0, "Done");
}
}
}
Another Example:
// gets the key of an animation as it starts it
// -sendao
key startAnim_FindKey( key who, string animname )
{
if( llGetPermissions() & PERMISSION_TRIGGER_ANIMATION ) {
list prelist = llGetAnimationList( who );
llStartAnimation(animname);
list postlist = llGetAnimationList( who );
integer i;
integer len = llGetListLength(prelist);
prelist = llListSort( prelist, 1, 1 );
postlist = llListSort( postlist, 1, 1 );
for( i = 0; i < len; i++ ) {
if( llList2Key( prelist, i ) != llList2Key( postlist, i ) ) return llList2Key(postlist, i);
}
if( i <= llGetListLength(postlist) ) return llList2Key( postlist, i );
}
return NULL_KEY;
}
A more efficient non-brain damaged replacement for llStartAnimation() by Edward Vellhi:
// that this replacement is needed is extremely lame.
// llStartAnimation() should return the key since it can
// obviously be derived anyway and thus not returning
// it provides NO ADDITIONAL SECURITY and is one big
// needless PITA since the key must be known to allow
// seamless streaming of non-repeating animations. morons.
//
key startAnimation(key avatar, string animation)
{
list preKeys = llGetAnimationList(avatar);
llStartAnimation(animation);
list postKeys = llGetAnimationList(avatar);
integer index;
while (llListFindList(preKeys, [llList2Key(postKeys, index)]) >= 0) index++;
return(llList2Key(postKeys, index));
}