1 registered members (TipmyPip),
18,633
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361938
03/05/11 20:51
03/05/11 20:51
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Btw. do you synchronize the entities at start up? Look under enet_ent_synchronize().
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361945
03/05/11 21:17
03/05/11 21:17
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
i think so
function connected_with_server(var sender, STRING* msg, var length)
{
enet_set_playername(playername_input);
if(enet_get_connection() == CLIENT_MODE)
{
level_load(msg);
wait(3);
while((team1 == 0 && team2 == 0) || players[0] == -1)
{
wait(1);
}
enet_ent_synchronize();
}
else
{
create_player();
}
}
Last edited by Ceryni; 03/05/11 21:17.
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#362272
03/07/11 15:59
03/07/11 15:59
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
enet_ent_globpointer() returns a var. I once had problems displaying a var with printf(). You could try to show the value in a panel (digit) or try to convert the returned value with var_to_string() and display the string with error() or printf(). Maybe this helps.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#362292
03/07/11 17:25
03/07/11 17:25
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
k thx now it displays something that sounds ok but both entyties have 1907293 as globalpointers in 3 d chat example and in my programm 1215. 3d chat :
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);
}
}
}
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#362298
03/07/11 17:41
03/07/11 17:41
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
But the 3d chat example works correct for you? Then it's still a display error. This should work:
error(str_for_num(NULL, enet_ent_globpointer(my)));
Last edited by Dark_samurai; 03/07/11 17:41.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#362316
03/07/11 18:34
03/07/11 18:34
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
k thx now it works the pointers are ok. but in my code i display the pointer when i shoot and then waht the server receive. The pointer the client gets when he shoot at someone is correct but the server alway get something like 26578.000
function sv_player_kill(var sender, STRING* msg)
{
error(str_for_num(NULL,msg));// not correct
hp[enet_ent_creator(str_to_num(msg))] -= 10;
if(hp[enet_ent_creator(str_to_num(msg))] < 1)
{
ENTITY* death = enet_ent_locpointer(str_to_num(msg));
if(team[enet_ent_creator(str_to_num(msg))] == 1)
{
vec_set(death.x,vector(-15,-3081,435));
}
else
{
vec_set(death.x,vector(-3,2439,100));
}
enet_send_pos(str_to_num(msg),BROADCAST,0);
score[sender]++;
enet_send_array("score",0,15,BROADCAST);
var data[2];
data[0] = sender;
data[1] = enet_ent_creator(str_to_num(msg));
enet_svsend_event(19,data,8,BROADCAST);
hp[enet_ent_creator(str_to_num(msg))] = 100;
}
enet_send_array("hp",0,15,BROADCAST);
}
function Pistole_Schiessen()
{
temp_schuss.x = (screen_size.x / 2) + (random(5))-2;
temp_schuss.y = (screen_size.y / 2) + (random(5))-2;
temp_schuss.z = 100000;
vec_for_screen(temp_schuss,camera);
c_trace(camera.x,temp_schuss,USE_POLYGON + IGNORE_ME + GET_HITVERTEX + ACTIVATE_SHOOT + IGNORE_PASSABLE );
if(you!=NULL)
{
if(enet_ent_globpointer(you) != ANET_ERROR)
{
if(team[enet_ent_creator(enet_ent_globpointer(you))] != myteam)
{
error(str_for_num(NULL, enet_ent_globpointer(you)));//correct
enet_clsend_event(19,enet_ent_globpointer(you),0,SERVER);
}
}
}
else
{
ent_create("media/Pics/schussloch.tga",target,Schussloch);
return;
}
}
are u in icq sometimes?
Last edited by Ceryni; 03/07/11 18:40.
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#362346
03/07/11 19:48
03/07/11 19:48
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
This is the problem:
enet_clsend_event(19,enet_ent_globpointer(you),0,SERVER);
Do it like this:
var glob_pointer = enet_ent_globpointer(you);
enet_clsend_event(19,&glob_pointer,4,SERVER);
And in the event you do this:
function sv_player_kill(var sender, STRING* msg)
{
var glob_pointer;
memcpy(&glob_pointer, _chr(msg), 4);
error(str_for_num(NULL,glob_pointer)); //should be correct now
}
Last edited by Dark_samurai; 03/07/11 19:49.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|