dim3 Forum

Full Version: Airplane script
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
I'm trying to edit the audi script to make a plane and this is what I have but it tells me in the console JS error, Audi construct not defined. THis is what I've edited

Code:
var lastCrashTick;

var lastAngleY;

var smokeCount;

var damageLevel;

var lastDamageTick;



function airplaneConstruct(obj)

{

obj.model.on=true;

obj.model.name='airplane';

obj.model.lit=DIM3_MODEL_LIT_VERTEX;



obj.model.shadow.on=true;

obj.model.shadow.alwaysInAir=true; // force shadow to always be under plane



obj.setting.damage=true;
obj.setting.fly=true

obj.setting.invincible=false;

obj.setting.turnOnlyWhenMoving=true;

obj.setting.restrictPlayerTurning=true;

obj.setting.quickReverse=false;

obj.setting.sideStep=false;

obj.setting.jump=false;

obj.setting.duck=false;

obj.setting.singleSpeed=true;

obj.setting.bumpUp=true;



obj.size.x=2800;

obj.size.z=5600;

obj.size.y=1900;

obj.size.weight=2000;



obj.rigidBody.on=true;



obj.vehicle.on=true;



obj.turnSpeed.facingWalk=1.5;

obj.turnSpeed.motionWalk=0.6;

obj.turnSpeed.facingAir=3;

obj.turnSpeed.motionAir=3;



obj.forwardSpeed.walk=250;

obj.forwardSpeed.acceleration=0.5;

obj.forwardSpeed.deceleration=1.75;

obj.forwardSpeed.accelerationAir=0.4;

obj.forwardSpeed.decelerationAir=0.6;



obj.objectSpeed.bounceFactor=1.3; // this makes the audi bounce off when hitting things

obj.objectSpeed.bumpHeight=500;



obj.look.upAngle=5;

obj.look.downAngle=10;

obj.health.maximum=200;
obj.health.start=200;



// headlight



obj.model.light.on=true;

obj.model.light.type=DIM3_LIGHT_TYPE_NORMAL;

obj.model.light.intensity=16000;



obj.model.lightColor.red=1;

obj.model.lightColor.green=1;

obj.model.lightColor.blue=0.8;



// the car engine ambient



obj.setting.setAmbient('Car Engine',1);



lastCrashTick=0;

lastAngleY=0;

smokeCount=0;

damageLevel=0;

lastDamageTick=0;

}



//

// car animations

//



function airplaneAnimation(obj,subEvent)

{

var model;



model=obj.model;



switch (subEvent) {



case DIM3_EVENT_ANIMATION_OBJECT_STOP:

model.animation.change('idle');

return;



case DIM3_EVENT_ANIMATION_OBJECT_WALK:

model.animation.change('fly');

return;



case DIM3_EVENT_ANIMATION_OBJECT_WALK_BACK:

model.animation.change('fly');

return;



}

}

//
// car in liquids
//

function airplaneLiquid(obj)

{

sound.play("Splash",obj.position.x,obj.position.z,obj.position.y,1);

}



//

// car timer

//



function audiTimer(obj)

{

var speed,pitch,smoke,pnt;



// engine sound



speed=obj.status.speed;

pitch=1.0;



if (speed<20) {

pitch=1.0;

}

else {

if (speed>=150) {

pitch=1.5;

}

else {

pitch=1+(0.5*((speed-20)/130));

}

}



obj.setting.changeAmbientPitch(pitch);



// time to start smoking?



if (speed!=0) {

if (utility.angle.dif(obj.angle.y,lastAngleY)>12) smokeCount=5;

}

if ((speed>0) && (speed<100)) smokeCount=10;



lastAngleY=obj.angle.y;



// smoke



if (smokeCount!=0) {

smokeCount--;



pnt=obj.model.bone.findPosition(null,'bRwl');

spawn.particle(pnt.x,pnt.z,pnt.y,'Car Smoke');

pnt=obj.model.bone.findPosition(null,'bLwl');

spawn.particle(pnt.x,pnt.z,pnt.y,'Car Smoke');

}

}



//

// entering and exiting auti

//



function audiEnter(obj)

