function move_player()
{
VECTOR player_dist; //needed for the movement
VECTOR save_pos; //stores the entity.pos (needed to find out if the position has changed)
VECTOR temp; //a temporary vector
my.flags |= SHADOW;
my.emask |= ENABLE_ENTITY;
my.event = NULL;
my.pan = save_pan; // used to face direction when spawn.,,,,
you = NULL;
while(enet_ent_globpointer(my) == -1) {wait(1);} //wait until the entity gets a global pointer
players[enet_ent_creator(enet_ent_globpointer(my))] = my; //saves the entity into the players array
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid()) //if this function runs on the client which created the entity
{
wait(1); //needed for c_updatehull
my.z += 30; //sets the entity above the ground
c_updatehull(my,0); //updates the collsision hull
while(enet_get_clientid() != -1) //as long as a connection to the server exists
{
my.pan -= 2*mouse_force.x; //rotates the entity with the mouse
player_dist.x = 15*(key_w-key_s)*time_step; //moves the player with [w] [a] [s] [d]
player_dist.y = 15*(key_a-key_d)*time_step;
//Gravity:
vec_set(temp, my.x);
temp.z -= 1000;
player_dist.z = -abs(c_trace (my.x, temp, IGNORE_ME | IGNORE_PASSABLE | USE_BOX ));
//c_move(my,player_dist,nullvector,GLIDE|IGNORE_PASSABLE); //moves the player
c_move(my,player_dist,nullvector,GLIDE);
if(key_w+key_s+key_a+key_d > 0) //if the entity had been moved
{
//animates the entity:
my.skill[41] += 7*time_step;
if(my.skill[41] > 100) {my.skill[41] = 0;}
ent_animate(my,"walk",my.skill[41],ANM_CYCLE);
//skill[42] == 1 if the entity shows it's animation (needed for the other clients+server to show the animation)
if(my.skill[42] == 0) //only send the skill if the value has changed
{
my.skill[42] = 1;
enet_send_skills(enet_ent_globpointer(my),42,42,-1); //sends the new skill value
}
}
else
{
if(my.skill[42] == 1) //only send the skill if the value has changed
{
my.skill[42] = 0;
enet_send_skills(enet_ent_globpointer(my),42,42,-1); //sends the new skill value
}
}
//sends the position if changed
if(save_pos.x != my.x || save_pos.y != my.y || save_pos.z != my.z) {enet_send_pos(enet_ent_globpointer(my),-1);vec_set(save_pos,my.x);}
//sends the angles if they changed
if(save_pan != my.pan) {enet_send_angle(enet_ent_globpointer(my),-1);save_pan = my.pan;}
update_views();
if(you!=NULL) //make sure an ENTITY has been hit
{
if(you.OBJECT_TYPE==OBSTACLE) //check if entity is an OBSTACLE
{
player_teleport();
}
}
wait(1);
}
}
}