Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Detecting a sitting agent/avitar without a sit target.

Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-17-2008 08:03
I have a large boat I am building, it has multiple seats and I want avitars to be able to sit in any seat at any time leaving any of the others open. As I understand it with sit target it forces avitars to sit on seats in link order. Now in addition to that I want to be able check if the operator of the boat is still sitting, and if not the boat stops.

Any help on this is appreciated.

Thanks in advance.
Eric Stuart
Registered User
Join date: 5 Jul 2006
Posts: 203
06-17-2008 08:10
I may have an idea on this. Just set the other seats in the boat to be poseballs with a single script inside them, instead of a script in the entire boat. If you want to save prims, just put a poseball script inside the seat and adjust the coding to align the person so that they are sitting they way you want. That way, they right click the seat and hit sit and sit on the single object with the prim, instead of having the problem you're having.

As for the vehicle stopping, I do believe that if you set the drivers seat up the same way (single prim with driving script in it, and the full boat having the vehicle script) then it will stop moving when the driver stands up from his position.

Hope this helps!
Jillian Callahan
Rotary-winged Neko Girl
Join date: 24 Jun 2004
Posts: 3,766
06-17-2008 08:11
If an av wants to sit in a particular seat, they can click on that particular prim for the pie menu and skip the link order.
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-17-2008 08:21
Alright yes that is working... now an old problem. How do I detect the "pilot" standing up separate from another Av sitting on another seat?

Here is my script for the seat. As it stands another Av sitting triggers the same condition as the pilot standing up.

CODE

default
{
state_entry()
{
llSitTarget(<0.1, -0.5, -0.2>, llEuler2Rot(<0,0,-90> * DEG_TO_RAD));
llSetCameraEyeOffset(<2.5,5,5>);
llSetCameraAtOffset(<2.5,-6,2>);
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
llSay(0, "You aren't the owner!");
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
// You sit and are owner so get controls
llMessageLinked(LINK_ROOT, llGetLinkNumber(), "pilot", agent);
}
}
else if (agent == NULL_KEY)
{
// You stand so boat stops
llMessageLinked(LINK_ROOT, llGetLinkNumber(), "moor", NULL_KEY);
}
}
}
}
Eric Stuart
Registered User
Join date: 5 Jul 2006
Posts: 203
06-17-2008 08:29
Just place the pilot script itself into the drivers seat and no others...don't put it into the entire boat.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-17-2008 10:41
You can actually find all the avatars sitting on an object without any sit targets even defined (try using this on changed/CHANGED_LINK events to print out a list of sitting avatars):

CODE

list getSittingAvatars()
{
list sitters = [];

integer index = nPrims;
while (index > 1)
{
key linkKey = llGetLinkKey(index);
if (llGetAgentSize(linkKey) != ZERO_VECTOR)
{
sitters = (sitters=[])+sitters+[ linkKey ];
--index;
} else
{
index = 0;
}
}

return sitters;
}


but unless you want to come up with your own logic for determining/remembering who "the pilot" is (e.g. the first avatar to sit down, or the closest to the controls, or whatever) a sit target and llAvatarOnSitTarget() is a good way to do it.

Note: The above code hasn't yet been compiled and may need a minor syntactic fix or two.
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
06-17-2008 14:05
It's funny I was just writing one of these things the other day.
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-17-2008 18:12
To be clear the code I posted above IS in the pilots seat only, the seat post is actually the root prim where the controls takes place, the "pilot" and "moor" messages effect the control script only prompting it to take control of the pilots inputs, the control script in turn sends "start" and "stop" to all other scripts related to the "drive wake" as well as turning the "hud" on and off.
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-18-2008 11:12
Alright still a little baffled as to why my sit target code above is triggering erroneously and what I could do to filter it further. Now the code above correctly detects when I sit or stand producing my key when I sit, and a Null Key when I stand... BUT it also produces a Null Key when some one else sits or stands which triggers the "moor" message killing the control system as if I stood up. This is proving to be fairly aggravating, should llAvatarOnSitTarget() not return a valid value after an avatar sits, or will it only return a value when an avatar sits on the object?

Though I am considering adapting some of the code Hewee suggested setting the pilot using the sit target then then scanning the keys for the pilot on CHANGE_LINK and possibly CHANGE_REGION as region crossings are also where one seems to be cast overboard.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
06-18-2008 11:36
From: Mortus Allen
...BUT it also produces a Null Key when some one else sits or stands which triggers the "moor" message killing the control system as if I stood up. This is proving to be fairly aggravating, should llAvatarOnSitTarget() not return a valid value after an avatar sits, or will it only return a value when an avatar sits on the object?

Your code unseats anyone who isn't the owner, which will cause another 'changed' event (avatar stands up), this time with no one on the sit target.
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-18-2008 11:43
But would that not be true for only that seat prim. It is also generating that "error" when I sit on a seat other than the captains chair.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
06-18-2008 11:49
From: Mortus Allen
This is proving to be fairly aggravating, should llAvatarOnSitTarget() not return a valid value after an avatar sits, or will it only return a value when an avatar sits on the object?


