Skate Script

Expired

This is a motorcycle script thast has been modified for skates

//Basic Motorcycle Script
//
// by Cory
// commented by Ben

//The new vehicle action allows us to make any physical object in Second Life a vehicle. This script is a good example of a 
// very basic vehicle that is done very well.  

integer loopsnd = 0;

default
{   

    //There are several things that we need to do to define vehicle, and how the user interacts with it.  It makes sense to 
    // do this right away, in state_entry.
    state_entry()
    {
        
        //We can change the text in the pie menu to more accurately reflecet the situation.  The default text is "Sit" but in 
        // some instances we want you to know you can drive or ride a vehicle by sitting on it. The llSetSitText function will
        // do this.
        llSetSitText("Skate");
        
        //Since you want this to be ridden, we need to make sure that the avatar "rides" it in a acceptable position
        // and the camera allows the driver to see what is going on. 
        //
        //llSitTarget is a new function that lets us define how an avatar will orient itself when sitting.
        // The vector is the offset that your avatar's center will be from the parent object's center.  The
        // rotation is bassed off the positive x axis of the parent. For this motorcycle, we need you to sit in a way
        // that looks right with the motorcycle sit animation, so we have your avatar sit slightly offset from the seat.
        llSitTarget(<0.3, 0.0, 0.40>, ZERO_ROTATION);
        
        
        llSetCameraEyeOffset(<-9.0, -0.00, 4.0>);
        llSetCameraAtOffset(<3 .0, 0.0, 2.0>);
        
        
        llSetVehicleFlags(-1);
        llSetVehicleType(VEHICLE_TYPE_CAR);
        
        llSetVehicleFlags(VEHICLE_FLAG_NO_FLY_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
        
        
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.80);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.10);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.10);
        
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.3);
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.2);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.3);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.1);
        
        
        llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000 .0, 2.0, 1000.0>);
        llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10 .0, 10.0, 1000.0>);
        
       
        llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.90);
        llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.90);
        
        
        llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.05);
        llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1);
        
        llCollisionSound("", 0.0);
    }
    
    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
                {
                    llSetStatus(STATUS_PHYSICS, TRUE);
                    llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
                }
            }
            else
            {
                llSetStatus(STATUS_PHYSICS, FALSE);
                llReleaseControls();
                llStopAnimation("sit");
            }
        }
        
    }
    
    run_time_permissions(integer perm)
    {
        if (perm)
        {
            llStartAnimation("surf");
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT, TRUE, FALSE);
        }
    }
    control(key id, integer level, integer edge)
    {
        
        vector angular_motor;

        if (level & edge & CONTROL_FWD)
        {
            
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <50 ,0,0>);
            
        }
        else if ((edge & CONTROL_FWD) && ((level & CONTROL_FWD) == FALSE))
        {
            
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,0>);
            
            loopsnd = 0;
        }
        else if (level & CONTROL_FWD)
        {
            
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <50 ,0,0>);
            
           
        }
        
        if(level & CONTROL_BACK)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <-10,0,0>);
        }
        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {
            angular_motor.x += 100;
            angular_motor.z -= 100;
        }
        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {
            angular_motor.x -= 100;
            angular_motor.z += 100;
        }
        if(level & (CONTROL_UP))
        {
            angular_motor.y -= 50;
        }
    
        llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
    }
    
}

 

Realistic Helicopter Script

Expired

// RealHeli by Apotheus Silverman
// An advanced, semi-realistic helicopter vehicle script for Second Life.
// This product is released open source. Please give due credit in
// derivative works. :-)
//
// This behavior script is based on my experience with helicopter flight in
// Microsoft Flight Simulator and the included vehicle object is based on
// the Hughes 500 model helicopter.
//
// This vehicle can only be controlled properly in mouselook.
//
// Helicopter controls:
// left/right - tail rotor / rudder
// pgup/pgdn - collective
// mouse - yoke

key currentAgent = NULL_KEY;

float minSoundVolume = 0.4;
float maxSoundVolume = 1.0;

float ROTATION_RATE = 2.0; // Rate of turning
float FWD_THRUST = 20; // Forward thrust motor force
float BACK_THRUST = 7; // Backup thrust
float VERTICAL_THRUST = 7;
// Keep a running linear motor value for better response
vector linear_motor = <0,0,0>;

