Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Guest Pilot Modification

PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 07:00
Guest Pilot Modification

Greetings,
Guest Pilot

As complex as this thread sounds (sorry for the long post), this all emulates a normal RL environment in the cockpit which I need to script/emulate. I am very interested in developing this here, on the Forum, and freely returning the modifification necessary as an "Example Script" here in the list.

Three (3) Seats:
I have a flight script that works well in a vehicle with three seats. I think of and label the seats as "Pilot", "CoPilot", and "Passenger". My goal and intent is to learn how to think of the script as enabling of the Pilot to "hand_off" Controls to the CoPilot, and the reverse, for the CoPilot to "hand_off" controls back to the Pilot. Ideally without either having to stand to do so. "Passenger" can be seated at any time, even first, and never be considered for controls.

"First Sit" irrelevant:
Further defining my goal, I am hoping to allow EITHER the Pilot OR CoPilot to be seated first, whilst still enabling this functionality.

Further still, if the CoPilot initially assumed control, then the Pilot seats, the CoPilot would be queried if CoPilot would like to hand off controls Yes/No. If no, then the CoPilot would continue to maintain Controls, but the CoPilot would still be given permissions to BE ABLE to "hand_off" to Pilot later, during flight, and without either needing to stand for this to work. This also means that if CoPilot is in control and Pilot reSeats... Pilot needs to be queried and given permission to TakeControls without actually _assuming_ those controls, allowing CoPilot to continue to maintian controls.

Further still, using the above example, if while in flight the Pilot stands (assuming in hover mode for example), Controls would Release from Pilot, revert over to the seated CoPilot, warning CoPilot of this change, and Pilot would walk around. When Pilot resumes Seat, Pilot would be queried for and granted Permissions; however CoPilot would continue to maintain controls until CoPilot initiates a "hand_off" to Pilot.

Disclaimer: If this modification is the source of in-world profit and risk of Open-Sourcing this modification is terrifying, please IM me in-world, or Private Message me in the Forums here, and do not dilute this thread with such discussion, as it has been talked out in other threads. It is not my intention to dilute in-world profits. however this modification has proved impossible for me to locate for purchase in-world (I need full perms for a subsequent modification) and only vaguely alluded to here on the forums.

One final note: Owner.
If the Owner of the vehicle assumes EITHER the seat of Pilot or CoPilot, they must be enabled at all times to chat-take controls back, overriding any current priveleges.


Initial difficulties that I see:
1) The FlightScript MUST be taken to NOT reside in the Pilot Seat, but rather in a linked prim I will call FlightPlate. Meaning not any of the three seats, leaving the seats to handle the SetCamera and SitPoses, seated, unseated, and so on.
2) FIRST avatar to click on a seat, any of the three, should trigger the FlightScript from that seat. meaning the Passenger seat should trigger nothing, the CoPilot Seat should set the FlightScript variable coPilotSeated = TRUE;, and the Pilot Seat should a) NOT be the prim the FlightScript is in, but rather b) like the CoPilot Seat, trigger the FlightScript variable pilotSeated = TRUE;. From this the FlightScript needs to decide how to handle furture change.

Please reply and help begin developing this modification.
Hewee Zetkin
Registered User
Join date: 20 Jul 2006
Posts: 2,702
05-01-2008 09:06
Each seat (or a prim in each seat anyway) can set its own sit target with llSitTarget(), and then test whether there is an avatar on it with llAvatarOnSitTarget(). From there, it sounds like what you are talking about is the use of link messages to communicate this information to a master controller script, probably in the root prim of the vehicle. Then you'll probably either have multiple scripts to take the controls of all the relevant sitters, or some logic in one that does llReleaseControls(), llRequestPermissionse()/PERMISSION_TAKE_CONTROLS, and llTakeControls() to switch residents.

