Jump to content

Need help for a balloon vehicul script


Alexander Mauclerc
 Share

You are about to reply to a thread that has been inactive for 2299 days.

Please take a moment to consider if this thread is worth bumping.

Recommended Posts

Hi i need help with a script! When i sit on the car i want it to be ready to move witout clicking on it. But i don't know how to make it work.. 

 

// Hot Air Balloon Script
// Modified version of the flying Saucer script
//
//
string animation = "crossleg"; // name of built-in animation or animation in prim inventory
string gSoundIdle = "Idle";
string gSoundStart = "Start2";

integer gOldSound=3; //variable for sound function
integer gNewSound=3;

float LINEAR_TAU = 0.75;
float TARGET_INCREMENT = 0.5;
float ANGULAR_TAU = 1.5;
float ANGULAR_DAMPING = 0.85;
float THETA_INCREMENT = 10;

integer KEYMASK = 0;
vector pos;
vector face;
float brake = 0.5;
key gOwnerKey;
string gOwnerName;
key Driver;
integer gFLYING = 0;
integer nudge = FALSE;
integer auto=FALSE;
integer CHANNEL = 6;
//---------------------------------------------------------------
help()
{
string chan = (string)CHANNEL;
llWhisper(0,"Commands:");
llWhisper(0,"Left click craft = Start ");
llWhisper(0,"Left click craft = Stop and release contol");
llWhisper(0,"/" + chan + " 1! through" + " /" + chan + " 9!," + " /" + chan + " slow = Set power");
llWhisper(0,"/" + chan + " menu = Display this list");
llWhisper(0,"PgUp or PgDn = Gain or lose altitude");
llWhisper(0,"Arrow keys = Left, right, Forwards and Back");
llWhisper(0,"Shift + Left or Right arrow = Rotate but maintain view");
llWhisper(0,"PgUp + PgDn or combination similar = Set cruise on or off");
}
//---------------------------------------------------------------
SetPhysics()
{
llSetStatus(STATUS_PHYSICS, TRUE);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, TRUE);
llSleep(0.1);
llSetStatus(STATUS_ROTATE_X | STATUS_ROTATE_Y, FALSE);
llSetStatus(STATUS_PHYSICS, FALSE);
llMoveToTarget(llGetPos(), 0);
llRotLookAt(llGetRot(), 0, 0);
llSetStatus(STATUS_PHYSICS, FALSE);
}
//---------------------------------------------------------------
SetPilotPosition()
{
llSetSitText("Pilot");
llSitTarget(<0.0, 0.0, 0.1>, ZERO_ROTATION);
}
//---------------------------------------------------------------
SetCamera()
{
llSetCameraEyeOffset(<-10.0, 0.0, 4.0>);
llSetCameraAtOffset(<0, 0.0, 0>);
}
//---------------------------------------------------------------
SetSpeed(float speed)
{
TARGET_INCREMENT = speed;
llWhisper(0,"Power: " + llGetSubString((string)(TARGET_INCREMENT * 10.0),0,3) + "%");
}
//---------------------------------------------------------------
handleKeys()
{
}
//---------------------------------------------------------------
Move()
{
pos *= brake; // Update position, effectively decays away 'speed'
if (pos.x < 0) { pos.x=0; } // Dont allow negative X values
else { pos.x += TARGET_INCREMENT; } // Speed increment
vector world_target = pos * llGetRot(); // Rotate into world co-ordinate system
llMoveToTarget(llGetPos() + world_target, LINEAR_TAU); // Move the vehicle
}
//---------------------------------------------------------------
CruiseMode()
{
if (auto)
{
auto=FALSE;
llWhisper(0,"Cruise off");
llSetTimerEvent(0.0);
}
else
{
auto=TRUE;
llWhisper(0,"Cruise on");
llSetTimerEvent(0.5);
}
llSleep(0.5);
}
//---------------------------------------------------------------
enginesound(){
vector vel = llGetVel();
float speed = llVecMag(vel);
if(speed <=10){
gNewSound = 0;
}
else if(speed >=50){
gNewSound = 2;
}
else {
gNewSound = 1;
}

if(gOldSound != gNewSound){
if(speed <=10){
llLoopSound(gSoundIdle,2.0);
}
else if(speed >=50){

}
else {

}
gOldSound = gNewSound;
}
}

