This might help, its my first attempt at working with C script and compiled from Many members pointers plus George and AUM.
Code:
////////////////////////////////////////////////////////////////////////////////
//1st person shooter perspective
var player_distance; // moves the player
var jumping = 0;
var vecFrom[3];
var vecTo[3];
////////////////////////////////////////////////////////////////////////////////
define health = skill18; // just another name for skill18
///////////////////////////////////////////////////////////////////////////////
function player_event();
function player_jumps();
///////////////////////////////////////////////////////////////////////////////
action player_me // attached to the player
{
my.fat = on;
my.narrow = on;
c_setminmax(my);
player = my; // I'm the player
my.invisible = on;
my.enable_scan = on;
my.enable_shoot = on;
my.enable_impact = on;
player.health = 200; // and I have 100 health points
while (my.health > 0)
{
vec_set (camera.pos, my.pos);
camera.x = my.x;
camera.y = my.y;
camera.z = my.z+30 ;
camera.tilt += 15 * mouse_force.y * time;
camera.pan -= 15 * mouse_force.x * time;
my.pan = camera.pan;
// my.tilt = camera.tilt;
player_distance.x = 30 * (key_w - key_s) * time; // moves forward / backward with W / S
player_distance.y = 30 * (key_a - key_d) * time;
player_distance.z = 30 * (key_space - key_c) * time;
if (key_shift ==1 && key_w==1 )
{
player_distance.x += 65 * time;
}
if (jumping == 0)
{
vec_set (temp, my.x);
temp.z -= 10000;
trace_mode = ignore_me + ignore_passable + use_box+activate_sonar;
my.skill30 = trace (my.x, temp);
if(result <= 0 )
{
//place player on ground
vec_set(VecFrom,my.x);
vec_set(VecTo,my.x);
VecTo.z -= 30* time; // place player on floor
my.z -= c_trace(VecFrom.x,VecTo.x,ignore_me+ignore_sprites+ignore_passable+ignore_passents+use_box);
my.z += 1;
}
if (my.skill30 < 20) // fall on the ground when closer than 50 quants to the surface
{
player_distance.z = -my.skill30;
}
else // way up in the air?
{
player_distance.z -= 30 * time; // then decrease player's z slowly
}
my.skill30 = -trace (my.x, temp);
}
if ((key_space == 1) && (jumping == 0)) // space to jump
{
player_jumps();
}
c_move(my,player_distance,nullvector,ignore_passable + glide);
wait (1);
}
}}
////////////////////////////////////////////////////////////////////////
function player_jumps()
{
proc_kill(4);
my.skill20 = 0;
jumping = 1;
while (my.skill20 < 30) //'hang' duration
{
ent_animate("jump", my.skill20);
my.skill20 += 3 * time; // "jump" animation speed
if (my.skill20 < 30)
{
player_distance.z += 0.1 * time;
}
else
{
player_distance.z -= 0.1 * time;
}
wait (1);
}
jumping = 0;
}
////////////////////////////////////////////////////////////////////////////////////
function player_event()
{
while (player == null)
{
wait (1);
}
if (my.health > 0)
{
my.health -= 10;
}
}
//////////////////////////////////////////////////////////////////////////////
action poly
{
my.polygon = on;
} //attach to model ground entities.
Bit of a hash but it worked fine at the time.