Similarly, of course, you might decide which resident(s) to accept chat/touch inputs from given the current script/variable state and any number of other things you might do to control a vehicle.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
05-01-2008 09:41
There is a wrinkle here, a bug with llTakeControls, that causes problems whenever you take controls for more than one avatar at a time (using multiple scripts of course, since one script can have permissions for at most one avatar).

When your control handler runs, the key passed will always be the owner's, regardless who hit the key. Also, when different scripts in a prim have controls for different avs, every control event is handed to every script -- not just the one which has taken control for the av who hit the key. Hopefully this won't happen if the scripts are in different prims in a linked set, but I haven't tested that.

If you simply want both pilot and copilot to have controls, then just have two scripts that take controls (e.g., one in each seat as Hewee says), and have them pass linked messages to the vehicle script. Then as in RL, either pilot can fly without passing control, but if they both try to at the same time, they'll fight each other.

Just make sure to test the possibility that for each keystroke, you might get two messages: one from the pilot's seat, and one from the copilots -- regardless who hit the key. Hopefully this problem is limited to scripts in a prim, rather than scripts in separate prims, in which case you won't get two messages.
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-01-2008 10:04
From: Lear Cale
If you simply want both pilot and copilot to have controls, then just have two scripts that take controls (e.g., one in each seat as Hewee says), and have them pass linked messages to the vehicle script. Then as in RL, either pilot can fly without passing control, but if they both try to at the same time, they'll fight each other.

Just make sure to test the possibility that for each keystroke, you might get two messages: one from the pilot's seat, and one from the copilots -- regardless who hit the key. Hopefully this problem is limited to scripts in a prim, rather than scripts in separate prims, in which case you won't get two messages.

What about just put the complete script + another small script in each seat. Then have a button on the dash with another small script that will send a link message to the seats, turning one off and the other on using llSetScriptState.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 12:26
Hewee,
Thank you for your contribution. Well put, see these example scripts.

Lear,
Thank you. And this is where we are. While I have not tested the below with anyone but myself (also Owner) yet, the switch happens down in the FlightScript where curr_pilot is swapped out. What we will need to try to do is keep from having ReleaseControls force the avatars to unsit (to sit and request them again. ideally, once permission is received and granted we need to simply pass actual COntrol back and forth, having permission from both avatars. Possible?

Jesse,
What a delight and honor to have you looking into this. Your posts over the last few years in here have inspired me to contantly take on too much at once. That's a good thing, Jesse, a compliment. :)

While of course there will always be an "Owner" this laboratory MUST be viewed first (to keep it simple and focussed) from the standpoint that anyone attempting to use this craft has already been authorized to do so. (in my case I handle this with an AccessControlList of names in a root prim Notecard; an accompanying database script that tests for authorization must pass through first) I make this point simply to clarify and stay focussed on the task at hand, and to eliminate Owner as the only qualifier, thus other than Owner can have same degree of privileges.


OK, to get the ball rolling: :)
Here are the two initial SeatScripts and the FlightScript
The guestPilot_testPlatform is:
(1) 10x10x.1 plywood root prim (I named mine FlightPlate) with zero rotation facing East (forward). This prim takes the role of Root Prim in the vehicle linkset and contains the script for the Flight system and behaviours. This script we call FlightScript v0.0.1 or whatever.
(1) single prim seat labelled PilotSeat with a sitPilot script in it's contents. This sitPilot script handles any qualifying avatar seated as assuming the role of "Pilot".
(1) single prim seat labelled CoPilotSeat with a sitCoPilot script in it's contents. This sitCoPilot script handles any qualifying avatar seated as assuming the role of "CoPilot".

I sprinkled som ilSay("";); commands throughout so your chat window will kind of echo what was fired. Messy but effective to get us up and running here.

IF you download this scriptset, PLEASE respect the work of the original authors to-date, DO come back to this post and post your findings good or bad and DO post corrections suggestions. While you are welcome to IM me in-world, please keep development results here in this thread where everyone can find and learn from them.
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 12:27
CODE