float collective = 0.0;
float oldCollective = 0.0;
float myMass;
string currentRegion;
vector currentVel;

vector reference_frame = <0,0,0>;

default {
state_entry() {
llPreloadSound("hughes 500");

llSitTarget(<0.88, 0.0, 0.4>, ZERO_ROTATION);
llSetCameraEyeOffset(<-7.0, 0.0, 3.0>);
llSetSitText("Fly");
llSetCameraAtOffset(<0, 0, 1>);

// Reset flags that can get set from other scripts
llSetBuoyancy(0.0);

//hover
llSetVehicleType(VEHICLE_TYPE_AIRPLANE);
llRemoveVehicleFlags(VEHICLE_FLAG_LIMIT_ROLL_ONLY| VEHICLE_FLAG_CAMERA_DECOUPLED);

llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME, llEuler2Rot(reference_frame * DEG_TO_RAD));
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.9);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.1);
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 30);
llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 1000);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.5);
llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.5);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 120);
llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000 ,1000,1000>);
llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <2 ,2,20>);
llSetVehicleFloatParam(VEHICLE_BUOYANCY, 0.0);
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.2);
llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2.0);
llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.0);
llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.0);
llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.05);

// Hover mode (mouselook)
llRemoveVehicleFlags(VEHICLE_FLAG_MOUSELOOK_STEER) ;
llSetVehicleFlags(VEHICLE_FLAG_MOUSELOOK_BANK);
llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <2 , 2.5, 0>);
}

touch_start(integer num) {
//llWhisper(0, "Buy me! Right click and choose 'Buy' then take me out of your inventory to fly!");
}

changed(integer change) {
if (change & CHANGED_LINK) {
key agent = llAvatarOnSitTarget();
if (agent) {
if (agent != llGetOwner()) {
// only the owner can use this vehicle
llSay(0, "You aren't the owner of this vehicle.");
llUnSit(agent);
llPushObject(agent, <0,0,10>, ZERO_VECTOR, FALSE);
} else if (currentAgent == NULL_KEY) {
// driver is entering the vehicle
llSetStatus(STATUS_PHYSICS, TRUE);
llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
currentRegion = llGetRegionName();
currentVel = llGetVel();
llSetTimerEvent(1.0);
llMessageLinked(LINK_SET, 1, "hud", NULL_KEY);
llLoopSound("hughes 500", minSoundVolume);
}
} else if (currentAgent) {
// driver is getting up
currentAgent = NULL_KEY;
llStopSound();
llSetStatus(STATUS_PHYSICS, FALSE);
llStopAnimation("driving generic");
llReleaseControls();
llSetTimerEvent(0.0);
llMessageLinked(LINK_SET, 0, "hud", NULL_KEY);
}
}
}

run_time_permissions(integer perm) {
if (perm) {
currentAgent = llAvatarOnSitTarget();
llStartAnimation("driving generic");
myMass = llGetMass();
collective = 7.3;
llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
}
}

timer() {
// Check for and attempt to correct bad sim border crossing
string newRegion = llGetRegionName();
if (newRegion != currentRegion) {
llApplyImpulse((currentVel - llGetVel()) * myMass, FALSE);
currentRegion = newRegion;
llSleep(0.2);
}


// Update VEHICLE_ANGULAR_DEFLECTION_TIMESCALE based on current velocity to simulate drag on the tail
currentVel = llGetVel();
float timescale = llVecMag(currentVel) * -0.05 + 0.7;
if (timescale <0.01) {
timescale = 0.01;
}
llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, timescale);
// Simulate drag
llApplyImpulse(-currentVel * 0.3, FALSE);
}

control(key id, integer level, integer edge) {
if (level & CONTROL_LEFT) {
llApplyRotationalImpulse(<0,0,2> * myMass, TRUE);
}
if (level & CONTROL_RIGHT) {
llApplyRotationalImpulse(<0,0,-2> * myMass, TRUE);
}

if (level & CONTROL_UP) {
collective += 0.25;
}
if (level & CONTROL_DOWN) {
collective -= 0.25;
}
if (oldCollective != collective) {
//llWhisper(0, "Collective " + (string)collective);
if (llFabs(collective - 9.8) <0.1) {
// Make sure we can always hover
collective = 9.8;
}
if (collective > 12.8) {
collective = 12.8;
} else if (collective <7.3) {
collective = 7.3;
}
llSetForce(<0, 0, collective> * llGetMass(), TRUE);
llMessageLinked(LINK_SET, (integer)(((collective - 7.3) / 5.5) * 100.0), "throttle", NULL_KEY);
llAdjustSoundVolume(((collective - 7.3) / 5.5) * (maxSoundVolume - minSoundVolume) + minSoundVolume);
}
oldCollective = collective;
}
}

 

