0 registered members (),
18,561
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
ANET entity pointer question
#361806
03/05/11 07:47
03/05/11 07:47
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
hi, i have an ENTITY* array where i save the my pointer to use it in the shot function but the problem is that you can only kill the server cause the my pointer changes.
//on create if creator = client id
players[enet_get_clientid()] = my;
enet_send_array("players",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)
{
enet_clsend_event(19,enet_ent_globpointer(you),4,SERVER);
}
}
}
else
{
ent_create("media/Pics/schussloch.tga",target,Schussloch);
return;
}
}
function player_kill(var sender, STRING* msg)
{
var data[2];
memcpy(data,_chr(msg),8);
str_cpy(kill_msg,"");
enet_get_playername(data[0],killer);
enet_get_playername(data[1],death);
str_cat(kill_msg,killer);
str_cat(kill_msg," hat ");
str_cat(kill_msg,death);
str_cat(kill_msg," getötet!");
}
function sv_player_kill(var sender, STRING* msg)
{
hp[enet_ent_creator(str_to_num(msg))] -= 10;
if(hp[enet_ent_creator(str_to_num(msg))] < 1)
{
if(team[enet_ent_creator(str_to_num(msg))] == 1)
{
vec_set(players[enet_ent_creator(str_to_num(msg))].x,vector(-15,-3081,435));
}
else
{
vec_set(players[enet_ent_creator(str_to_num(msg))].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);
}
so how can i solve it?
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361807
03/05/11 09:20
03/05/11 09:20
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Just looking at your first 2 lines tells me that this won't work. The my pointer is a pointer to the local memory of the computer where the code is executed. --> It's called a local pointer. If you send this pointer to a different computer, the pointer will point to something different because on this computer the memory has a different content and order. You can solve this by using a global pointer. A global pointer is always pointing at the same entity on all computers. This would be correct:
//initialize the array as var (because a glob. pointer is a var
//and set all values to ANET_ERROR
var players[MAX_PLAYERS] = {ANET_ERROR};
//on create if creator = client id
players[enet_get_clientid()] = enet_ent_globpointer(my);
enet_send_array("players",0,15,BROADCAST);
//if you want to do something with the entity on a different computer:
my = enet_ent_locpointer(players[enet_get_clientid()];
Please notice that only global created entities (using enet_ent_create()) have a global pointer! Using enet_get_globpointer() for an entity created with ent_create() will cause an error. Does that solve your problem?
Last edited by Dark_samurai; 03/05/11 09:21.
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]
#361808
03/05/11 09:57
03/05/11 09:57
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
i have changed it like taht but u always kill the server when u kill a client
players[enet_get_clientid()] = enet_ent_globpointer(my); enet_send_array("players",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)
{
enet_clsend_event(19,enet_ent_globpointer(you),4,SERVER);
}
}
}
else
{
ent_create("media/Pics/schussloch.tga",target,Schussloch);
return;
}
}
function player_kill(var sender, STRING* msg)
{
var data[2];
memcpy(data,_chr(msg),8);
str_cpy(kill_msg,"");
enet_get_playername(data[0],killer);
enet_get_playername(data[1],death);
str_cat(kill_msg,killer);
str_cat(kill_msg," hat ");
str_cat(kill_msg,death);
str_cat(kill_msg," getötet!");
}
function sv_player_kill(var sender, STRING* msg)
{
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);
}
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361825
03/05/11 13:01
03/05/11 13:01
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
ok i found out that the msg (the glob you pointer) is always 0 any idea why?
maybe the wrong msg size?
Last edited by Ceryni; 03/05/11 15:42.
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361858
03/05/11 15:45
03/05/11 15:45
|
Joined: Mar 2002
Posts: 7,727
old_bill
Senior Expert
|
Senior Expert
Joined: Mar 2002
Posts: 7,727
|
@Ceryni: Please don't use the "notify" button for technical isssues, it's intend for abuse or other critical issues only.
Thanks.
Success is walking from failure to failure with no loss of enthusiasm.
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361907
03/05/11 19:14
03/05/11 19:14
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
I have a guess. Do you send the players[] array to a new client before he creates his player entity?
Example: Content of players[] at start: [0][0][0][0] Server started --> players[]: [0][0][0][0] (because the first glob. pointer is 0) Client started --> players[]: [0][1][0][0] now send it Client2 started --> players[]: [0][0][2][0] now send it
You see two things out of this exmample: 1) The startvalue of players has to be [-1][-1][-1][-1] because 0 is already a pointer 2) The array has to be sent to a new client before he creates his player. Otherwise it will send an array where all entries are zero (or -1 if you do it correct) and only the entry for this client is filled. 3) Another thing: Don't send the whole array if you only change 1 index. Send only the changed index. This produces much less traffic.
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]
#361912
03/05/11 19:54
03/05/11 19:54
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
thats my sv event when a client connects
function client_connected(var sender, STRING* msg)
{
enet_send_array("players",0,15,BROADCAST);
enet_send_array("hp",0,15,BROADCAST);
enet_send_array("team",0,15,BROADCAST);
enet_send_array("score",0,15,BROADCAST);
enet_send_var("team1",BROADCAST);
enet_send_var("team2",BROADCAST);
}
but not only the msg pointer is 0 also the pointer after i created the entity(directly after player_create())
Last edited by Ceryni; 03/05/11 19:59.
|
|
|
Re: ANET entity pointer question
[Re: Ceryni]
#361929
03/05/11 20:32
03/05/11 20:32
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
The global pointer of the first entity is always 0, the second is 1 and so on. The msg pointer is always NULL on this server side event.
Your source code is already big. So it's not that easy to find the problem without doing some tests. You should comment out everything that's not needed. Then you can check if the correct function is called for every player entity. If the my pointer is pointing to the entity you want. Then you can check if the global pointer returned by anet is correct and so on. Do a step by step debugging and try to keep the code as simple as possible. Comment out things that are unrelated to your problem.
I can tell you that the functions are tested out very well! There are already a lot of games using these functions. Maybe looking into my example codes on the anet homepage may also help you.
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]
#361932
03/05/11 20:39
03/05/11 20:39
|
Joined: Dec 2010
Posts: 63
Ceryni
OP
Junior Member
|
OP
Junior Member
Joined: Dec 2010
Posts: 63
|
i know that there are many games and the plugin is good work i did a test (line 29) and i dont understand why he returns 0 but thx for your help i will try to find my fault if i find a solution i will post it
function Bewegen()
{
VECTOR player_dist;
VECTOR save_pos;
VECTOR temp;
var save_pan = 0;
TEXT* name_text;
STRING* save_str = "#50";
VECTOR vFeet;
vec_for_min(vFeet,me);
my.flags |= SHADOW;
while(enet_ent_globpointer(my) == ANET_ERROR) {wait(1);}
wait(-1);
if(enet_ent_creator(enet_ent_globpointer(my)) == enet_get_clientid())
{
wait(1);
chat_eingeben();´
if(team1 > team2)
{
team[enet_get_clientid()] = 1;
}
else
{
team[enet_get_clientid()] = 2;
}
players[enet_get_clientid()] = enet_ent_globpointer(my);
printf("pointer: %.0f",enet_ent_globpointer(my));
hp[enet_get_clientid()] = 100;
enet_send_array("players",0,15,BROADCAST);
enet_send_array("hp",0,15,BROADCAST);
enet_send_array("team",0,15,BROADCAST);
while(enet_get_clientid() != ANET_ERROR )
{
if(waffeready == 0)
{
waffereloading+=waffereloading+((time_step/16)/10);
if (waffereloading>=waffereloadtime)
{
waffereloading=0;
waffeready=1;
}
}
if(mouse_left)
{
Schuss();
}
vec_for_min(vFeet,me);
if(key_shift)
{
run = 1.5;
}
else
{
if(key_ctrl)
{
run = 0.5;
}
else
{
run = 1;
}
}
VECTOR* mov = vector(0,0,0);
if(key_w)
{
mov.x=movement_speed_fb * run*time_step;
}
if(key_s)
{
mov.x=movement_speed_fb/2 *-1*run*time_step;
}
if(key_a)
{
mov.y=movement_speed_rl * run*time_step;
}
if(key_d)
{
mov.y=movement_speed_rl *-1*run*time_step;
}
if(c_trace(my.x,vector(my.x,my.y,my.z-40),IGNORE_ME | IGNORE_PASSABLE))
{
anziehung=0;
PlayerinderLuft=0;
}
else
{
anziehung=anziehung+gravitiy;
PlayerinderLuft=1;
}
if(key_space && PlayerinderLuft==0)
{
mov.z=5*time_step;
anziehung=-30;
PlayerinderLuft=1;
mov.z=-1*anziehung*time_step;
}
else
{
mov.z=-1*anziehung*time_step;
if(c_trace(my.x,vector(my.x,my.y,my.z-40),IGNORE_ME | IGNORE_PASSABLE))
{
my.z = hit.z - vFeet.z+20;
}
}
c_move(me, mov, NULL, GLIDE + IGNORE_SPRITES);
follow(me);
if(save_pos.x != my.x || save_pos.y != my.y || save_pos.z != my.z)
{
enet_set_unreliable(1);
enet_send_pos(enet_ent_globpointer(my),BROADCAST,0);vec_set(save_pos,my.x);
enet_set_unreliable(0);
}
if(save_pan != my.pan)
{
enet_set_unreliable(1);
enet_send_angle(enet_ent_globpointer(my),BROADCAST,ONLYSEND_PAN);save_pan = my.pan;
enet_set_unreliable(0);
}
wait(1);
}
}
else
{
name_text = txt_create(2,2);
name_text.flags |= VISIBLE;
my.skill[40] = handle(name_text);
set(name_text,LIGHT);
while(my != NULL && enet_get_connection() != NO_CONNECTION && enet_ent_globpointer(my) != ANET_ERROR)
{
if(team[enet_ent_creator(enet_ent_globpointer(my))] == myteam)
{
vec_set(name_text.blue,vector(0,200,0));
}
else
{
vec_set(name_text.blue,vector(0,0,200));
}
c_trace(camera.x,my.x,NULL);
if(you == NULL)
{
name_text.flags &= ~VISIBLE;
wait(1);
}
else
{
name_text.flags |= VISIBLE;
vec_set(temp,my.x);
vec_to_screen(temp,camera);
name_text.pos_x = temp.x-20;
if(vec_dist(my.x,camera.x)>1)
{
name_text.pos_y = temp.y-250/(vec_dist(my.x,camera.x)*0.01);
}
else
{
name_text.pos_y = temp.y-300;
}
enet_get_playername(enet_ent_creator(enet_ent_globpointer(my)),save_str);
str_cat(save_str,"(");
str_cat_num(save_str,"%.0f",hp[enet_ent_creator(enet_ent_globpointer(my))]);
str_cat(save_str,")");
str_cpy((name_text->pstring)[0],save_str);
wait(1);
}
}
}
}
Last edited by Ceryni; 03/05/11 20:42.
|
|
|
|