// FlightScript script to develop a Guest Pilot system for use in the secondlife Example Script development program
// URL = http://rpgstats.com/wiki/index.php?title=Examples
// Discussion URL at: /54/9e/256457/1.html
// By contributors on the secondlife "Scripting Tips" Forum

// This FlightScript is developed from the:
// Mouselook flyer mmotor script
// By Jillian Callahan

//Please leave the credits intact!
//This script is NOT INTENDED FOR SALE! It's for learning about scripting!

float FWD_THRUST = 35.0; // Forward thrust motor force maximum
float LATERAL_THRUST = 8.0; // Lateral
float VERTICAL_THRUST = 14.0; // Hover thrust
float THRUST_PITCH = 0.0;
float mass;

// Other varables
key curr_pilot = NULL_KEY; // the key of the pilot passed from the sit and control scripts of either PilotSeat or CoPilot Seat

float motor_x = 0.0; // PERCENTAGES of MOTOR THRUST
float motor_y = 0.0;
float motor_z = 0.0;

// STATES

default
{
state_entry()
{
mass = llGetMass();
llSay(0, "Mass of this craft is currently: "+(string)mass);
llSetStatus(STATUS_PHANTOM, FALSE);
llSetStatus(STATUS_BLOCK_GRAB, TRUE);

llSetVehicleType(VEHICLE_TYPE_SLED);

llRemoveVehicleFlags(-1);
llSetVehicleFlags(VEHICLE_FLAG_HOVER_UP_ONLY);
llSetVehicleFlags(VEHICLE_FLAG_MOUSELOOK_STEER);
llSetVehicleFlags(VEHICLE_FLAG_CAMERA_DECOUPLED);
llSetVehicleFlags(VEHICLE_FLAG_LIMIT_ROLL_ONLY);

llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.0);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 900.0);

llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.0);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 900.0);

llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.25); // ------------- 1.5
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 100.0);

llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.05);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.01);

llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0.0, 6.0, 5.25> ); // Required for mouselook

llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <60.0, 1.0, 30.0>);
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <0.0, 0.0, 0.0>);

llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 0.0);
llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0);
llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 9000.0);

llSetVehicleFloatParam(VEHICLE_BUOYANCY, 0.94); // We floats, we does

llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5); // We be upright, but not uptight
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1.0);

llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.0); // We likes to bank, we do
llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.75);
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.05); // And be quick about it!
}

link_message(integer src, integer num, string msg, key id)
{
if ( ( msg == "pilot" || msg == "copilot" ) && (id == NULL_KEY) )
{
llSay(0, "No Pilot or CoPilot in control. Shutting down.");
llSetTimerEvent(0);

motor_x = 0.0; // PERCENTAGES of MOTOR THRUST
motor_y = 0.0;
motor_z = 0.0;
llMessageLinked(LINK_SET,0,"THROTTLE",NULL_KEY);
llMessageLinked(LINK_SET,0,"rundown",NULL_KEY);
llReleaseControls();
llResetScript();
}
else if( ( msg == "pilot" ) && (id != NULL_KEY) )
{
llSay(0, "FlightScript curr_pilot is set to: "+msg);
motor_x = 0.0; // PERCENTAGES of MOTOR THRUST
motor_y = 0.0;
motor_z = 0.0;
llMessageLinked(LINK_SET,0,"THROTTLE",NULL_KEY);
llMessageLinked(LINK_SET,0,"runup",NULL_KEY);
curr_pilot = id;
llRequestPermissions(curr_pilot, PERMISSION_TAKE_CONTROLS);
// ------------------------------------------------------------------------*** STARTUP
llMessageLinked(LINK_SET,0,"runloop",NULL_KEY);
llSetTimerEvent(0.3);
// llSetTimerEvent(0.05);
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
}
else if( ( msg == "copilot" ) && (id != NULL_KEY) )
{
llSay(0, "FlightScript curr_pilot is set to: "+msg);
motor_x = 0.0; // PERCENTAGES of MOTOR THRUST
motor_y = 0.0;
motor_z = 0.0;
llMessageLinked(LINK_SET,0,"THROTTLE",NULL_KEY);
llMessageLinked(LINK_SET,0,"runup",NULL_KEY);
curr_pilot = id;
llRequestPermissions(curr_pilot, PERMISSION_TAKE_CONTROLS);
// ------------------------------------------------------------------------*** STARTUP
llMessageLinked(LINK_SET,0,"runloop",NULL_KEY);
llSetTimerEvent(0.3);
// llSetTimerEvent(0.05);
llSetStatus(STATUS_BLOCK_GRAB, TRUE);
}
}

