Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Motorcycle script and adding sound to it - Help

JR Breed
Registered User
Join date: 17 Jan 2006
Posts: 49
04-08-2006 15:24
This is probably the noobest guestion out of all noobs.

The motorcycle script is created by Cory Linden and modified by Andrew Linden.

In the script descritpion at the top it states "Sound triggers are commented out but not removed, so if you want sounds, just add the sounds to the cycle's contents and uncomment the triggers"

Now, I understand the "add the sounds to the cycles contents" but I have no clue what the rest mean. Ive edited scripts before but Ive never added sounds that are assocaited to a key binding before.

How would I add the start, idle (loop), and move forward (loop) sounds in dummy terms? A step by step example would be great!

Once again the script is called "Motorcycle Script" made by Cory Linden. Tweak and modified by Andrew Linden. Any and all help would be greatly apprecaited. =)
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-08-2006 16:29
If it says it's in the script but commented, then the script probably has lines like:

CODE
//llLoopSound("motor", 0.5);


... or whatever. Removing the two // characters from that line "uncomments" it, i.e. it changes it from being a comment (that does nothing) into a real line of code (that actually runs).

So look for those commented lines (they'll all start with //), and remove the // from the lines you want to uncomment.

Also, if you post the script here, someone might be able to point out the lines that need to be commented.
JR Breed
Registered User
Join date: 17 Jan 2006
Posts: 49
04-08-2006 17:22
I have no clue how to post a "PHP code" =( I'll post the portion I think that needs to be edited. I really hope this is it.

-------------------------------------------------------------------------------------------------------

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
// owner has mounted
llSay(0, "Get off my bike fool!";);
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
// not the owner ==> boot off
llSetStatus(STATUS_PHYSICS, TRUE);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
//llSound("start", 0.40, FALSE, FALSE);

// reset the global accumulators
gAngularMotor = <0, 0, 0>;
gLinearMotor = <0, 0, 0>;
gBank = 0.0;
}
}
else
{
// dismount
llSetStatus(STATUS_PHYSICS, FALSE);
llReleaseControls();
llStopAnimation("motorcycle_sit";);
//llSound("off", 0.4, FALSE, TRUE);
}
}

}

run_time_permissions(integer perm)
{
if (perm)
{
llStartAnimation("motorcycle_sit";);
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT
| CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP, TRUE, FALSE);
//llSound("on", 1.0, TRUE, TRUE);
}
}

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

--------------------------------------------------------------------------------------------------------

I see where it says "//||Sound("on", 1.0, TRUE, TRUE):" Problem is, Im not seeing anythign that says "//||LoopSound...."
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-08-2006 17:32
To post PHP code type [ php ] (without the spaces) at the beginning and [ / php ] (again, without the spaces) at the end.

llSound is an old function, and has been replaced by llPlaySound and llLoopSound. I guess this is an old script :) Here's what I would try, for starters. Take every line that you found...

CODE
llSound("SomeSoundFileName", SomeNumber, blah, blah...)


And replace it with the following 2 lines:

CODE

llStopSound();
llLoopSound("UseTheSameSoundFileName", UseTheSameNumber);


Leave the rest of the script as it is. See what that does.
JR Breed
Registered User
Join date: 17 Jan 2006
Posts: 49
04-08-2006 18:18
Thank you very much Ziggy =) I got the start sound to work along with the engine idle to work. Unfortainitly, there is no key binding (code, or what ever the proper term is) for forward throtle. I also found out what "comment and uncomment" means in scripting. Im really glad you took the time to help me and I greatly apprecaite that. Thank you very much Ziggy! =))
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-08-2006 18:30
From: JR Breed
Unfortainitly, there is no key binding (code, or what ever the proper term is) for forward throtle.


That would be in the control event handler...

CODE

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


