OsSetSitActiveRange

From OpenSimulator

(Difference between revisions)
Jump to: navigation, search
m (passive voice change to active voice, punctuation.)
 
Line 13: Line 13:
 
// Example of osSetSitActiveRange
 
// Example of osSetSitActiveRange
  
vector target = <0.0, 0.3, 0.55>;
+
vector target = <0.0, 0.3, 0.55>; // Defines the position where avatars will sit
vector rotate = <0.0, 0.0, 90.0>;
+
vector rotate = <0.0, 0.0, 90.0>; // Defines the rotation of the seated avatars
float active_range = 5.0;
+
float active_range = 5.0; // Specifies the range within which avatars are considered active
key avatar;
+
key avatar; // Stores the key of the currently seated avatar
  
 +
// Function to output debug messages
 
debug(string name)
 
debug(string name)
 
{
 
{
     active_range = osGetSitActiveRange();
+
     active_range = osGetSitActiveRange(); // Updates the active range
     llOwnerSay("active_range for avatar " + name + " is " + (string)active_range);
+
     llOwnerSay("active_range for avatar " + name + " is " + (string)active_range); // Outputs debug message
 
}
 
}
  
Line 28: Line 29:
 
     state_entry()
 
     state_entry()
 
     {
 
     {
         llUnSit(llAvatarOnSitTarget());
+
         llUnSit(llAvatarOnSitTarget()); // Ensures no avatar is currently seated
         llSetClickAction(CLICK_ACTION_SIT);
+
         llSetClickAction(CLICK_ACTION_SIT); // Sets click action to trigger sitting behavior
         llSitTarget(target, llEuler2Rot((rotate * DEG_TO_RAD)));
+
         llSitTarget(target, llEuler2Rot((rotate * DEG_TO_RAD))); // Sets the sitting target position and rotation
         osSetSitActiveRange(active_range);
+
         osSetSitActiveRange(active_range); // Sets the active range for avatar sitting
 
     }
 
     }
  
 
     changed(integer change)
 
     changed(integer change)
 
     {
 
     {
         if (change & CHANGED_LINK)
+
         if (change & CHANGED_LINK) // Checks if there's a change in links (i.e., avatar sitting)
 
         {
 
         {
             key user = llAvatarOnSitTarget();
+
             key user = llAvatarOnSitTarget(); // Gets the key of the avatar sitting on the target
  
             if (user != NULL_KEY)
+
             if (user != NULL_KEY) // If an avatar is sitting on the target
 
             {
 
             {
                 avatar = user;
+
                 avatar = user; // Stores the key of the seated avatar
                 debug(osKey2Name(avatar));
+
                 debug(osKey2Name(avatar)); // Outputs debug message with the name of the seated avatar
 
             }
 
             }
 
+
             else if (user == NULL_KEY) // If no avatar is sitting on the target
             else if (user == NULL_KEY)
+
 
             {
 
             {
                 debug(osKey2Name(avatar));
+
                 debug(osKey2Name(avatar)); // Outputs debug message with the name of the previously seated avatar
                 avatar = NULL_KEY;
+
                 avatar = NULL_KEY; // Resets the stored avatar key
 
             }
 
             }
 
+
             else // If an unexpected situation occurs
             else
+
 
             {
 
             {
                 llResetScript();
+
                 llResetScript(); // Resets the script
 
             }
 
             }
 
         }
 
         }

Latest revision as of 00:04, 6 March 2024

osSetSitActiveRange(float range)
sets a limit on how far a avatar can be to have a sit request accepted, or disable sits.
  • range > 0: sit request is silently ignored if a avatar is further than range from the prim.
  • range == 0: disables this limit. Region default is used. Currently range is unlimited if a sit target is set or physics can sit the avatar, otherwise 10m.
  • range < 0: sits are disabled. Requests are silently ignored.

The range value is stored in the prim, even if the script is removed

Threat Level None
Permissions Use of this function is always allowed by default
Extra Delay 0 seconds
Example(s)
// Example of osSetSitActiveRange
 
vector target = <0.0, 0.3, 0.55>; // Defines the position where avatars will sit
vector rotate = <0.0, 0.0, 90.0>; // Defines the rotation of the seated avatars
float active_range = 5.0; // Specifies the range within which avatars are considered active
key avatar; // Stores the key of the currently seated avatar
 
// Function to output debug messages
debug(string name)
{
    active_range = osGetSitActiveRange(); // Updates the active range
    llOwnerSay("active_range for avatar " + name + " is " + (string)active_range); // Outputs debug message
}
 
default
{
    state_entry()
    {
        llUnSit(llAvatarOnSitTarget()); // Ensures no avatar is currently seated
        llSetClickAction(CLICK_ACTION_SIT); // Sets click action to trigger sitting behavior
        llSitTarget(target, llEuler2Rot((rotate * DEG_TO_RAD))); // Sets the sitting target position and rotation
        osSetSitActiveRange(active_range); // Sets the active range for avatar sitting
    }
 
    changed(integer change)
    {
        if (change & CHANGED_LINK) // Checks if there's a change in links (i.e., avatar sitting)
        {
            key user = llAvatarOnSitTarget(); // Gets the key of the avatar sitting on the target
 
            if (user != NULL_KEY) // If an avatar is sitting on the target
            {
                avatar = user; // Stores the key of the seated avatar
                debug(osKey2Name(avatar)); // Outputs debug message with the name of the seated avatar
            }
            else if (user == NULL_KEY) // If no avatar is sitting on the target
            {
                debug(osKey2Name(avatar)); // Outputs debug message with the name of the previously seated avatar
                avatar = NULL_KEY; // Resets the stored avatar key
            }
            else // If an unexpected situation occurs
            {
                llResetScript(); // Resets the script
            }
        }
    }
}
Notes
This function was added in 0.9.2.0
Personal tools
General
About This Wiki