default
{
state_entry()
{
gOwnerKey = llGetOwner(); // The Owner
gOwnerName = llKey2Name(llGetOwner()); // The Owners name (WHY, Never Used)

SetPilotPosition(); // Position of pilot's seat
SetCamera(); // Position camera

llSetTimerEvent(0.0);

SetPhysics();
// Which Keys we are interested in
KEYMASK = CONTROL_FWD | CONTROL_BACK | CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT | CONTROL_UP | CONTROL_DOWN | CONTROL_LEFT | CONTROL_RIGHT | CONTROL_ML_LBUTTON;

TARGET_INCREMENT = 0.5;

state Listening;
}
}
//---------------------------------------------------------------
state Listening
{
state_entry()
{
llWhisper(0,"Type /" + (string)CHANNEL + " menu for a list of options.");
llListen(CHANNEL, "", "", ""); // Listen to anyoen saying anything

}

on_rez(integer number) { llResetScript(); } // Reset The script if we rez, this ensures a good start up

changed(integer change)
{
if (change & CHANGED_LINK)
{
llWhisper(0,"if1");
key sitter = llAvatarOnSitTarget();
if(sitter != NULL_KEY) llRequestPermissions(sitter , PERMISSION_TRIGGER_ANIMATION);
else
{
key id = llDetectedKey(0);
if (id == Driver)
{
llWhisper(0,"Thank You for flying!");
gFLYING = 0;
auto=FALSE;
llSleep(1.5);
llSetSitText("Pilot");
llSetStatus(STATUS_PHYSICS, FALSE);
llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", gOwnerKey);
llSetTimerEvent(0.0);
llReleaseControls();
llStopSound();
llResetScript();
llStopSound();
}
}
}
}

run_time_permissions(integer perm)
{
if ( perm & PERMISSION_TRIGGER_ANIMATION )
{
llSetAlpha(0.0, ALL_SIDES); // hide prim
llStartAnimation(animation);
llStopAnimation("sit");

if (gFLYING == 0)
{

gFLYING = 1;
llSetStatus(STATUS_PHYSICS, TRUE);
llSetSitText("Ride");

Driver=llGetOwner();
llTriggerSound(gSoundStart,1.0);
llSleep(2.5);
enginesound();

state StateDriving;
}
else{llStopSound();}

}
}

//touch_start(integer total_number)
//{
// if (gFLYING == 0)
//{
//gFLYING = 1;
//llSetStatus(STATUS_PHYSICS, TRUE);
//llSetSitText("Ride");
//Driver=llDetectedKey(total_number - 1);
// llTriggerSound(gSoundStart,1.0);
// llSleep(2.5);
//enginesound();
// state StateDriving;
// }
// }

// Here is the Listen callback
listen(integer channel, string name, key id, string msg)
{
//if (llSameGroup(id)==1) // This is meant to only allow same group control but it fails
//{
string message = llToLower(msg);
if (message == "menu")
{
help();
}
//}
}
}
//---------------------------------------------------------------
state StateDriving
{
state_entry()
{
llRequestPermissions(Driver, PERMISSION_TAKE_CONTROLS);
llMoveToTarget(llGetPos(), LINEAR_TAU);
llRotLookAt(llGetRot(), ANGULAR_TAU, 1.0);
llListen(CHANNEL, "", Driver, "");
llMessageLinked(LINK_ALL_CHILDREN, 0, "light", gOwnerKey);

}

// Handles Key press events
control(key driver, integer keys, integer edges)
{
pos *= brake;
face.x *= brake;
face.z *= brake;
nudge = FALSE;

if (keys & CONTROL_FWD)
{
if (pos.x < 0) { pos.x=0; }
else { pos.x += TARGET_INCREMENT; }
nudge = TRUE;
}
if (keys & CONTROL_BACK)
{
if (pos.x > 0) { pos.x=0; }
else { pos.x -= TARGET_INCREMENT; }
nudge = TRUE;
}
if (keys & CONTROL_UP)
{
llMessageLinked(LINK_ALL_CHILDREN, 0, "fast", driver);
if(pos.z<0) { pos.z=0; }
else { pos.z += TARGET_INCREMENT; }
face.x=0;
nudge = TRUE;
}
if (keys & CONTROL_DOWN)
{
llMessageLinked(LINK_ALL_CHILDREN, 0, "fast", driver);
if(pos.z>0) { pos.z=0; }
else { pos.z -= TARGET_INCREMENT; }
face.x=0;
nudge = TRUE;
}
if ((keys) & (CONTROL_LEFT|CONTROL_ROT_LEFT))
{
if (face.z < 0) { face.z=0; }
else { face.z += THETA_INCREMENT; }
nudge = TRUE;
}
if ((keys) & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
if (face.z > 0) { face.z=0; }
else { face.z -= THETA_INCREMENT; }
nudge = TRUE;
}
if ((keys & CONTROL_UP) && (keys & CONTROL_DOWN))
{
CruiseMode();
}

if (nudge)
{
llWhisper(0,"ok6");
vector world_target = pos * llGetRot();
llMoveToTarget(llGetPos() + world_target, LINEAR_TAU);

vector eul = face;
eul *= DEG_TO_RAD;
rotation quat = llEuler2Rot( eul );
rotation rot = quat * llGetRot();
llRotLookAt(rot, ANGULAR_TAU, ANGULAR_DAMPING);
}
}

timer()
{
Move();
}


}