run_time_permissions(integer perms)
{
if(perms & (PERMISSION_TAKE_CONTROLS))
{
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN | CONTROL_ML_LBUTTON, TRUE, FALSE);
}
else
{
//llUnSit(curr_pilot);
llSay(0, "No Pilot or CoPilot in control.");
}
}

control(key id, integer level, integer edge)
{

// Controls -------- Mousie
if ( ( level & CONTROL_ML_LBUTTON ) && ( edge & CONTROL_ML_LBUTTON ) )
{
llSay(0, "Mouse was clicked.");
}


// CONTROLS -------- Y-AXIS THRUST

if((edge & CONTROL_RIGHT) && (level & CONTROL_RIGHT))
{
motor_y = -1.0;
}

if((edge & CONTROL_RIGHT) && !(level & CONTROL_RIGHT))
{
motor_y = 0;
}

if((edge & CONTROL_LEFT) && (level & CONTROL_LEFT))
{
motor_y = 1.0;
}

if((edge & CONTROL_LEFT) && !(level & CONTROL_LEFT))
{
motor_y = 0;
}

// CONTROLS -------- X-AXIS THRUST =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= FORWARD THROTTLE

if ( ( motor_x > -0.05 ) && ( motor_x < 0.05 ) ) motor_x = 0.0;

if( (level & CONTROL_FWD) && (level & CONTROL_BACK) ) //FWD and BACK at once
{
if (motor_x != 0.0) // Avoid cloggin' the works
{
llMessageLinked(LINK_SET, 0, "THROTTLE", NULL_KEY);
}
motor_x = 0.0;
llResetTime();
}
else if((llGetTime() > 0.3) && (level & CONTROL_FWD))
{
llResetTime();
if (motor_x == 0.0 ) // Fresh start!
{
motor_x = motor_x + 0.1;
if (motor_x > 1.1) motor_x = 1.1;
llMessageLinked(LINK_SET,llRound(motor_x * 100),"THROTTLE",NULL_KEY);
}
else // Increment throttle!
{
motor_x = motor_x + 0.1;
if (motor_x > 1.1) motor_x = 1.1;// regular limiter
if ( ( motor_x > -0.05 ) && ( motor_x < 0.05 ) ) motor_x = 0.0;
if (motor_x == 0.0) llMessageLinked(LINK_SET,0,"THRUST_HORIZONTAL_END",NULL_KEY);
llMessageLinked(LINK_SET,llRound(motor_x * 100),"THROTTLE",NULL_KEY);
}
}
else if((llGetTime() > 0.4) && (level & CONTROL_BACK))
{
llResetTime();
if (motor_x == 0.0 ) // Fresh start!
{
motor_x = motor_x - 0.1;
if (motor_x < -0.6) motor_x = -0.6;
llMessageLinked(LINK_SET,llRound(motor_x * 100),"THROTTLE",NULL_KEY);
}
else // Increment throttle!
{
motor_x = motor_x - 0.1;
if (motor_x < -0.6) motor_x = -0.6;// regular limiter
if ( ( motor_x > -0.05 ) && ( motor_x < 0.05 ) ) motor_x = 0.0;
llMessageLinked(LINK_SET,llRound(motor_x * 100),"THROTTLE",NULL_KEY);
}
}


// CONTROLS -------- Z-AXIS THRUST

if((edge & CONTROL_UP) && (level & CONTROL_UP))
{
motor_z = 1.0;
}

if((edge & CONTROL_UP) && !(level & CONTROL_UP))
{
motor_z = 0.0;
}

if ((edge & CONTROL_DOWN) && (level & CONTROL_DOWN))
{
motor_z = -0.8;
}

if ((edge & CONTROL_DOWN) && !(level & CONTROL_DOWN))
{
motor_z = 0.0;
}
}

