Free SL Scripts

  • Increase font size
  • Default font size
  • Decrease font size
Vehicle

Flight Script

E-mail Print PDF
// Simple airplane script example 
Read more...
 

Helicopter Script

E-mail Print PDF
// Script to fly a helicopter in Second Life
Last Updated on Sunday, 08 March 2009 19:38 Read more...
 

Lift script v 1.0

E-mail Print PDF

// This script will allow you to make any prim a lift or an elevator.

Last Updated on Sunday, 08 March 2009 19:00 Read more...
 

Basic Motorcycle Script

E-mail Print PDF
// Detailed script for beginners to set vehicle type, camera position, vehicle flags, ...
Last Updated on Monday, 09 March 2009 20:55 Read more...
 

Car script

E-mail Print PDF
// Script that controls a car or other land-based vehicules in Second Life. 
Read more...
 

Motorcycle script

E-mail Print PDF

// example motorcycle script. Oiginally written by Cory Linden.
// Then modified and tweaked by Andrew Linden for the forum script library.

// Retrieved from from Free SL Scripts on http://www.freeSLscripts.com or www.gendersquare.org/sl
// Root prim should be oriented such that its local X-, Y- and Z-axes are
// parallel to forward, left, and up respectively.
//
// 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.
//
// Be careful when changing parameters.  Some of them can be very
// sensitive to change, such that a change of less than 5% can have a
// noticable effect.  You can tell some (but not necessarily all) of the
// more sensitive settings in this example by looking for the ones that
// have been set to double precission.  Changing only one at a time is a
// good idea.
//
// The geometry of the motorcycle itself can have significant impact on
// whether it in a straight line when not trying to turn.  For best results
// use asymmetric design with as wide of a base as you can tolerate.

// These are globals only for convenience (so when you need to modify
// them you need only make a single change).  There are other magic numbers
// below that have not yet been pulled into globals.
float gMaxTurnSpeed = 12;
float gMaxWheelieSpeed = 5;
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");
    llCollisionSound("", 0.0);
    llSitTarget(<0.6, 0.05, 0.20>, 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,   3.0);
    llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 0.7);
    llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.01);

    //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, "You aren't the owner");
          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);
          //llPlaySound("start", 0.40);

          // 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");
        //llPlaySound("off", 0.4);
      }
    }

  }

  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);
      //llLoopSound("on", 1.0);
    }
  }

  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 straighter travel when not actively turning
        gAngularMotor *= 0.5;
        gBank *= 0.8;
        llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY,  gBank);
      }
    }
  }
}

 

 

Motor Yacht v0.82

E-mail Print PDF

// Fixit Galatea generic boat script

// Retrieved from from Free SL Scripts on http://www.freeSLscripts.com or www.gendersquare.org/sl
// Motor Yacht v0.82
// This script uses the basic direction keys for boat operation and requires
// the final prim to be oriented at rotation <0, 0, 0>. The handling 
// Version of this script
float version = 0.82;

//****************************************************************************
//****************************************************************************
//****************************************************************************
//* The following items can be edited in this script. See the comment for each
//* item to see how it work when it is changed.
//****************************************************************************

//* When the forward key is pressed and the mouse button is pressed at the
//* same time, this speed is used. This number should be between 0.0 and 30.0,
//* with higher numbers giving faster performance.
float fastspeed = 30;

//* When the forward key is pressed and the mouse button is NOT pressed, this
//* speed is used. This number should be between 0.0 and whatever the
//* fastspeed value was set at, with higher numbers giving faster performance.
float slowspeed = 30;

//* This is the reverse speed. It shouldn't be too fast, but can be between
//* 0.0 and 30.0.
float backspeed = 10.0;

//* This is the vehicle 'hover' height, or how far it sits out of the water.
//* Adjust this as necessary for your boat.
float floatheight = 0.75;

//* If the boat is to ramp up speed slowly, set the following value to '1'.
//* Otherwise, the board will instantly reach full speed when the forward
//* key is pressed.
integer fastforward = 0;  // NOT IMPLEMENTED YET

//* Turning speed, a small turning speed is best
float turnspeed = 1.5;

//* If the boat 'angles' into turns, set the following value to '1'.
//* Otherwise, the boat will do flat turns.
integer angledturn = 5;   // NOT IMPLEMENTED YET

//* Height offset of seat
vector seatheight = <0.5, -0.55, 0.35>;

//* Viewing position
vector viewpos = <-10, 0, 3>;

//****************************************************************************