Motorcycle Script

Expired

default
{
    state_entry()
    {
        llSetSitText("Ride");
        llSitTarget(<0.6, 0.05, 0.20>, ZERO_ROTATION);
        llSetCameraEyeOffset(<-5.0, 0.0, 2.0>);
        llSetCameraAtOffset(<3 .0, 0.0, 2.0>);
        llSetVehicleFlags(-1);
        llSetVehicleType(VEHICLE_TYPE_CAR);
        llSetVehicleFlags(VEHICLE_FLAG_NO_FLY_UP | VEHICLE_FLAG_LIMIT_ROLL_ONLY);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.2);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.80);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 0.10);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 0.10);
         
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 1.0);
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.2);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.5);
        
        
        llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1000 .0, 2.0, 1000.0>);
        llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <10 .0, 10.0, 1000.0>);
        
        
        llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.50);
        llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 0.50);
        
        llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 0.99);
        llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.01);
    }
    
    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
                {
                    llSetStatus(STATUS_PHYSICS, TRUE);
                    llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
                }
            }
            else
            {
                llSetStatus(STATUS_PHYSICS, FALSE);
                llReleaseControls();
                llStopAnimation("motorcycle_sit");
            }
        }
        
    }
    
    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, TRUE, FALSE);
        }
    }
    control(key id, integer level, integer edge)
    {
        vector angular_motor;

        if(level & CONTROL_FWD)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <200 ,0,0>);
        }
        if(level & CONTROL_BACK)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <-10,0,0>);
        }
        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {
            angular_motor.x += 100;
            angular_motor.z -= 100;
        }
        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {
            angular_motor.x -= 100;
            angular_motor.z += 100;
        }
        if(level & (CONTROL_UP))
        {
            angular_motor.y -= 50;
        }
    
        llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
    }
    
}

 

Motorcycle Wheel:

 

default
{
    state_entry()
    {
        llSetTimerEvent(0.20);
    }
    timer()
    {
        vector vel = llGetVel();
        float speed = llVecMag(vel);
        llSetTextureAnim(ANIM_ON | SMOOTH | LOOP, 0, 0, 0, 0, 1, speed*0.5);
    }
}

 

 

Jetski V2.1

Expired

vector angular_motor;
float speed=0;
float lift = 0.04;
float tilt=15;
float turn=1.0;
vector moving;
integer turnnow = FALSE;
integer ts = FALSE;
integer cs = FALSE;
integer sit=FALSE;
vector velocity=<0,0,0>;
vector impulse;
float turbo=10;
string Bname; // Name of Vehicle
integer own=FALSE;
float volume=1.0;
key passenger;
key driver;

help()
{
    llWhisper(0,"Key Actions:");
    llWhisper(0,"Right click and 'Ride' <-- Starts " + Bname);
    llWhisper(0,"Click STAND UP button <-- Stops " + Bname + " and returns contols");
    llWhisper(0,"W or Forward <-- Accelerates or goes faster forwards");
    llWhisper(0,"S or Backwards <-- Slows or goes faster backwards");
    llWhisper(0,"W or Forward & S or Backwards <-- Brakes or stops the " + Bname);
    llWhisper(0,"E or Page up <-- Toggles on and off Turbo Mode");
    llWhisper(0,"C or Page down <-- Toggles on and off Cruise mode");
    llWhisper(0,"A or Left <-- Turns left");
    llWhisper(0,"D or Right <-- Turns right");
}