Just checked to see if this was borked but it seems fine, each child is correctly reporting what is (or isn't) on its own sit target both inside and outside changed events, with a little bit of musical chairs going on between two avatars.

But, any time anyone sits or stands in the link set, if the pilot is still there, a new "pilot" link message will be sent out. Is your root prim's script accounting for that? (you might want to store away the last value of "agent" and only send the message if things have actually changed.)
_____________________
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-18-2008 12:03
Here is the code that recieves the message from the seat. To my knowledge and experiance the link message event triggers for each message that is recieved, as you can see I have Owner Say debug code in place in the link message event so I can see all messages coming to the root script.

CODE

link_message(integer sender_num, integer num, string str, key id)
{
llOwnerSay("Message Recieved: " + str + " " + (string)id);

if (str == "pilot")
{
// You sit and are owner so get controls
llSetStatus(STATUS_PHYSICS, TRUE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, TRUE);
llRequestPermissions(id,PERMISSION_TAKE_CONTROLS);
}
else if (str == "moor")
{
// You stand so boat stops
llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", NULL_KEY);
llSetStatus(STATUS_PHYSICS, FALSE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y | STATUS_ROTATE_Z, FALSE);
llReleaseControls();
llSetTimerEvent(0.0);
speed = 0;
}
}


I also removed the Unsit code incase this was triggering a false unsit even with the false Null Key avatar.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
06-18-2008 12:34
All righty, testing with a slightly modified version of the script you posted here. The only difference in the pilot seat script is the introduction of last_agent, so we aren't repeatedly asking to take controls or moor unless the pilot is actually sitting or standing.

CODE

key last_agent = NULL_KEY;

default
{
state_entry()
{
llSitTarget(<0.1, -0.5, -0.2>, llEuler2Rot(<0,0,-90> * DEG_TO_RAD));
llSetCameraEyeOffset(<2.5,5,5>);
llSetCameraAtOffset(<2.5,-6,2>);
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent != NULL_KEY)
{
if (agent != llGetOwner())
{
llSay(0, "You aren't the owner!");
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
// You sit and are owner so get controls
if (last_agent != agent) { // only do if the pilot just arrived
llMessageLinked(LINK_ROOT, llGetLinkNumber(), "pilot", agent);
}
}
}
else if (agent == NULL_KEY)
{
// You stand so boat stops
if (last_agent == llGetOwner()) { // only do this if the pilot was there
llMessageLinked(LINK_ROOT, llGetLinkNumber(), "moor", NULL_KEY);
}
}
last_agent = agent;
}
}
}


The other child prim that I'm using as a "passenger seat" has no running scripts in it.

in the root prim I have the bare bones script:

CODE

default {
link_message(integer sender_num, integer num, string str, key id)
{
llOwnerSay("Message Received: " + str + " " + (string)id);
}
}


With this arrangement (no other scripts to be found in the link set but these two in the root and pilot seat), things seem ok here.
_____________________
Mortus Allen
Registered User
Join date: 28 Apr 2007
Posts: 528
06-18-2008 14:14
Works like a charm Viktoria, thanks for the help. Guess I am a little to off for scripting at the moment, but that solution was easy enough to not occur to me. LOL Thanks again all for you attempts to help.
Viktoria Dovgal
Join date: 29 Jul 2007
Posts: 3,593
06-18-2008 15:39
Mm, LSL reminds me of my bratty nephew, if you don't ask it things in just the right way it gives you a smart-ass answer.
_____________________
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
06-18-2008 19:52
From: Viktoria Dovgal
Mm, LSL reminds me of my bratty nephew, if you don't ask it things in just the right way it gives you a smart-ass answer.

And that reminds me of a joke.

A helicopter leaves a Seattle office building on a routine flight to the airport to drop off the family of some executives. As they are making their way the fog rolls in and they are forced to switch to instruments, when all of a sudden the main panel sparks and catches fire. After putting out the fire all, the electronics are burnt out. They fly about, nearly miss the trees a couple time as they search for a place to land, until finally they see the glowing hulk of a building loom out of the fog. They pull along side and see it's a big office full of cubicles with people milling about and working at computers. When the workers see the helicopter they start to gather about the closest windows. The pilot says to his co "We need to find out where we are" and so the co climbs in the back and writes on a piece of cardboard in a big letters "Where are we?" then holds it up to the window. The office denizens squint to make out the text and then start to talk hurriedly, then one runs off and returns with cardboard and marker. They wait patiently while the workers scribble, when it is finally held up the copilot reads allowed "You are in a helicopter." The pilot starts to get angry but then all of a sudden laughs and says to his co, "Chart us a course to the airport, we are at the Microsoft complex". After finally making it to the airport and landing the copilot turns to the pilot and asks "How did you know where we were?" The pilot smiles and replies "Because at Microsoft, they give you total factual answers that are entirely useless."
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river.
- Cyril Connolly

Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence.
- James Nachtwey