Differences

This shows you the differences between two versions of the page.

Link to this comparison view

wiki:scripting_portal:lsl_functions:llavataronsittarget [2018/11/20 17:25]
Royale Mobian created
wiki:scripting_portal:lsl_functions:llavataronsittarget [2019/07/22 19:01] (current)
Royale Mobian
Line 1: Line 1:
 ====== llAvatarOnSitTarget ====== ====== llAvatarOnSitTarget ======
-===== Introduction ===== +**[[wiki:​scripting_portal:​lsl_functions|Function]]:​ [[wiki:​scripting_portal:​lsl_types:​key|key]] llAvatarOnSitTarget( );**\\ 
- +Returns a key that is the [[wiki:uuid|UUID]] of the user seated on the prim.
- +
-==== Example use cases====+
  
 +If the prim lacks a sit target or there is no avatar sitting on the prim, then [[wiki:​scripting_portal:​lsl_functions:​ll_constants:​null_key|NULL_KEY]] is returned.**[[wiki:​scripting_portal:​lsl_functions|Function]]:​ [[wiki:​scripting_portal:​lsl_types:​key|key]] llAvatarOnSitTarget( );**
  
 +===== Caveats =====
 +  * A prim does not have a sit target unless [[wiki:​scripting_portal:​lsl_functions:​llsittarget|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 [[wiki:​scripting_portal:​lsl_functions:​llgetnumberofprims|llGetNumberOfPrims]]). ​
  
 ===== Examples ===== ===== Examples =====
  
 <code ossl> <code ossl>
 +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"​);​ 
 +            } 
 +        } 
 +    } 
 +}
 </​code>​ </​code>​
 +==== Useful Snippets ====
 +<code ossl>
 +//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.
 +}
 +</​code>​
 +<code ossl>
 +//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 chan, string name, key id, string msg)
 +    {
 +        // If the user clicked the "​Yes"​ button
 +        llWhisper(0,​ "Thank you");
 +    }
 +}
 +</​code>​
 +=== Notes ===
 +The position of an avatar on a sit target can be determined with the use of [[wiki:​scripting_portal:​lsl_functions:​llGetObjectDetails|llGetObjectDetails]] (see [[wiki:​scripting_portal:​lsl_functions:​llSitTarget|llSitTarget]] for an example).
 +
 +===== See Also =====
 +==== Events ====
 +  * [[wiki:​scripting_portal:​events:​changed|changed]]
 +
 +==== Functions ====
 +  * [[wiki:​scripting_portal:​lsl_functions:​llAvatarOnLinkSitTarget|llAvatarOnLinkSitTarget]]
 +  * [[wiki:​scripting_portal:​lsl_functions:​llSitTarget|llSitTarget]]
 +  * [[wiki:​scripting_portal:​lsl_functions:​llLinkSitTarget|llLinkSitTarget]]
 +  * [[wiki:​scripting_portal:​lsl_functions:​llGetLinkKey|llGetLinkKey]]
 +
 +==== Articles ====
 +  * [[wiki:​scripting_portal:​lsl_functions:​ll_constants:​changed_link|CHANGED_LINK]]
QR Code
QR Code wiki:scripting_portal:lsl_functions:llavataronsittarget (generated for current page)