That's the code that makes the bike move, so there's code in there that detects when the up arrow has been pressed, when it's been released, and so on. You'll have to add new code to turn off idle / turn on rev, and vice versa. Try it, if you're feeling adventurous :) It's probably not the easiest code to navigate though. Or post the control function's code here, and I can try to help you further.
JR Breed
Registered User
Join date: 17 Jan 2006
Posts: 49
04-08-2006 20:08
CODE
float gMaxTurnSpeed = 12;
float gMaxWheelieSpeed = 0;
float gMaxFwdSpeed = 30;
float gMaxBackSpeed = -10;
float gAngularRamp = 0.17;
float gLinearRamp = 0.2;

// These are true globals whose values are "accumulated" over
// multiple control() callbacks.
float gBank = 0.0;
vector gLinearMotor = <0, 0, 0>;
vector gAngularMotor = <0, 0, 0>;

default
{
state_entry()
{
// init stuff that never changes
llSetSitText("Ride Out");
llCollisionSound("", 0.0);
llSitTarget(<0.6, 0.05, 0.80>, ZERO_ROTATION);
llSetCameraEyeOffset(<-6.0, 0.0, 1.0>);
llSetCameraAtOffset(<3.0, 0.0, 1.0>);

// create the vehicle
llSetVehicleFlags(-1);
llSetVehicleType(VEHICLE_TYPE_CAR);
llSetVehicleFlags(VEHICLE_FLAG_LIMIT_MOTOR_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.8);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.8);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.3);

llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.8);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.4);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.01);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.35);

llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000, 100, 1000>);
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <100, 10, 100>);

llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.49);
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.44);

llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0);
llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.);
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0);

//llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, 2.0);
//llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 1.0);
//llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.5);
}

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
// owner has mounted
llSay(0, "Get off my bike fool!");
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
// not the owner ==> boot off
llSetStatus(STATUS_PHYSICS, TRUE);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
llSound("cb750", 1.0, FALSE, FALSE);

// reset the global accumulators
gAngularMotor = <0, 0, 0>;
gLinearMotor = <0, 0, 0>;
gBank = 0.0;
}
}
else
{
// dismount
llSetStatus(STATUS_PHYSICS, FALSE);
llReleaseControls();
llStopAnimation("motorcycle_sit");
llSound("car_idle", 0.4, FALSE, TRUE);
}
}

}

run_time_permissions(integer perm)
{
if (perm)
{
llStartAnimation("motorcycle_sit");
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT
| CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP, TRUE, FALSE);
llSound("car_idle", 1.0, TRUE, TRUE);
}
}

control(key id, integer level, integer edge)
{
// The idea here is to ramp up the motors when the keys are held down for a long
// time and to let the motors decay after they are let go. This allows fine-
// tuning of the motion of the vehicle by throttling the key controls.
//
// Note that this probably doesn't work well when the client FPS and/or the server
// FPS is lagging. So for best results you'll want to turn off as much visual
// effects as you can tolerate, and drive in the more empty areas.

// linear
integer key_control = FALSE;
if(level & CONTROL_FWD)
{
gLinearMotor.x = gLinearMotor.x + gLinearRamp * (gMaxFwdSpeed - gLinearMotor.x);
key_control = TRUE;
}
if(level & CONTROL_BACK)
{
gLinearMotor.x = gLinearMotor.x + gLinearRamp * (gMaxBackSpeed - gLinearMotor.x);
key_control = TRUE;
}
if (key_control)
{
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);
key_control = FALSE;
}
else
{
if (gLinearMotor.x > 15 || gLinearMotor.x < -5)
{
// Automatically reduce the motor if keys are let up when moving fast.
gLinearMotor.x *= 0.8;
llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, gLinearMotor);

}
else
{
// reduce the linear motor accumulator for the next control() event
gLinearMotor.x *= 0.8;
}

}