{

// backup the original camera



camera.state.save();



// change camera for airplane



camera.setting.type=DIM3_CAMERA_TYPE_CHASE;



camera.chase.distance=10500;

camera.chase.trackSpeed=0.1;



camera.chaseAngle.x=0;

camera.chaseAngle.y=0;

camera.chaseAngle.z=0;



camera.chaseSlop.y=25;



// start a timer for engine noise



obj.event.startTimer(1,0);

}



function audiExit(obj)

{

// turn off the engine noise timer



obj.event.clearTimer();



// restore camera



camera.state.restore();



// make sure animation is idling



obj.model.animation.change('Running');

}



function audiEnterOrExit(obj,subEvent)

{

// door sound



// sound.play("Car Door",obj.position.x,obj.position.z,obj.position.y,1);



// start or stop changes



switch (subEvent) {



case DIM3_EVENT_VEHICLE_ENTER:

audiEnter(obj);

break;



case DIM3_EVENT_VEHICLE_EXIT:

audiExit(obj);

break;



}

}



//

// car colliding with map or object

//



function audiCollide(obj,tick)

{

// if car isn't moving, then no collide effects



if (!obj.status.moving) return;



// car hit sound



if (tick>lastCrashTick) {

sound.play("Crash",obj.position.x,obj.position.z,obj.position.y,0.7);

lastCrashTick=tick+800;

}



// turn on the smoke



smokeCount=20;

}



//

// car taking damage when colliding with wall

//



function audiDamage(obj,tick)

{



// max damage level is 2



if (damageLevel==2) return;



// only take damage at certain rates



if (tick<lastDamageTick) return;



lastDamageTick=tick+2000;



// change for damage



damageLevel++;



switch (damageLevel) {



case 1: // break window

obj.model.fill.change(1,1);

break;

case 2: // damage body

obj.model.fill.change(0,1);

break;



}

}



//

// car horn

//



function audiCarHorn(obj,subEvent)

{

// if no weapon selected, then all fire messages come directly to object

// only check for fire message



if (subEvent==DIM3_EVENT_WEAPON_FIRE_DOWN) sound.play("Car Horn",obj.position.x,obj.position.z,obj.position.y,1);

}



//

// events

//



function event(obj,mainEvent,subEvent,id,tick)

{

switch (mainEvent) {



case DIM3_EVENT_CONSTRUCT:

audiConstruct(obj);

return;



case DIM3_EVENT_SPAWN:

obj.model.animation.start("idle");

return;



case DIM3_EVENT_COLLIDE:

audiCollide(obj,tick);

audiDamage(obj,tick);

return;



case DIM3_EVENT_TOUCH:

audiCollide(obj,tick);

return;



case DIM3_EVENT_ANIMATION_OBJECT:

audiAnimation(obj,subEvent);

return;


case DIM3_EVENT_LIQUID:

audiLiquid(obj);

return;



case DIM3_EVENT_VEHICLE:

audiEnterOrExit(obj,subEvent);

return;



case DIM3_EVENT_WEAPON_FIRE:

audiCarHorn(obj,subEvent);

return;



case DIM3_EVENT_TIMER:

audiTimer(obj);

return;



}

}
Oh, that's easy. Go to the back of the script and replace 'audiConstruct' and 'audiAnimation' with 'airplaneConstruct' and 'airplaneAnimation' and it should work fine. You see, the computer reads those and determines what function it should go to when a specific event occurs; you forgot to say 'airplaneConstruct' instead of 'audiConstruct'. The computer has seen an 'airplaneConstruct' before, but an 'audiConstruct' isn't in the script, so it's whining and automatically shuts down the script. Had it read more, it would have discovered that 'audiAnimation' wasn't defined as well. That's what happened. Next time, don't change the names of functions unless you have a REALLY good reason. Wink
Also PLEASE place all code in the CODE brackets.

It should look like this:

Code:
functionblahBlah(obj)
{

do this and do that haha
return;
}

It also makes it easier for us to work on your problem.
ok thanks for the help.
I tried it out and changed some stuff in the scripts but it says that it could open the script and it stays on the floor without flying using something like the audi script.

Code:
function airplaneConstruct(obj)