// Initialize the vehicle as a boat
vehicle_init()
{
    llSetVehicleType(VEHICLE_TYPE_BOAT);

    // least for forward-back, most friction for up-down
    llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <10, 1, 3>);

    // uniform angular friction (setting it as a scalar rather than a vector)
    llSetVehicleFloatParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, 0.1);

    // linear motor wins after about five seconds, decays after about a minute
    llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, 0.1);
    llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 0.05);

    // agular motor wins after four seconds, decays in same amount of time
    llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, <0, 0, 0>);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, 0.1);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, 0.2);

    // hover
    llSetVehicleFloatParam(VEHICLE_HOVER_HEIGHT, floatheight);
    llSetVehicleFloatParam(VEHICLE_HOVER_EFFICIENCY, 0.2);
    llSetVehicleFloatParam(VEHICLE_HOVER_TIMESCALE, 0.4);
    llSetVehicleFloatParam(VEHICLE_BUOYANCY, 1.0);

    // Slight linear deflection with timescale of 1 seconds
    llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, 0.1);
    llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 1);

    // Slight angular deflection
    llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, 0.1);
    llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 6);

    // somewhat bounscy vertical attractor
    llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 0.5);
    llSetVehicleFloatParam(VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 1);

    // weak negative damped banking
    llSetVehicleFloatParam(VEHICLE_BANKING_EFFICIENCY, 1.0);
    llSetVehicleFloatParam(VEHICLE_BANKING_MIX, 1.0);
    llSetVehicleFloatParam(VEHICLE_BANKING_TIMESCALE, 0.1);

    // default rotation of local frame
    llSetVehicleRotationParam(VEHICLE_REFERENCE_FRAME,
        llEuler2Rot(<0, 0, 0>));

    // remove these flags
    llRemoveVehicleFlags(VEHICLE_FLAG_HOVER_TERRAIN_ONLY
                         | VEHICLE_FLAG_LIMIT_ROLL_ONLY
                         | VEHICLE_FLAG_HOVER_GLOBAL_HEIGHT);
    // set these flags
    llSetVehicleFlags(VEHICLE_FLAG_NO_DEFLECTION_UP
                      | VEHICLE_FLAG_HOVER_WATER_ONLY
                      | VEHICLE_FLAG_HOVER_UP_ONLY
                      | VEHICLE_FLAG_LIMIT_MOTOR_UP);
}

// Setup everything
all_setup()
{
    // Display version number
//    llWhisper(0, "Motor Yacht script " + (string) version);
    llSetStatus(STATUS_PHYSICS, FALSE);

    // Set sit direction (forward) and sight location slightly up and behind
    llSitTarget(seatheight, llEuler2Rot(<0, 0, 0>));
    llSetCameraAtOffset(<6, 0, 6>);
    llSetCameraEyeOffset(viewpos);
    llSetSitText("Ride!");

    // Initialize vehicle states
    vehicle_init();

    // Set up listener callback function
    llListen(0, "", llGetOwner(), "");
}

// State (default) event handlers
default
{
    state_entry()
    {
        all_setup();
    }

    on_rez(integer start_param)
    {
        llSetStatus(STATUS_PHYSICS, FALSE);
    }

     run_time_permissions(integer permissions)
    {
        // Get user permissions
        if ((permissions & PERMISSION_TAKE_CONTROLS) ==
            PERMISSION_TAKE_CONTROLS)
        {
            llTakeControls(CONTROL_ML_LBUTTON | CONTROL_FWD |
                CONTROL_BACK | CONTROL_LEFT | CONTROL_RIGHT |
                CONTROL_ROT_LEFT | CONTROL_ROT_RIGHT, TRUE, FALSE);
        }
    }

    changed(integer change)
    {
        if (change & CHANGED_LINK)
        {
            key agent = llAvatarOnSitTarget();
            if (agent)
            {
                if (agent != llGetOwner())
                {
                    llSay(0, "This boat isn't yours, but you can buy a copy!");
                    llUnSit(agent);
                }
                else
                {
                    llRequestPermissions(agent, PERMISSION_TAKE_CONTROLS);
                    llSetStatus(STATUS_PHYSICS, TRUE);
                }
            }
            else
            {
                llReleaseControls();
                llSetStatus(STATUS_PHYSICS, FALSE);
            }
        }
    }

    control(key name, integer levels, integer edges)
    {
        float side = 0.0;
        float forw = 0.0;
        float move = 0.0;
        float turn;

        if (levels & CONTROL_ML_LBUTTON)
        {
            move = fastspeed;
            turn = 1.5 * turnspeed;
//            forw = 2 * PI / 3;
        }
        else if (levels & CONTROL_FWD)
        {
            move = slowspeed;
            turn = 1.0 * turnspeed;
//            forw = PI / 2;
        }
        else if (levels & CONTROL_BACK)
        {
            move = -backspeed;
//            forw = -PI / 3;
//            turn = -1.0 * turnspeed;
        }

        if (levels & (CONTROL_LEFT | CONTROL_ROT_LEFT))
        {
            if (move == fastspeed)
            {
                side = turnspeed;
//                forw = PI;
            }
            else if (move != 0)
            {
                side = turnspeed;
//                forw = PI / 3;
            }
            else
            {
                side = .67 * turnspeed;
//                forw = PI / 4;
                move = 0.1;
            }
        }
        else if (levels & (CONTROL_RIGHT | CONTROL_ROT_RIGHT))
        {
            if (move == fastspeed)
            {
                side = -turnspeed;
//                forw = PI;
            }
            else if (move != 0)
            {
                side = -turnspeed;
//                forw = PI / 3;
            }
            else
            {
                side = -.67 * turnspeed;
//                forw = PI / 4;
                move = 0.1;
            }
        }

        if (move == 0)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0, 0, 0>);
        }
        else
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION,
                  <move, 0, 0>);
            llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION,
                <-side / 5, 0, side>);
        }
    }

    listen(integer channel, string name, key id, string message)
    {
        list params = llParseString2List(message, [" "], [":"]);
        string cmd = llList2String(params, 0);
        integer enable = llList2Integer(params, 1);

        // Commands
        ;
    }

    touch_start(integer total_number)
    {
        key id = llDetectedOwner(total_number - 1);
       // llGiveInventory(id, "Info card");
    }
}

 

Speed an object over water

E-mail Print PDF

// Puts a motor in an object

Last Updated on Sunday, 08 March 2009 19:14 Read more...
 


Submit a Free Script

GTranslate

English French German Italian Portuguese Russian Spanish

SL News Feeds

Test SL Script Vendor


Follow Me

Facebook Twitter YouTube

Feedburner

GSyndication

Scripters online in SL