timer()
{
// ===== Linear Motors!
float motorx;
vector motor = ZERO_VECTOR;
if(motor_x > 1.0)
{
motorx = 1.0;
}
else
{
motorx = motor_x;
}
motor.x = FWD_THRUST * motorx;
motor.y = LATERAL_THRUST * motor_y;
motor.z = VERTICAL_THRUST * motor_z;

//ADJUST Z MOTOR FOR DISTANCE TO GROUND
vector pos = llGetPos();
float z_motor_t = motor.z;
if ( ((pos.z - llGround(ZERO_VECTOR)) < 15.0) && (motor.z < 0.0)) z_motor_t /= 3;
if ( ((pos.z - llGround(ZERO_VECTOR)) < 5.0) && (motor.z < 0.0)) z_motor_t /= 2;
if ( ((pos.z - llGround(ZERO_VECTOR)) < 2.0) && (motor.z < 0.0)) z_motor_t /= 2;
motor.z = z_motor_t;

//Apply the liniar motors
if(motor_x == 1.1)
{
llApplyImpulse(<15000,0,0>, TRUE);
motor.x = 39 * motorx;
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, motor);
}
else
{
llSetForce(<0,0,0>, TRUE);
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, motor);
}
}

on_rez(integer num)
{
llResetScript();
}
}
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 12:28
CODE
// sitCoPilot script to develop a Guest Pilot system for use in the secondlife Example Script development program
// URL = http://rpgstats.com/wiki/index.php?title=Examples
// Discussion URL at: /54/9e/256457/1.html
// By contributors on the secondlife "Scripting Tips" Forum

// This SitScript is developed from the:
// FLuer seat and control script
// By Jillian Callahan

//Please leave the credits intact!
//This script is NOT INTENDED FOR SALE! It's for learning about scripting!

string sitText = "CoPilot!"; // Replaces that "Sit" text in the pie menu
//vector sittingPosition = <0.36, 0.0, 0.41>; //This is the position. X, Y, Z This is what you need to mess with.
vector sittingPosition = <0.00, 0.0, 0.41>; //This is the position. X, Y, Z This is what you need to mess with.

key agentKey = NULL_KEY;
key copilot = NULL_KEY;
integer AUTHORIZED = FALSE;
integer permissionResult = FALSE;
integer RUNNING = FALSE;
integer HOLD = FALSE;
integer open = 0;

init()
{
llSay(0, "Init ing");
llSetCameraEyeOffset(<-9.0, 0.0, 3.0>);
llSetCameraAtOffset(<0.0, 0.0, 1.75>);
llSetSitText(sitText);
llSitTarget(sittingPosition,ZERO_ROTATION);
}


getauthorization(key avatar)
{
string agentName = llKey2Name(llDetectedKey(0)); // Get the name of the agent touching this.
llSay(0, agentName + "is seeking authorization");
// For now, just grant anyone Authorization to proceed.
AUTHORIZED = TRUE;
}