{

    obj.model.on=true;

    obj.model.name='airplane';

    obj.model.lit=DIM3_MODEL_LIT_VERTEX;



    obj.model.shadow.on=true;

    obj.model.shadow.alwaysInAir=true;        // force shadow to always be under plane



    obj.setting.damage=true;
    obj.setting.fly=true

    obj.setting.invincible=false;

    obj.setting.turnOnlyWhenMoving=true;

    obj.setting.restrictPlayerTurning=true;

    obj.setting.quickReverse=false;

    obj.setting.sideStep=false;

    obj.setting.jump=false;

    obj.setting.duck=false;

    obj.setting.singleSpeed=true;

    obj.setting.bumpUp=true;



    obj.size.x=2800;

    obj.size.z=5600;

    obj.size.y=1900;

    obj.size.weight=2000;

    

    obj.rigidBody.on=true;



    obj.vehicle.on=true;

    

    obj.turnSpeed.facingWalk=1.5;

    obj.turnSpeed.motionWalk=0.6;

    obj.turnSpeed.facingAir=3;

    obj.turnSpeed.motionAir=3;

    

    obj.forwardSpeed.walk=250;

    obj.forwardSpeed.acceleration=0.5;

    obj.forwardSpeed.deceleration=1.75;

    obj.forwardSpeed.accelerationAir=0.4;

    obj.forwardSpeed.decelerationAir=0.6;

    

    obj.objectSpeed.bounceFactor=1.3;        // this makes the audi bounce off when hitting things

    obj.objectSpeed.bumpHeight=500;

    

    obj.look.upAngle=5;

    obj.look.downAngle=10;

    obj.health.maximum=200;
    obj.health.start=200;

    

        // headlight

        

    obj.model.light.on=true;

    obj.model.light.type=DIM3_LIGHT_TYPE_NORMAL;

    obj.model.light.intensity=16000;

    

    obj.model.lightColor.red=1;

    obj.model.lightColor.green=1;

    obj.model.lightColor.blue=0.8;



        // the car engine ambient

            

    obj.setting.setAmbient('Car Engine',1);

    

    lastCrashTick=0;

    lastAngleY=0;

    smokeCount=0;

    damageLevel=0;

    lastDamageTick=0;

}



//

// car animations

//



function airplaneAnimation(obj,subEvent)

{

    var            model;

    

    model=obj.model;

    

    switch (subEvent) {

    

        case DIM3_EVENT_ANIMATION_OBJECT_STOP:

            model.animation.change('Idle');

            return;



        case DIM3_EVENT_ANIMATION_OBJECT_WALK:

            model.animation.change('fly');

            return;

            

        case DIM3_EVENT_ANIMATION_OBJECT_WALK_BACK:

            model.animation.change('fly');

            return;



    }

}

//
// car in liquids
//

function airplaneLiquid(obj)

{

    sound.play("Splash",obj.position.x,obj.position.z,obj.position.y,1);

}



//

// car timer

//



function audiTimer(obj)

{

    var        speed,pitch,smoke,pnt;

    

        // engine sound

    

    speed=obj.status.speed;

    pitch=1.0;

    

    if (speed<20) {

        pitch=1.0;

    }

    else {

        if (speed>=150) {

            pitch=1.5;

        }

        else {

            pitch=1+(0.5*((speed-20)/130));

        }

    }

    

    obj.setting.changeAmbientPitch(pitch);

    

        // time to start smoking?

      

    if (speed!=0) {

        if (utility.angle.dif(obj.angle.y,lastAngleY)>12) smokeCount=5;

    }

    if ((speed>0) && (speed<100)) smokeCount=10;

    

    lastAngleY=obj.angle.y;

    

        // smoke

        

    if (smokeCount!=0) {

        smokeCount--;

        

        pnt=obj.model.bone.findPosition(null,'BOdy');

        spawn.particle(pnt.x,pnt.z,pnt.y,'Car Smoke');

        pnt=obj.model.bone.findPosition(null,'BOdy');

        spawn.particle(pnt.x,pnt.z,pnt.y,'Car Smoke');

    }

}



//

// entering and exiting auti

//



function audiEnter(obj)