// angular
if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
{
gAngularMotor.x = gAngularMotor.x + gAngularRamp * (gMaxTurnSpeed - gAngularMotor.x);
key_control = TRUE;
}
if(level & (CONTROL_LEFT | CONTROL_ROT_LEFT))
{
gAngularMotor.x = gAngularMotor.x - gAngularRamp * (gMaxTurnSpeed + gAngularMotor.x);
key_control = TRUE;
}
if(level & CONTROL_UP)
{
gAngularMotor.y = gAngularMotor.y - gAngularRamp * (gMaxWheelieSpeed + gAngularMotor.y);
key_control = TRUE;
}
if (key_control)
{
// turn on banking and apply angular motor
gBank = 3.0;
llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, gBank);
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, gAngularMotor);
gAngularMotor *= 0.95; // light attenuation
}
else
{
if (gAngularMotor.x > 4
|| gAngularMotor.x < -4)
{
// We were turning hard, but no longer ==> reduce banking to help
// the motorcycle travel straight when bouncing on rough terrain.
// Also, turn off the angular motor ==> faster upright recovery.
gAngularMotor *= 0.4;
gBank *= 0.5;
llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, gBank);
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, gAngularMotor);
}
else
{
// reduce banking for straigher travel when not actively turning
gAngularMotor *= 0.5;
gBank *= 0.8;
llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, gBank);
}
}
}
}


This is the whole script. I only know how to edit scripts at a basic level. Adding new lines, where to put it, and what to type, I would have no idea. If you want to further help me, that would be great. If not totally understandable. Though I do want to learn, but not on somebodys expense. I tend to feel quilty.

I must have confused you about the forward throtle. It does move forward when I press "W". What I was meaning is that there is no option to add a sound effect when you press forward (i.e engine shifting and reving up as I press forward). Only sound options it has is collision, start, idle, and dismount. If you would like to help me with adding that feature that would be great. If its to complicated and technical to explain, I will understand. =)
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-08-2006 23:12
Hmm... not sure if this is going to work well at all, but you could try something like this at the end of the control(...) handler:

CODE

if (key_control)
{
llStopSound();
llLoopSound("engineRevSoundName", 0.5);
}
else
{
llStopSound();
llLoopSound("engineIdleSoundName", 0.5);
}


I'm no vehicle scripter though, so that's going to be very crude. Try asking someone who's worked on vehicles :)
JR Breed
Registered User
Join date: 17 Jan 2006
Posts: 49
04-09-2006 00:41
Well it worked but 1 problem........... When I press forward, it plays the sound, but it rapidly plays it. It only plays the first split second of the sound over and over while I have the button press.
Ziggy Puff
Registered User
Join date: 15 Jul 2005
Posts: 1,143
04-09-2006 08:44
Ah, right. See, I knew my first attempt wouldn't work :) Add a global variable to the top of the script:

CODE
integer revving = FALSE;


Make sure it gets initialized when the person gets on or off (new code added is in blue):

CODE

changed(integer change)
{
if (change & CHANGED_LINK)
{
key agent = llAvatarOnSitTarget();
if (agent)
{
if (agent != llGetOwner())
{
// owner has mounted
llSay(0, "Get off my bike fool!");
llUnSit(agent);
llPushObject(agent, <0,0,100>, ZERO_VECTOR, FALSE);
}
else
{
// not the owner ==> boot off
llSetStatus(STATUS_PHYSICS, TRUE);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
llSound("cb750", 1.0, FALSE, FALSE);

// reset the global accumulators
gAngularMotor = <0, 0, 0>;
gLinearMotor = <0, 0, 0>;
gBank = 0.0;
revving = FALSE;
}
}
else
{
// dismount
llSetStatus(STATUS_PHYSICS, FALSE);
llReleaseControls();
llStopAnimation("motorcycle_sit");
llSound("car_idle", 0.4, FALSE, TRUE);
revving = FALSE;
}
}

}


Then change the code in the control handler to:

CODE

if (key_control && !revving)
{
llStopSound();
llLoopSound("engineRevSoundName", 0.5);
revving = TRUE;
}
else if (!key_control && revving)
{
llStopSound();
llLoopSound("engineIdleSoundName", 0.5);
revving = FALSE;
}


See if that gets the rev/idle sound changes to work better :) It might act a little funky, where if you hold down the left or right arrow while the bike is still, it'll probably still play the rev sound.