Link to comment
Share on other sites

Just at a quick glance, it looks like it should do that already.  You have disabled the touch_start event, so clicking won't do anything.  And the changed event triggers when you sit, and then requests permissions and goes to state driving.  Start adding llOwnerSay statements to see where script execution is going (and hanging up).

Link to comment
Share on other sites

Not only is the touch disabled but the movement appears to be controlled by variable executed on timer event and all the timers that I noticed are turned off (set to 0.0). There is one time the timer event is turned on, but, the variable defined as Auto has to be set to True and not seeing anywhere in the script that changes this variable from it's initial state of False..... granted I didn't look long or try the script out for myself... but on first glance that's what I observe.

 

I'd repair those two elements and see if that fixes your problem.

Link to comment
Share on other sites

yep, I see it too 

if (auto){auto=FALSE;llWhisper(0,"Cruise off");llSetTimerEvent(0.0);}else{auto=TRUE;llWhisper(0,"Cruise on");llSetTimerEvent(0.5);}llSleep(0.5);}

and also here in the changed event, it's changing it to FALSE when the avatar stands up. maybe it needs to be added to the event to change to true when the avatar sits? added it and bolded it in red. Also there's a llDetectedKey() in the changed event that shouldn't be there

 

changed(integer change){if (change & CHANGED_LINK){llWhisper(0,"if1");key sitter = llAvatarOnSitTarget();if(sitter != NULL_KEY) 
{
llRequestPermissions(sitter , PERMISSION_TRIGGER_ANIMATION);

}else{if (id == Driver){llWhisper(0,"Thank You for flying!");gFLYING = 0;llSleep(1.5);llSetSitText("Pilot");llSetStatus(STATUS_PHYSICS, FALSE);llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", gOwnerKey);llSetTimerEvent(0.0);llReleaseControls();llStopSound();llResetScript();llStopSound();}}}}

 

Link to comment
Share on other sites

also here, the timer is triggering the move function. does the:

 else {pos.x += TARGET_INCREMENT...

update the global variable, or does:

pos = <pos.x, pos.y,pos.z>; 

need to be added after adding the TARGET_INCREMENT for the global variable?

 

 

Move(){pos *= brake; // Update position, effectively decays away 'speed'if (pos.x < 0) { pos.x=0; } // Dont allow negative X valueselse 
{
pos.x += TARGET_INCREMENT;

} // Speed incrementvector world_target = pos * llGetRot(); // Rotate into world co-ordinate systemllMoveToTarget(llGetPos() + world_target, LINEAR_TAU); // Move the vehicle}

 

 

 

Link to comment
Share on other sites

You are about to reply to a thread that has been inactive for 2299 days.

Please take a moment to consider if this thread is worth bumping.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...