default
{
    state_entry()
    {
        Bname=llGetObjectName();
        llWhisper(0,"Preparing " + Bname);
        llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", NULL_KEY);
        llSetStatus(STATUS_PHYSICS, FALSE);
        llStopSound();
        llSetTimerEvent(0.0);
        velocity = <10, 0, 0>;
        turnnow = FALSE;
        ts = FALSE;
        cs = FALSE;
        llCollisionSound("", 0.0);
        llSitTarget(<-0.4,0.05,0.7>, <0,0.0,0,1>);
        llSetCameraEyeOffset(<-9.0, 0.0, 3.0>);
        llSetCameraAtOffset(<0.0, 0.0, 1.0>);
        llPreloadSound("Ducati Idle");
        llPreloadSound("D0");
        llPreloadSound("D1");
        llPreloadSound("D2");
        llPreloadSound("D3");
        llPreloadSound("D4");
        llPreloadSound("D5");
        llPreloadSound("D6");
        llSetSitText("Ride");
        llSetVehicleFlags(-1);
        llSetVehicleType(VEHICLE_TYPE_BOAT);
        llSetVehicleFlags(VEHICLE_FLAG_HOVER_UP_ONLY | VEHICLE_FLAG_HOVER_WATER_ONLY);
        llRemoveVehicleFlags( VEHICLE_FLAG_HOVER_TERRAIN_ONLY 
                              | VEHICLE_FLAG_LIMIT_ROLL_ONLY 
                              | VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT);
        llSetVehicleVectorParam( VEHICLE_LINEAR_FRICTION_TIMESCALE, <8 , 3, 2> );
        llSetVehicleFloatParam( VEHICLE_ANGULAR_FRICTION_TIMESCALE, 2 );
        llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_TIMESCALE, 2 );
        llSetVehicleFloatParam( VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 60 );
        llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_TIMESCALE, 1 );
        llSetVehicleFloatParam( VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 5 );
        llSetVehicleFloatParam( VEHICLE_HOVER_HEIGHT, 0.15);
        llSetVehicleFloatParam( VEHICLE_HOVER_EFFICIENCY,.5 );
        llSetVehicleFloatParam( VEHICLE_HOVER_TIMESCALE, 2.0 );
        llSetVehicleFloatParam( VEHICLE_BUOYANCY, 0.5 );
        llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.5 );
        llSetVehicleFloatParam( VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 3 );
        llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.5 );
        llSetVehicleFloatParam( VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 10 );
        llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5 );
        llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2 );
        llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 1 );
        llSetVehicleFloatParam( VEHICLE_BANKING_MIX, 0.1 );
        llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, .5 );
        llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
        llWhisper(0,Bname + " is now ready to ride");
    }
    
    touch(integer total_number)
    {
        key owner=llGetOwner();
        if (llDetectedKey(0)==owner)
        {
            help();
        }
        else
        {
            llWhisper(0,llDetectedName(0) + ", Please step away from the " + Bname);
        } 
    }
    
    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            llStopSound();
            llSetStatus(STATUS_PHYSICS, FALSE);
            driver = llAvatarOnSitTarget();
            if (driver)
            {
                if (driver != llGetOwner() && own==FALSE)
                {
                    string ownername=llKey2Name(llGetOwner());
                    string sitter=llKey2Name(driver);
                    llWhisper(0,sitter + ", you may only drive the " + Bname + " after " + ownername + " is seated");
                }
                if(driver == llGetOwner())
                {
                    //llWhisper(0,"1" + (string)own);
                    own=TRUE;
                }
                llSetTimerEvent(0.1);
            }
            else
            {
                llSetTimerEvent(0.0);
                //llWhisper(0,"4" + (string)own);
                own=FALSE; 
                llStopAnimation("motorcycle_sit");
                llMessageLinked(LINK_ALL_CHILDREN, 0, "stop", NULL_KEY);
                llSetStatus(STATUS_PHYSICS, FALSE);
                llReleaseControls();
                llStopSound();
                sit=FALSE;
                ts = FALSE;
                cs = FALSE;
            }
        }
        
    }
    
    run_time_permissions(integer perm)
    {
        if (perm && own)
        {
            //llWhisper(0,"3" + (string)own);
            sit=TRUE;
            speed=0;
            ts = FALSE;
            cs = FALSE;
            llStopAnimation("sit");
            llStartAnimation("motorcycle_sit");
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN, TRUE, FALSE);
        }
    }
    
    control(key id, integer level, integer edge)
    {
        if(level & CONTROL_FWD)
        {
            if(ts)
            {
                if(velocity.x <100)
                {
                    if(cs == FALSE) { velocity.x += (turbo * 3);}
                    else { velocity.x += turbo;}
                    speed = 0; 
                }   
            }
            else
            {    
                if(speed < 35)
                {
                    if(cs == FALSE) { speed += 5;}
                    else { speed += 1; }
                    
                }
            }
        }
        if(level & CONTROL_BACK)
        {
            if(ts)
            {
                if(velocity.x > 0)
                {
                    velocity.x -= turbo; 
                }   
                else 
                {
                    velocity.x = 0;
                    speed = 0;
                }
            }        
            if(speed > -15 && velocity.x <1)
            {
                speed -= 3;
            }
        }
        if((level & CONTROL_BACK) && (level & CONTROL_FWD))
        {
            speed=0;
            velocity=<0,0,0>;
        }
        if(level & CONTROL_UP)
        {
            if(ts)
            {
                llWhisper(0,"Turbo off");
                ts = FALSE;
                lift=0.04;
                speed=0;
                turn=1.0;
                velocity=<0,0,0>;
            }
            else
            {
                llWhisper(0,"Turbo on");
                ts = TRUE;
                lift=0.08;
                speed=0;
                turn=2.0;
                velocity=<0,0,0>;
            }
        }
        if(level & CONTROL_DOWN)
        {
            if(cs)
            {
                llWhisper(0,"Cruise off");
                cs = FALSE;
                speed=0;
                velocity=<0,0,0>;
            }
            else
            {
                llWhisper(0,"Cruise on");
                cs = TRUE;
                speed=0;
                velocity=<0,0,0>;
            }
        }
        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {
            turnnow = TRUE;
            angular_motor.x += tilt;
            angular_motor.z -= turn;
        }
        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {
            turnnow = TRUE;
            angular_motor.x -= tilt;
            angular_motor.z += turn;
        }
        
    }
    
    timer()
    {
        if (sit==FALSE)
        {
            if(own)
            {
                llSetStatus(STATUS_PHYSICS, TRUE);
                llRequestPermissions(driver,PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
                llLoopSoundMaster("Ducati Idle",volume - 0.5);
                llMessageLinked(LINK_ALL_CHILDREN, 0, "start", NULL_KEY);
            }
        }
        else if(sit)
        {
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, ZERO_VECTOR);
            if(turnnow)
            {
                llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
                angular_motor = ZERO_VECTOR;
                turnnow = FALSE;
            }
            
            if((velocity.x > 9) || (speed > 1))
            {
                llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, lift, 0, 1> );
            }
            else
            {
                llSetVehicleRotationParam( VEHICLE_REFERENCE_FRAME, <0, 0, 0, 1> );
            }
            
            if(ts) { llApplyImpulse( velocity, TRUE ); }
            else
            {
                llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, ); 
            }   
            moving=llGetVel(); 
            float total = llVecMag(moving);
            if (total <1)
            {
                llLoopSoundSlave("Ducati Idle",volume - 0.5);
            }
            else if (total < 3) 
            {
                llLoopSoundSlave("D0",volume);
            }
            else if (total < 6) 
            {
                llLoopSoundSlave("D1",volume);
            }
            else if (total < 9) 
            {
                llLoopSoundSlave("D2",volume);
            }
            else if (total < 12) 
            {
                llLoopSoundSlave("D3",volume);
            }
            else if (total < 15) 
            {
                llLoopSoundSlave("D4",volume);
            }
            else if (total < 18) 
            {
                llLoopSoundSlave("D5",volume);
            }
            else if (total > 17) 
            {
                llLoopSoundSlave("D6",volume);
            }
            if(cs == FALSE)
            {
                speed *= 0.75;
                velocity.x *= 0.75;
            }
                
        }
    }
    
    link_message(integer sender_num, integer num, string str, key id)
    {
        if(num==21)
        {
            passenger=str;
            sit=FALSE;
            if(passenger == llGetOwner())
            {
                own=TRUE;
            }
        }
        else if(num==20)
        {
            if(passenger == llGetOwner())
            {
                own=FALSE;
            }
            passenger=NULL_KEY;
            sit=FALSE;
        }
    }
    
    on_rez(integer start_param)
    {
        llResetScript();
    } 
}