Shortnote

The following script is a modified version the the original UFO engine mentioned in the code headers. It was used for Warp Core Project in order to make the helicopter move. The engine feels and handles like a helicopter, including tilt and is controlled using the WSAD keys and E and C for altitude control.

Code

ufo.lsl
// From the book:
//
// Scripting Recipes for Second Life
// by Jeff Heaton (Encog Dod in SL)
// ISBN: 160439000
// Copyright 2007 by Heaton Research, Inc.
//
// This script may be freely copied and modified so long as this header
// remains unmodified.
//
// For more information about this book visit the following web site:
//
// http://www.heatonresearch.com/articles/series/22/
//
// additional fixes for opensim by Renmiri Writer @ Second Life on 9/12/2010
 
 
// Modified by Morgan LeFay and moonbuggy Resident.
// Used in the ROFLCopter to power the basic engines 
// and is not essential to Kira Warp Drive. Replace 
// with any other drive.
 
float forward_power = 10; 
float reverse_power = -8; 
float turning_ratio = 2; 
string sit_message = "Fly"; 
string not_owner_message = "You are not the owner ..."; 
float VERTICAL_THRUST = 7;
float ROTATION_RATE = 5;      
 
resetY()
{
    rotation rot = llGetRot();
    llSetRot(rot);
}
 
default
{
    state_entry()
    {
        llSetSitText(sit_message);
 
        llSetCameraEyeOffset(<-8, .0, 5>);
        llSetCameraAtOffset(<1, .0, 2>);
 
        llSetVehicleType(VEHICLE_TYPE_AIRPLANE);
 
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_EFFICIENCY, .1);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_EFFICIENCY, .1);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_DEFLECTION_TIMESCALE, 10);
        llSetVehicleFloatParam(VEHICLE_LINEAR_DEFLECTION_TIMESCALE, 10);
 
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_TIMESCALE, .2);
        llSetVehicleFloatParam(VEHICLE_LINEAR_MOTOR_DECAY_TIMESCALE, 10);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_TIMESCALE, .2);
        llSetVehicleFloatParam(VEHICLE_ANGULAR_MOTOR_DECAY_TIMESCALE, .1);
 
        llSetVehicleVectorParam(VEHICLE_LINEAR_FRICTION_TIMESCALE, <1,1,1>);
        llSetVehicleVectorParam(VEHICLE_ANGULAR_FRICTION_TIMESCALE, <1,1000,1000>);
 
        llSetVehicleFloatParam(VEHICLE_BUOYANCY, 1);
 
        llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_EFFICIENCY, 1 );
        llSetVehicleFloatParam( VEHICLE_VERTICAL_ATTRACTION_TIMESCALE, 2 );
 
        llSetVehicleFloatParam( VEHICLE_BANKING_EFFICIENCY, 1 );
        llSetVehicleFloatParam( VEHICLE_BANKING_MIX, .5 );
        llSetVehicleFloatParam( VEHICLE_BANKING_TIMESCALE, .5 );
 
 
    }
 
    changed(integer change)
    {
 
 
        if (change & CHANGED_LINK)
        {
 
            key agent = llAvatarOnSitTarget();
            if (agent)
            {
                if (agent != llGetOwner())
                {
                    llSay(0, not_owner_message);
                    llUnSit(agent);
                    llPushObject(agent, <0,0,50>, ZERO_VECTOR, FALSE);
                }
                else
                {
                    llMessageLinked(LINK_ALL_CHILDREN , 0, "start", NULL_KEY);
 
                    llSleep(.4);
                    llSetStatus(STATUS_PHYSICS, TRUE);
                    llSetStatus(STATUS_ROTATE_Y,TRUE);
                    llSleep(.1);
                    llRequestPermissions(agent, PERMISSION_TRIGGER_ANIMATION | PERMISSION_TAKE_CONTROLS);
 
                }
            }
            else
            {
                llMessageLinked(LINK_ALL_CHILDREN , 0, "stop", NULL_KEY);
 
                llSetStatus(STATUS_PHYSICS, FALSE);
                llSleep(.4);
                llReleaseControls();
                llTargetOmega(<0,0,0>,PI,0);
 
                llResetScript();
            }
        }
 
    }
 
    run_time_permissions(integer perm)
    {
        if (perm) {
            llTakeControls(CONTROL_FWD | CONTROL_BACK | CONTROL_RIGHT | CONTROL_LEFT | CONTROL_ROT_RIGHT | CONTROL_ROT_LEFT | CONTROL_UP | CONTROL_DOWN | CONTROL_LBUTTON, TRUE, FALSE);
        }
    }
 
    control(key id, integer level, integer edge)
    {
        vector angular_motor;
 
        if(level & CONTROL_LBUTTON) {
            llMessageLinked(LINK_SET, 0, "fire", NULL_KEY);
        }
 
        if(level & CONTROL_FWD)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <forward_power,0,0>);
        } else if(edge & CONTROL_FWD)
    {
        llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,0>);
    }
 
 
 
        if(level & CONTROL_BACK)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <reverse_power,0,0>);
        }
        else if(edge & CONTROL_BACK)
        {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,0>);
        }
 
 
        if(level & (CONTROL_RIGHT|CONTROL_ROT_RIGHT))
        {
            angular_motor.x += 25;
        }
 
        if(level & (CONTROL_LEFT|CONTROL_ROT_LEFT))
        {
            angular_motor.x -= 25;
        }
 
 
 
        if(level & CONTROL_UP) {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,VERTICAL_THRUST>);
        } else if (edge & CONTROL_UP) {
                llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,0>);
        }
 
 
 
        if(level & CONTROL_DOWN) {
            llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,-VERTICAL_THRUST>);
        } else if (edge & CONTROL_DOWN) {
                llSetVehicleVectorParam(VEHICLE_LINEAR_MOTOR_DIRECTION, <0,0,0>);
        }
 
        angular_motor.y = 0;
        llSetVehicleVectorParam(VEHICLE_ANGULAR_MOTOR_DIRECTION, angular_motor);
 
 
 
    } 
 
 
 
}

secondlife/engines/ufo.txt ยท Last modified: 2017/02/22 18:30 (external edit)

Access website using Tor


For the copyright, license, warranty and privacy terms for the usage of this website please see the license and privacy pages.