default
{
state_entry()
{
init();
}

on_rez(integer times)
{
init();
}
touch_start(integer num_times)
{ // Simply, elegantly handle attempts to touch the seat.
string agentName = llKey2Name(llDetectedKey(0)); // Get the name of the agent touching this.
getauthorization(copilot);
if(AUTHORIZED)
{
if(llDetectedKey(0) == llGetOwner())
{
llSay(0, "Welcome "+agentName+", you are Authorized to CoPilot this craft, seeing as you are the Owner.");
}
else
{
llSay(0, "Welcome "+agentName+", you are Authorized to CoPilot this craft.");
}
} else
{
llSay(0, "Sorry"+agentName+", you do not have authorization use this.");
}
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
key sitter = llAvatarOnSitTarget();
getauthorization(sitter);
if( (sitter != NULL_KEY) && (agentKey == NULL_KEY) ) // Fresh sit
{
if (AUTHORIZED == TRUE)
{
agentKey = sitter;
llListen(0, "", agentKey, "");
llOwnerSay("You have been Authorized, and are assuming the duties of CoPilot.");
}
else
{
llUnSit(sitter);
llSay(0, "Sorry, you do not have authorization to sit here.");
}
}
else if ( (sitter == NULL_KEY) && (agentKey != NULL_KEY) ) // Probably stand
{
llSay(0, "UnSitting");
if (RUNNING)
{
llSetTimerEvent(0.0);
llMessageLinked(1, 0, "copilot", NULL_KEY);
}
llResetScript();
}
}
}

listen(integer chan, string name, key id, string msg)
{
msg = llToLower(msg);
if ( msg == "start" )
{
llMessageLinked(1, 0, "copilot", agentKey); // Tell the main script who;s piloting
llSetStatus(STATUS_PHYSICS, TRUE);
llSetTimerEvent(0.5);
llOwnerSay("Say \"help\" for instructions.");
RUNNING = TRUE;
HOLD = FALSE;
}
else if ( msg == "stop" )
{
llSetTimerEvent(0.0);
llMessageLinked(1, 0, "copilot", NULL_KEY); // Tell the main script that we no longer have a pilot
llSetStatus(STATUS_PHYSICS, FALSE);
llOwnerSay("Shutdown complete.");
RUNNING = FALSE;
HOLD = FALSE;
}
else if ( msg == "h" )
{
if (RUNNING)
{
if (HOLD)
{
llSetStatus(STATUS_PHYSICS, TRUE);
llSetTimerEvent(0.5);
HOLD = FALSE;
llSay(0,"Hold released.");
}
else
{
llSetTimerEvent(0.0);
llSetStatus(STATUS_PHYSICS, FALSE);
HOLD = TRUE;
llSay(0,"Hold active!");
}
}
}
}

timer()
{
if (!llGetStatus(STATUS_PHYSICS)) // Checks to make sure physics is still on.
{
llSetPos(llGetPos() + <0.0, 0.0, 1.0>); // if not, move up one meter and try turning it on
llSetStatus(STATUS_PHYSICS, TRUE);
}
}
}
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 12:28
CODE
// sitPilot script to develop a Guest Pilot system for use in the secondlife Example Script development program
// URL = http://rpgstats.com/wiki/index.php?title=Examples
// Discussion URL at: /54/9e/256457/1.html
// By contributors on the secondlife "Scripting Tips" Forum

// This SitScript is developed from the:
// FLuer seat and control script
// By Jillian Callahan

//Please leave the credits intact!
//This script is NOT INTENDED FOR SALE! It's for learning about scripting!

string sitText = "Pilot!"; // Replaces that "Sit" text in the pie menu
//vector sittingPosition = <0.36, 0.0, 0.41>; //This is the position. X, Y, Z This is what you need to mess with.
vector sittingPosition = <0.00, 0.0, 0.41>; //This is the position. X, Y, Z This is what you need to mess with.

key agentKey = NULL_KEY;
key pilot = NULL_KEY;
integer AUTHORIZED = FALSE;
integer permissionResult = FALSE;
integer RUNNING = FALSE;
integer HOLD = FALSE;
integer open = 0;

init()
{
llSay(0, "Init ing");
llSetCameraEyeOffset(<-9.0, 0.0, 3.0>);
llSetCameraAtOffset(<0.0, 0.0, 1.75>);
llSetSitText(sitText);
llSitTarget(sittingPosition,ZERO_ROTATION);
}


