Jump to content

Keep people from sitting on my object?


Recommended Posts

Not as such, since the script can't detect someone is sitting until they actually sit.    However, it's easy enough to unsit someone immediately if they try to sit. 

You detect someone sits using the changed event, and then unsit them using llUnsit().   If you look at the wiki you will see some examples of how to use it.  Either of the first two examples will do what you want, with a minor change.

That is, immediately before you unsit the avatar, you need to test whether it's the owner or not.   

So I would alter the changed event in the first example to read something like

	if(change & CHANGED_LINK) // When an agent sits on an object they become a new link.		{			key user = llAvatarOnSitTarget(); // Store the UUID of any agent sitting on the sit target.			if(user)// An avatar is on the sit target.			{				if(user != llGetOwner())//if the avatar is not the owner				{					llUnSit(user); // Un-Sit the avatar.				}			}		}


Note that is just a snippet -- you need to look at the first example script and change it in the way I suggest.

Link to comment
Share on other sites

It seems that you only care about people sitting on the same object you're already sitting on, and they should be able to join you while you're "awake" but not while "away". If so, the script must

  1. determine that you (the owner, presumably) are sitting on the object, and if so,
  2. determine when you go AFK and return, and
  3. change "sit-ability" accordingly, and
  4. restore to normal when you stand.

So the CHANGED_LINK event is clearly the trigger for #1 and #4, and to be most general the script would run through all the links, checking if one of them is the owner (this as opposed to only checking the avatar on the sit target, about which more below).

For #2, you probably need to poll llGetAgentInfo() on the seated owner to detect AGENT_AWAY.

For #3, as Innula suggests, you could llUnSit the intruder; that's probably all you need, and you'd need that as a fall-back anyway, but it may also be possible to get the system to discourage sitting with its frustrating "no suitable places to sit" response. To do that, you'd need to cycle through each prim in the linkset clearing llLinkSitTarget (which you'd want to restore in #4).

Now, it may be that a linkset on which are set any sit targets can only seat as many avatars as there are sit targets, but I am not at all confident about that. If that works, you'd simply clear all but whichever sit target the owner is occupying, and you'd be done. If instead multiple avatars can be seated on a linkset with just one sit target, then it may be worth the effort to reshape the collision envelope of the linkset to make it harder to sit on, perhaps by scaling up some transparent pointy links to act as "pigeon spikes" for avatars.

Link to comment
Share on other sites

There is one problem: llAvatarOnSitTarget only works if the avatar is sitting on the sit target. But the owner already sits there.

So you need to check the other sit targets with llAvatarOnLinkSitTarget.

If there are no other sit targets you can link a prim with a sit target or set a sit target in another prim of the object.

To unsit an avatar that doesn't sit on a sit target you neeed to scan the whole linkset in a loop and check if its an avatar.

if (llGetAgentSize(uuid)) // true if it's an avatar

Then check for not owner and unsit.

You can move the avatar about max 1000m (within sim boundaries) b4 unsit but thats griefing. You can drop them 3m away if you want to add some force to the unsit.

Another idea is to set the 2nd sit target to a location 10m away. (max 310m possible) That will work if there are no more sit targets on this object. You don't even need a script then. Just one to set the sit target once..

Link to comment
Share on other sites

If the goal is to prevent a second person from sitting on your object, you can take advantage of the priority system that LSL gives for link sit targets.  Here's the relevant note from the LSL wiki:

If an object has multiple seats (each seat has a script that sets a sit target with llSitTarget, or the linkset has a script that assigns several llLinkSitTargets), the following method determines which sit target an avatar ends up at:

  • If the prim that is clicked on has a sit target and that sit target is not full, that sit target is used.
  • If the prim that is clicked on has no sit target, and one or more other linked prims have sit targets that are not full, the sit target of the prim with the lowest link number will be used.

The trick, then, is to apply a sit target in your object's root prim and then a link sit target in link #2.  Then write your changed event, in part, as

changed (integer change){    if (change & CHANGED_LINK)    {        key Av1 = llAvatarOnLinkSitTarget(1);        key Av2 = llAvatarOnLinkSitTarget(2);        if (Av1)        {            //Do normal sitting stuff ... activate animation, play sound, whatever...        }        if (Av2)        {            llUnSit(Av2);        }    }}

 Then, be sure that link #2 is in a place where nobody is likely to ever sit on it.  I use a very tiny transparent prim on the inside of the root prim.  All of this means that anyone sitting on your object while it is unoccupied will end up on link sit target #1. If there is already someone on link sit target #1, the priority rules say that the person will be seated on the next available prim with a numbered sit target ... your bouncer prim.  There are no other seating options.


Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in

Sign In Now

  • Create New...