Difference between revisions of "LlStartAnimation"

From Second Life Wiki
Jump to navigation Jump to search
m (remove previous edit of mine which bollixed up this page)
m
 
(25 intermediate revisions by 12 users not shown)
Line 1: Line 1:
{{LSLFunctionAll|func_id=129|func_sleep=0.0|func_energy=10.0|func=llStartAnimation|p1_type=string|p1_name=anim|func_footnote=Start animation anim for agent that owns object|return_text|spec|caveats|examples|helpers|related|also|notes}}[[Category:LSL_Functions]][[Category:LSL_Stub]]
{{LSL_Function
|inject-2={{Issues/BUG-10971}}{{Issues/BUG-7729}}{{Issues/BUG-7853}}
{{LSL_Function/permission|PERMISSION_TRIGGER_ANIMATION}}
{{LSL_Function/inventory|anim|uuid=false|type}}
|func_id=129|func_sleep=0.0|func_energy=10.0
|func=llStartAnimation|sort=StartAnimation
|p1_type=string|p1_name=anim|p1_desc= or [[Internal Animations|built-in animation]]
|func_footnote
|func_desc=Start animation {{LSLP|anim}} for agent that granted [[PERMISSION_TRIGGER_ANIMATION]] if the permission has not been revoked.
|return_text
|spec
|caveats=* Only 30 animations can be played at a time.  (Prior to 1.25.4 the limit was 15 and prior to 1.25.3 there was no limit at all.)
|constants
|examples=
<source lang="lsl2">
default
{
    touch_start(integer detected)
    {
        llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStartAnimation("sit");
            llOwnerSay("animation will end in 5 seconds");
            llSetTimerEvent(5.0);
        }
    }
    timer()
    {
        llSetTimerEvent(0.0);
        llStopAnimation("sit");
    }
}
</source>
Add an animation or pose inside the same object as this script:
<source lang="lsl2">
string animation; // the first animation in inventory will automatically be used
  // the animation name must be stored globally to be able to stop the animation when standing up
 
default
{
    state_entry()
    {
        // set sit target, otherwise this will not work
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
    }
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            key av = llAvatarOnSitTarget();
            if (av) //evaluated as true if not NULL_KEY or invalid
                llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
            else // avatar is standing up
            {
                if (animation)
                    llStopAnimation(animation); // stop the started animation
                llResetScript(); // release the avatar animation permissions
            }
        }
    }
   
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            animation = llGetInventoryName(INVENTORY_ANIMATION,0); // get the first animation from inventory
            if (animation)
            {
                llStopAnimation("sit"); // stop the default sit animation
                llStartAnimation(animation);
            }
        }
    }
}
</source>
Common script to play some kind of a "holding animation" while an object is attached to an avatar:
<source lang="lsl2">
string animation_name = "hold";
 
default
{
    // Whenever this object is attached or detached...
    attach(key id)
    {
        if (id)
        {  // If it was just attached, request permission to animate.
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        }
        else
        {  // It's being detached...
            if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
            {  // If we have permission to animate, stop the animation.
                llStopAnimation(animation_name);
            }
        }
    }
 
    // Whenever permissions change...
    run_time_permissions(integer permissions)
    {
        if (permissions & PERMISSION_TRIGGER_ANIMATION)
        {  // If permission to animate was granted, start the animation.
            llStartAnimation(animation_name);
        }
    }
}
</source>
|helpers
|also_functions={{LSL DefineRow||[[llStopAnimation]]|}}
|also_tests
|also_events
|also_articles={{LSL DefineRow||[[Internal_Animations]]|lists internal Animations always available}}
|notes
|cat1=Animation
|cat2
|cat3
|cat4
}}

Latest revision as of 12:14, 22 September 2020

Summary

Function: llStartAnimation( string anim );
0.0 Forced Delay
10.0 Energy

Start animation anim for agent that granted PERMISSION_TRIGGER_ANIMATION if the permission has not been revoked.

• string anim an item in the inventory of the prim this script is in or built-in animation

To run this function the script must request the PERMISSION_TRIGGER_ANIMATION permission with llRequestPermissions.

Caveats

Permissions
  • If anim is missing from the prim's inventory then an error is shouted on DEBUG_CHANNEL.
  • Only 30 animations can be played at a time. (Prior to 1.25.4 the limit was 15 and prior to 1.25.3 there was no limit at all.)

Examples

default
{
    touch_start(integer detected)
    {
        llRequestPermissions(llDetectedKey(0), PERMISSION_TRIGGER_ANIMATION);
    }
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            llStartAnimation("sit");
            llOwnerSay("animation will end in 5 seconds");
            llSetTimerEvent(5.0);
        }
    }
    timer()
    {
        llSetTimerEvent(0.0);
        llStopAnimation("sit");
    }
}

Add an animation or pose inside the same object as this script:

string animation; // the first animation in inventory will automatically be used
  // the animation name must be stored globally to be able to stop the animation when standing up

default
{
    state_entry()
    {
        // set sit target, otherwise this will not work 
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
    }
 
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            key av = llAvatarOnSitTarget();
            if (av) //evaluated as true if not NULL_KEY or invalid
                llRequestPermissions(av, PERMISSION_TRIGGER_ANIMATION);
            else // avatar is standing up
            {
                if (animation)
                    llStopAnimation(animation); // stop the started animation
                llResetScript(); // release the avatar animation permissions
            }
        }
    }
    
    run_time_permissions(integer perm)
    {
        if (perm & PERMISSION_TRIGGER_ANIMATION)
        {
            animation = llGetInventoryName(INVENTORY_ANIMATION,0); // get the first animation from inventory
            if (animation)
            {
                llStopAnimation("sit"); // stop the default sit animation
                llStartAnimation(animation);
            }
        }
    }
}

Common script to play some kind of a "holding animation" while an object is attached to an avatar:

string animation_name = "hold";

default
{
    // Whenever this object is attached or detached...
    attach(key id)
    {
        if (id)
        {   // If it was just attached, request permission to animate.
            llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
        }
        else
        {   // It's being detached...
            if (llGetPermissions() & PERMISSION_TRIGGER_ANIMATION)
            {   // If we have permission to animate, stop the animation.
                llStopAnimation(animation_name);
            }
        }
    }

    // Whenever permissions change...
    run_time_permissions(integer permissions)
    {
        if (permissions & PERMISSION_TRIGGER_ANIMATION)
        {   // If permission to animate was granted, start the animation.
            llStartAnimation(animation_name);
        }
    }
}

See Also

Events

•  run_time_permissions Permission receiving event

Functions

•  llGetPermissions Get the permissions granted
•  llGetPermissionsKey Get the agent who granted permissions
•  llRequestPermissions Request permissions
•  llStopAnimation

Articles

•  Script permissions
•  Internal_Animations lists internal Animations always available

Deep Notes

Signature

function void llStartAnimation( string anim );