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
var save_pan = 0; //stores the entity.pan (needed to find out if the pan has changed)
TEXT* name_text; //stores the TEXT which shows the name and chatmessage of the entity
STRING* save_str = "#50"; //needed for buffering the playername
my.flags |= SHADOW;
while(enet_ent_globpointer(my) == ANET_ERROR) {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
pan_setdigits(statistics_pan,0,300,200,"%.0f",font_create("Arial#25"),1,enet_ent_globpointer(my));
while(enet_get_clientid() != ANET_ERROR) //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
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,BROADCAST); //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,BROADCAST); //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),BROADCAST,DONTSEND_Z);vec_set(save_pos,my.x);}
//sends the angles if they changed
if(save_pan != my.pan) {enet_send_angle(enet_ent_globpointer(my),BROADCAST,ONLYSEND_PAN);save_pan = my.pan;}
//controls the camera
camera.x = my.x-100*cos(my.pan);
camera.y = my.y-100*sin(my.pan);
camera.z = my.z+50;
camera.tilt += mouse_force.y;
camera.pan = my.pan;
if(camera.tilt < -50) {camera.tilt = -50;}
if(camera.tilt > 20) {camera.tilt = 20;}
wait(1);
}
}
else //if the host didn't created the entity
{
//creates the TEXT which displays the name and the chatmessage
name_text = txt_create(2,2);
name_text.flags |= VISIBLE;
my.skill[40] = handle(name_text); //saves the handle local
while(my != NULL && enet_get_connection() != NO_CONNECTION && enet_ent_globpointer(my) != ANET_ERROR)
{
//moves the TEXT above the Playerhead
vec_set(temp,my.x);
vec_to_screen(temp,camera);
name_text.pos_x = temp.x-20;
//reduces the distance between head and text depending on the distance camera-entity
if(vec_dist(my.x,camera.x)>1) //no div through 0
{
name_text.pos_y = temp.y-250/(vec_dist(my.x,camera.x)*0.01);
}
else
{
name_text.pos_y = temp.y-300;
}
//saves the playername in the first string of the TEXT
enet_get_playername(enet_ent_creator(enet_ent_globpointer(my)),save_str);
str_cpy((name_text->pstring)[0],save_str);
//animates the entity if my.skill[42] == 1
if(my.skill[42] == 1)
{
my.skill[41] += 7*time_step;
if(my.skill[41] > 100) {my.skill[41] = 0;}
ent_animate(my,"walk",my.skill[41],ANM_CYCLE);
}
wait(1);
}
}
}