{

        // backup the original camera

        

    camera.state.save();

        

        // change camera for airplane

        

    camera.setting.type=DIM3_CAMERA_TYPE_CHASE;

    

    camera.chase.distance=10500;

    camera.chase.trackSpeed=0.1;

    

    camera.chaseAngle.x=0;

    camera.chaseAngle.y=0;

    camera.chaseAngle.z=0;

        

    camera.chaseSlop.y=25;

    

        // start a timer for engine noise

        

    obj.event.startTimer(1,0);

}



function audiExit(obj)

{

        // turn off the engine noise timer

        

    obj.event.clearTimer();

    

        // restore camera

        

    camera.state.restore();

    

        // make sure animation is idling

        

    obj.model.animation.change('Running');

}



function audiEnterOrExit(obj,subEvent)

{

        // door sound

        

//    sound.play("Car Door",obj.position.x,obj.position.z,obj.position.y,1);



        // start or stop changes

        

    switch (subEvent) {

    

        case DIM3_EVENT_VEHICLE_ENTER:

            audiEnter(obj);

            break;

            

        case DIM3_EVENT_VEHICLE_EXIT:

            audiExit(obj);

            break;

            

    }

}



//

// car colliding with map or object

//



function audiCollide(obj,tick)

{

        // if car isn't moving, then no collide effects



    if (!obj.status.moving) return;



        // car hit sound



    if (tick>lastCrashTick) {

        sound.play("Crash",obj.position.x,obj.position.z,obj.position.y,0.7);

        lastCrashTick=tick+800;

    }



        // turn on the smoke

        

    smokeCount=20;

}



//

// car taking damage when colliding with wall

//



function audiDamage(obj,tick)

{



        // max damage level is 2



    if (damageLevel==2) return;



        // only take damage at certain rates



    if (tick<lastDamageTick) return;



    lastDamageTick=tick+2000;



        // change for damage



    damageLevel++;



    switch (damageLevel) {



        case 1:        // break window

            obj.model.fill.change(1,1);

            break;

        case 2:        // damage body

            obj.model.fill.change(0,1);

            break;



    }

}



//

// car horn

//



function audiCarHorn(obj,subEvent)

{

        // if no weapon selected, then all fire messages come directly to object

        // only check for fire message

    

    if (subEvent==DIM3_EVENT_WEAPON_FIRE_DOWN) sound.play("Car Horn",obj.position.x,obj.position.z,obj.position.y,1);

}



//

// events

//



function event(obj,mainEvent,subEvent,id,tick)

{

    switch (mainEvent) {

    

        case DIM3_EVENT_CONSTRUCT:

            airplaneConstruct(obj);

            return;

    

        case DIM3_EVENT_SPAWN:

            obj.model.animation.start("Idle");

            return;

            

        case DIM3_EVENT_COLLIDE:

            audiCollide(obj,tick);

            audiDamage(obj,tick);

            return;



        case DIM3_EVENT_TOUCH:

            audiCollide(obj,tick);

            return;

            

        case DIM3_EVENT_ANIMATION_OBJECT:

            airplaneAnimation(obj,subEvent);

            return;
            

        case DIM3_EVENT_LIQUID:

            audiLiquid(obj);

            return;



        case DIM3_EVENT_VEHICLE:

            audiEnterOrExit(obj,subEvent);

            return;

            

        case DIM3_EVENT_WEAPON_FIRE:

            audiCarHorn(obj,subEvent);

            return;

            

        case DIM3_EVENT_TIMER:

            audiTimer(obj);

            return;



    }

}
This is what I have now.
Seriously link the script as a download file, and don't use double returns. Its unreadable.
Mafoo, I think the copy&paste is causing it to double space the lines. I have the same problem with code sites and other places.
Alexander Smith Wrote:Mafoo, I think the copy&paste is causing it to double space the lines. I have the same problem with code sites and other places.

Its probably because the editor is in maxumum compatibility mode, so i has /n and /r at the end of every line. Changing the line encodings before you copy will fix this, but I'd still recomend posting the script speratly.

Try the pastebin http://dim3.pastebin.com/
Ok guess I'll do that
I edited the post on the top to have the code brackets. SO how do I fix the script problem quickly?
Pages: 1 2 3
Reference URL's