getauthorization(key avatar)
{
string agentName = llKey2Name(llDetectedKey(0)); // Get the name of the agent touching this.
llSay(0, agentName + "is seeking authorization");
// For now, just grant anyone Authorization to proceed.
AUTHORIZED = TRUE;
}


default
{
state_entry()
{
init();
}

on_rez(integer times)
{
init();
}
touch_start(integer num_times)
{ // Simply, elegantly handle attempts to touch the seat.
string agentName = llKey2Name(llDetectedKey(0)); // Get the name of the agent touching this.
getauthorization(pilot);
if(AUTHORIZED)
{
if(llDetectedKey(0) == llGetOwner())
{
llSay(0, "Welcome "+agentName+", you are Authorized to Pilot this craft, seeing as you are the Owner.");
}
else
{
llSay(0, "Welcome "+agentName+", you are Authorized to Pilot this craft.");
}
} else
{
llSay(0, "Sorry"+agentName+", you do not have authorization use this.");
}
}
changed(integer change)
{
if(change & CHANGED_LINK)
{
key sitter = llAvatarOnSitTarget();
getauthorization(sitter);
if( (sitter != NULL_KEY) && (agentKey == NULL_KEY) ) // Fresh sit
{
if (AUTHORIZED == TRUE)
{
agentKey = sitter;
llListen(0, "", agentKey, "");
llOwnerSay("You have been Authorized, and are assuming the duties of Pilot.");
}
else
{
llUnSit(sitter);
llSay(0, "Sorry, you do not have authorization to sit here.");
}
}
else if ( (sitter == NULL_KEY) && (agentKey != NULL_KEY) ) // Probably stand
{
llSay(0, "UnSitting");
if (RUNNING)
{
llSetTimerEvent(0.0);
llMessageLinked(1, 0, "copilot", NULL_KEY);
}
llResetScript();
}
}
}

listen(integer chan, string name, key id, string msg)
{
msg = llToLower(msg);
if ( msg == "start" )
{
llMessageLinked(1, 0, "pilot", agentKey); // Tell the main script who;s piloting
llSetStatus(STATUS_PHYSICS, TRUE);
llSetTimerEvent(0.5);
llOwnerSay("Say \"help\" for instructions.");
RUNNING = TRUE;
HOLD = FALSE;
}
else if ( msg == "stop" )
{
llSetTimerEvent(0.0);
llMessageLinked(1, 0, "pilot", NULL_KEY); // Tell the main script that we no longer have a pilot
llSetStatus(STATUS_PHYSICS, FALSE);
llOwnerSay("Shutdown complete.");
RUNNING = FALSE;
HOLD = FALSE;
}
else if ( msg == "h" )
{
if (RUNNING)
{
if (HOLD)
{
llSetStatus(STATUS_PHYSICS, TRUE);
llSetTimerEvent(0.5);
HOLD = FALSE;
llSay(0,"Hold released.");
}
else
{
llSetTimerEvent(0.0);
llSetStatus(STATUS_PHYSICS, FALSE);
HOLD = TRUE;
llSay(0,"Hold active!");
}
}
}
}

timer()
{
if (!llGetStatus(STATUS_PHYSICS)) // Checks to make sure physics is still on.
{
llSetPos(llGetPos() + <0.0, 0.0, 1.0>); // if not, move up one meter and try turning it on
llSetStatus(STATUS_PHYSICS, TRUE);
}
}
}
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 12:35
hmmm.... too bad the Forum strips out our code indenting.

Again, my test platform, if you want to duplicate it is just two uniquely name 1 prim seats, a script in each, and a 10x10x.1 square root prim Flight Plate under them all linked with the FlightPlate as root.

I _think_ we need to focus on the FlightScript handling of incoming linked messages.

These scripts are very VERY similar to one of the most popular Flight Combat Systems in use in SL. If we can implement this Guest Pilot feature editing them as little as possible, then the result will likely fit snugly in with these popular flight combat systems to everyone's delight.

