@ Mr.Guest:

Your code worked almost perfectly. "E" starts the engine soundloop, and stops it... well, sometimes. For some reason, I have to wait about 3-5 seconds between keypresses. I guess that's not so bad, because a real Panzer IV would be about the same, heheh. You can't instantly start and stop it. But I would like to know why it does that.

Here's my source code, which is now working pretty much as I want it, with the exception of requiring the delay between keypresses...

Code:
///////////////////////////////////////////////////////////////////////////////////////////////////
// Icluding...
#include <acknex.h>
#include <default.c>
//
///////////////////////////////////////////////////////////////////////////////////////////////////
// Vehicle movement template... testing a tank... 
///////////////////////////////////////////////////////////////////////////////////////////////////

// Using the desert skirmish map, "Das Sandbox"...

// Declaring variables

var engine_state = 0;

var tank_handle;

var hnd_tankidle;

// Defining sounds

SOUND* snd_tankidle = "tankidle.wav";

//Declaring entity pointers

ENTITY* panzer;

// Defining movement vectors

VECTOR vSpeed, vAngularSpeed, vForce, vMove, vAhead;


// Declaring funtions

//////////////////////////////////////////////////////////////////////////////////////////////////
// Testing new function by MrGuest...                                                           //
//////////////////////////////////////////////////////////////////////////////////////////////////

function toggle_engine()
{
	
	//toggle to the new state
	engine_state = 1 - engine_state;
	
	//if engine is now on
	if(engine_state)
   {hnd_tankidle = ent_playloop(panzer, snd_tankidle, 77);}
		
	//if engine is now off
	else
	{
		snd_stop(hnd_tankidle);
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////


// Tank movement code...

// Defining actions

action tank_controls()
{
	wait(1);
   set(my,POLYGON); // Make the engine interpret collisions by the polygon and not bounding box
	
	// Set the tank's physical properties.
      phent_settype(my,PH_RIGID,PH_BOX);
      phent_setmass(my,2,PH_SPHERE);
      phent_setfriction(my,5);
      phent_setelasticity(my,7,100);
      phent_setdamping(my,27,5);
	

	while(1)
	{
		 // Update camera positions
      camera.x = my.x - 55;      // Position relative to tank's x position
      camera.y = my.y + 0;      // Position relative to tank's y position
      camera.z = my.z + 25;      // Position relative to tank's z position
      // Set camera tilt and pan in order to look at the tank.
      camera.tilt = -15;
      camera.pan = 0;
      wait(1);
      

    if(key_e) 
    {
    	toggle_engine();
    }
  
      //   Check to see if the player has fallen off the level i.e. the z value is less than minus 200
      if(my.z < -200)
      {
         phent_enable( me, 0 );      // To move physics enabled entities to an xyz position you must first disable physics for that entity
         my.x = 0;                  // Place at 0,0,80 (The 80 is so it spawns high enough above the level. You may need to change this with custom levels)
         my.y = 0;                  //
         my.z = 1000;
         phent_clearvelocity(my);   // Remove any speed and direction from the entity
         phent_enable( me, 1);      // Re-enable physics
      }
	}
}

// Collision detection/properties for objects
action terrain_prop()
{
   wait(1);
   c_updatehull(my,1);   // Update the "hull" of the object (helps engine with collisions)
   set(my,POLYGON);      // Make the engine interpret collisions by the polygon and not bounding box
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// MAIN ///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////

function main()
{
	video_mode = 8;
	shadow_stencil= ON;
	video_screen = 1;
	mouse_mode = 0;
	wait(1);
	
	//load level "Das Sandbox"...
	level_load("tryintankin.wmb");
	wait(2);
	
	// Gravity
   ph_setgravity(vector(0,0,-500));
   
   // Create sky
   ent_createlayer("skycube+6.tga", SKY | CUBE | VISIBLE, 0); // Create a black backdrop for the level.
   wait(2);
   
   // create player/tank entity
   panzer = ent_create("panzerIV_sk_wip.mdl", vector(-488,-848,1500), tank_controls);
}



Can you explain to me why that worked and mine didn't? I'm just curious as to the difference. You know what they say, "Give a man a fish, and he eats for the day; teach a man to fish, and he eats for a lifetime..." laugh Well, you gave me the fish here. Can you tell me how you caught it? heheh...

Also, now that this works correctly, I can add something to my tank's action code like...

while(engine_state = 1)
{
...tanks movement/physics instructions here
}

...correct? That way, you can only drive the tank when the engine runs? That's how I originally planned to do this.

Thanks to all of you! I can't thank you enough for your time and patience! laugh