Difference between revisions of "LlAvatarOnSitTarget"

From Second Life Wiki
Jump to navigation Jump to search
m (On the last code snippet, used the signature 'listen(integer channel, string name, key id, string message)' for consistency's sake)
 
(36 intermediate revisions by 17 users not shown)
Line 1: Line 1:
{{LSL_Function|func_id=239|func_sleep=0.0|func_energy=10.0
{{LSL_Function|func_id=239|func_sleep=0.0|func_energy=10.0
|func=llAvatarOnSitTarget|sort=AvatarOnSitTarget
|func=llAvatarOnSitTarget
|return_type=key
|return_type=key
|return_text=that is the key of the user seated on the prim.
|return_text=that is the [[UUID]] of the user seated on the prim.
|func_footnote=If the prim lacks a sit target or there is no avatar sitting on the prim, then {{LSLG|NULL_KEY}} is returned.
|func_footnote=If the prim lacks a [[llSitTarget|sit target]] or there is no avatar sitting on the prim, then {{LSL Constant/NULL_KEY}} is returned.
|caveats=If the prim lacks a sit target or the avatar is seated upon a different prim, the only way to determin how many and which avatars are seated upon the object is to scan the link set.
|caveats=*A prim does not have a sit target unless [[llSitTarget]] has been called with a '''nonzero''' vector as the first argument.
*If the prim lacks a sit target or the avatar is seated upon a different prim, the only way to determine how many and which avatars are seated upon the object is to scan the link set (for an example of this, see [[llGetNumberOfPrims#Useful_Snippets|llGetNumberOfPrims]]).
|spec
|spec
|examples=|examples=<lsl>
|examples=<syntaxhighlight lang="lsl2">default
default
{
{
     state_entry()
     state_entry()
     {
     {
         // set sit target, otherwise this will not work  
         // set sit target, otherwise this will not work  
         llSitTarget(<0,0,.1>, ZERO_ROTATION);
         llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
     }
     }


     changed(integer chance) {
     changed(integer change)
         if (change & CHANGED_LINK) {  
    {
             if (llAvatarOnSitTarget() != NULL_KEY) {
         if (change & CHANGED_LINK)
                 llSay(0, "Hello " + llKey2Name(llAvatarOnSitTarget()) + ", thank you for sitting down");
        {  
            key av = llAvatarOnSitTarget();
             if (av) // evaluated as true if key is valid and not NULL_KEY
            {
                 llSay(0, "Hello " + llKey2Name(av) + ", thank you for sitting down");
            }
        }
    }
}</syntaxhighlight>
|helpers=<syntaxhighlight lang="lsl2">//Gets the link number of a seated avatar
integer GetAgentLinkNumber(key avatar)
{
    integer link_num = llGetNumberOfPrims();
    while (link_num > 1) // Check only child prims.
    {
        if (llGetLinkKey(link_num) == avatar) // If it is the avatar we want
        {
            return link_num; // then return the link number
        }
        --link_num; // else go on with next child.
    }
    // Avatar wasn't found
    return FALSE; // 0 (zero) for easy testing.
}</syntaxhighlight>
<syntaxhighlight lang="lsl2">//It's sometimes useful to use a state change
//useful when the prim is linked to an other prim
//and useful with a dialog box
default
{
    state_entry() 
    {
        //"Sit target is a prim property."
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
    }
   
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            key av_sit = llAvatarOnSitTarget();
            if (av_sit)
            {
                //Someone is on the sit target.
                state sitting;
             }
             }
         }
         }
     }
     }
}
}
</lsl>
 
|helpers=<pre>
state sitting
//Gets the link number of a seated avatar
integer GetAgentLinkNumber(key avatar)
{
{
     integer linkNum = 1 + llGetNumberOfPrims();
     state_entry()
     key linkKey;
     {
    //Next we get the linkKey and make sure it's not null, if it's null we are done.
        //Open a dialog box when an avatar is sitting on the prim
    while((linkKey = llGetLinkKey( --linkNum )))
        key av_menu = llAvatarOnSitTarget();
         if(avatar == linkKey)//It's an avatar, is it the avatar we want?
        llListen(-99, "", av_menu, "Yes");
            return linkNum;//It's the avatar we want so return.
        llDialog(av_menu, "\nDo you like this example?", ["Yes", "No" ] , -99);
     //avatar wasn't found so return a number that isn't a LINK_* flag that can't be a valid link number either.
    }
    return 0x7FFFFFFF;//max int.
   
}//Written by Strife Onizuka
    changed(integer change)
</pre>
    {
        if (change & CHANGED_LINK)
         {
            key av_unsit = llAvatarOnSitTarget();
            if (av_unsit == NULL_KEY)  
            {
                //No one is on the sit target.
                //"On state change all listens are removed automatically."
                state default;
            }
        }
    }
 
     listen(integer channel, string name, key id, string message)
    {
        // If the user clicked the "Yes" button
        llWhisper(0, "Thank you");
    }
}</syntaxhighlight>
|related
|related
|also_tests
|also_tests
|also_events={{LSL DefineRow||{{LSLG|changed}}|}}
|also_events={{LSL DefineRow||[[changed]]|}}
|also_functions={{LSL DefineRow||{{LSLG|llSitTarget}}|}}
|also_functions=
|also_articles
{{LSL DefineRow||[[llAvatarOnLinkSitTarget]]|}}
|notes
{{LSL DefineRow||[[llSitTarget]]|}}
{{LSL DefineRow||[[llLinkSitTarget]]|}}
{{LSL DefineRow||[[llGetLinkKey]]}}
|also_articles={{LSL DefineRow||[[CHANGED_LINK]]|}}
|notes=The position of an avatar on a sit target can be determined with the use of [[llGetObjectDetails]] (see [[llSitTarget#Useful_Snippets|llSitTarget]] for an example).
|haiku={{Haiku|Glorious sunset|Lazy avatar enjoys|sitting on a prim}}
|cat1=Avatar
|cat1=Avatar
|cat2=Prim
|cat2=Prim

Latest revision as of 14:32, 23 April 2022

Summary

Function: key llAvatarOnSitTarget( );
0.0 Forced Delay
10.0 Energy

Returns a key that is the UUID of the user seated on the prim.

If the prim lacks a sit target or there is no avatar sitting on the prim, then NULL_KEY is returned.

Caveats

  • A prim does not have a sit target unless llSitTarget has been called with a nonzero vector as the first argument.
  • If the prim lacks a sit target or the avatar is seated upon a different prim, the only way to determine how many and which avatars are seated upon the object is to scan the link set (for an example of this, see llGetNumberOfPrims).

Examples

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 key is valid and not NULL_KEY
            {
                llSay(0, "Hello " + llKey2Name(av) + ", thank you for sitting down");
            }
        }
    }
}

Useful Snippets

//Gets the link number of a seated avatar
integer GetAgentLinkNumber(key avatar)
{
    integer link_num = llGetNumberOfPrims();
    while (link_num > 1) // Check only child prims.
    {
        if (llGetLinkKey(link_num) == avatar) // If it is the avatar we want
        {
            return link_num; // then return the link number
        }
        --link_num; // else go on with next child.
    }
    // Avatar wasn't found
    return FALSE; // 0 (zero) for easy testing.
}
//It's sometimes useful to use a state change
//useful when the prim is linked to an other prim
//and useful with a dialog box
default
{
    state_entry()  
    {
        //"Sit target is a prim property."
        llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
    }
    
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        { 
            key av_sit = llAvatarOnSitTarget();
            if (av_sit) 
            {
                //Someone is on the sit target.
                state sitting;
            }
        }
    }
}

state sitting
{
    state_entry()
    {
        //Open a dialog box when an avatar is sitting on the prim
        key av_menu = llAvatarOnSitTarget();
        llListen(-99, "", av_menu, "Yes");
        llDialog(av_menu, "\nDo you like this example?", ["Yes", "No" ] , -99);
    }
    
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        { 
            key av_unsit = llAvatarOnSitTarget();
            if (av_unsit == NULL_KEY) 
            {
                //No one is on the sit target.
                //"On state change all listens are removed automatically."
                state default;
            }
        }
    }

    listen(integer channel, string name, key id, string message)
    {
        // If the user clicked the "Yes" button
        llWhisper(0, "Thank you");
    }
}

Notes

The position of an avatar on a sit target can be determined with the use of llGetObjectDetails (see llSitTarget for an example).

See Also

Events

•  changed

Functions

•  llAvatarOnLinkSitTarget
•  llSitTarget
•  llLinkSitTarget
•  llGetLinkKey

Articles

•  CHANGED_LINK

Deep Notes

Signature

function key llAvatarOnSitTarget();

Haiku

Glorious sunset
Lazy avatar enjoys
sitting on a prim