It occurred to me while assembling these that it is not a far off step to allow the CoPilot to go into something like "Gunner Mode" if the Pilot is currently in command of the Flight Controls. Meaning, if the the CoPilot commandeers one of the linkset mouselook guns... and if the CoPilot is in command of controls could the Pilot then go into Gunner mode? This is all really intruiging even if the end result craft has no guns involved at all.

Jump in and try these. And thanks already to those contributing.
Lear Cale
wordy bugger
Join date: 22 Aug 2007
Posts: 3,569
05-01-2008 18:08
PR, just *in case* LL ever turns the codes back on, please put
CODE
 ... 
tags around your code.

Folks on this forum mostly know, to see your code with indentation, they just hit the "quote" button. Try it!

It's a bit much code for me to pore over for grins; I code for a living, code for fun in SL, and code other stuff for hobbies, code code code ... and well, eventually I do get a little tired of it!
Jesse Barnett
500,000 scoville units
Join date: 21 May 2006
Posts: 4,160
05-01-2008 20:06
From: PR Noyes
Jesse,
What a delight and honor to have you looking into this. Your posts over the last few years in here have inspired me to contantly take on too much at once. That's a good thing, Jesse, a compliment. :)

OMG this is by far the nicest thing anyone has ever said about me and thank you sooooooo much!

Sorry I haven't had a chance to look at the code yet but I will! Have been installing Mojopac onto a 4 gig sd card and getting ThinInstall running on it and it is a chore. But the nice thing is I have also installed Mojopac onto a 160 gig external drive and now I can bring LSLEditor, VS2005, Scite, SL Nicholax version, MAYA, Autocad 2008, plus many more (and lets not forget my personal copy of the wiki :cool: ) with me anywhere.

Apologies for the geek speek but among other things this means I can run all of those programs without installing anything on the work computer or any other computer when I travel :p. Plus it should make lunch at work much more fun now.
_____________________
I (who is a she not a he) reserve the right to exercise selective comprehension of the OP's question at anytime.
From: someone
I am still around, just no longer here. See you across the aisle. Hope LL burns in hell for archiving this forum
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 20:48
From: Lear Cale
PR, just *in case* LL ever turns the codes back on, please put
CODE
 ... 
tags around your code.
Lear thank you. I'd not have done it without invitation. Etiquette on someone else's boards. Thank you.

From: Lear Cale
Folks on this forum mostly know, to see your code with indentation, they just hit the "quote" button. Try it!
Thanks again for the tip. now one more knows how helpful it is.

From: Lear Cale
It's a bit much code for me to pore over for grins; I code for a living, code for fun in SL, and code other stuff for hobbies, code code code ... and well, eventually I do get a little tired of it!
I pasted it complete for you and others to drop into a script in a primset and fly it. Just grab all three scripts and drop the sit scripts into two seats or boxes and the FlightScript into a larger root prim and she'll fly. Feeling it will start the simpler suggestions flowing. Give it a shot.

And thanks again.
PR Noyes
Registered User
Join date: 24 Jan 2008
Posts: 16
05-01-2008 20:51
Jesse,

Just pop those scripts in and tell me what you think. This is a foundation piece, striped to solve the Guest Pilot example for the Wiki.

And to others that have downloaded it. I'll do the work i you don't want to but I have so many plates in orbit right now I genuinely need discussion help to get this issue closed, and we all benefit.

Give it a shot and post your comments back here.

Thanks,
PR
Nectere Niven
Gadget Junky
Join date: 12 Jan 2007
Posts: 211
05-02-2008 22:26
I have a boat that gives a hud that kinda does this, it allows any of the passengers to be a "skipper" which allows them to take control of the boat and sail it (at the same time tho if I recall) - seems something like that might be useful in a plane as well - be a copilot or gunner or whatever the case may be. Unfortunetly I don't have access to these scripts in any sort of mod form to study, but the idea of it works pretty well in any case.

As an avid collector of SL planes and jets it will be interesting to see this project come to fruition.
_____________________
Every second of your life is a moment of opportunity to make it better than the last...