|
[ANET] Send coordinates?
#351490
12/25/10 20:56
12/25/10 20:56
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Hi there, iīve been trying really hard to find out how to do this. But everything i tried didnt work. I want to send coordinates from my muzzle to the target to every client. The clients then create a draline3d effect between those 2 points. Till now iīm using a string to send the datas. Hereīs my script. This is the creation of the string which is going to be send.
if(trace_hit)
{
if(you)
{
you.health -= integer(random(25))+80;
}
else
{
ent_create(einschussloch,hit.x,einschuss);
}
str_cpy(send_str, str_for_num(NULL,muendung.x));
str_cat(send_str, ",");
str_cat(send_str, str_for_num(NULL,muendung.y));
str_cat(send_str, ",");
str_cat(send_str, str_for_num(NULL,muendung.z));
str_cat(send_str, ":");
str_cat(send_str, str_for_num(NULL,hit.x));
str_cat(send_str, ",");
str_cat(send_str, str_for_num(NULL,hit.y));
str_cat(send_str, ",");
str_cat(send_str, str_for_num(NULL,hit.z));
enet_clsend_event(18,send_str,0,BROADCAST);
Iīm receiving this string in another function and split every value with string manipulations (str_trunc etc.) BEcause of that the script is very big and the string is also big. So i have more traffic. Now i really need to know cause i canīt find it out myself. How can i use the data send in ANET? I tried it with this one.
var g_data[6];
g_data[0] = muendung.x;
g_data[1] = muendung.y;
g_data[2] = muendung.z;
g_data[3] = hit.x;
g_data[4] = hit.y;
g_data[5] = hit.z;
enet_clsend_event(18,g_data,6,BROADCAST);
But i really dont know how to receive this data now? When iīm using char and receiving it with the _chr(msg) function the values arenīt the same as send. Please help me. I really want to finally know how this works. Thank you very much
|
|
|
Re: [ANET] Send coordinates?
[Re: Rasch]
#351732
12/28/10 11:41
12/28/10 11:41
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Hi Rasch, methode 2: Sending the array and then sending the event immediately after the enet_send_array() function was called would work. Packets are always deliverd in the correct order (if sent reliable). But of course methode 1 is more preferable because it consumes less traffic. This should work: Code for sending (remember 6 * var is 6 * 4 Byte and thus 24, not 6!):
var g_data[6];
g_data[0] = muendung.x;
g_data[1] = muendung.y;
g_data[2] = muendung.z;
g_data[3] = hit.x;
g_data[4] = hit.y;
g_data[5] = hit.z;
enet_clsend_event(18, g_data, 24, BROADCAST)
Code for receiving:
function rcv_data(var sender, STRING* msg, var size)
{
var g_data[6];
memcpy(g_data, _chr(msg), 24);
// do something with the data...
}
I tested the code and it should work
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
Re: [ANET] Send coordinates?
[Re: Dark_samurai]
#351769
12/28/10 14:03
12/28/10 14:03
|
Joined: Jun 2008
Posts: 428
Rasch
OP
Senior Member
|
OP
Senior Member
Joined: Jun 2008
Posts: 428
|
Thank you very much Dark_samurai. It works perfectly Didnīt think it would be that easy. ^^ Now i just have some more questions. 1) Is it possible to send an entity pointer? Lets say in my example i would send the you pointer to the server. Would the server know who entity this is and how would i send it, or should i better send an id of the entity to the server? 2) If i create a entity with enet_ent_create and give it some action. My bullet hole for example. On the client who created the bullet hole, the "normal" vector is correct and can be used. But on the other clients itīs not correct. So i send skills in the action to the other clients which hold the normal values. Iīm waiting a few frames and then using the received normal vector. That works. But is there another solution for that? Sorry for my 2 questions but those are the only things in programming with anet which i couldnt find out by myself. Hereīs the code for example 2:
function einschuss()
{
VECTOR normal_save;
vec_set(normal_save, normal); // saving normal cause itīs only 1 frame there
set(my,INVISIBLE);
while(enet_ent_globpointer(my) == ANET_ERROR) {wait(1);}
if(MY_CREATOR == MY_CLIENTID) // this runs on the creator machine
{
my.skill[70] = normal_save.x;
my.skill[71] = normal_save.y;
my.skill[72] = normal_save.z;
enet_send_skills(enet_ent_globpointer(my),70,72,BROADCAST);
vec_to_angle(my.pan, normal_save);
if(my.pan == 0)
{
my.pan = 0.001;
}
vec_add(my.x,normal_save);
...
}
else
{
var lifetime = 5; // Just for the while loop
while(lifetime > 0)
{
var normal_x = my.skill[70];
var normal_y = my.skill[71];
var normal_z = my.skill[72];
vec_set(temp_normal, vector(normal_x,normal_y,normal_z));
vec_to_angle(my.pan, temp_normal);
if(my.pan == 0)
{
my.pan = 0.001;
}
if(lifetime < 4.99) // just set vec_add after a short wait
{
if(vec_add_set != 1)
{
vec_add(my.x,temp_normal);
vec_add_set = 1;
}
}
lifetime -= time_step/16;
wait(1);
}
}
AS you can see iīm sending the normal values via skills and then receiving the skills and using them. But i need to use a while loop, because the skills which are send donīt come early enough. It makes sense. But is there another solution maybe? Thank you very much
|
|
|
Re: [ANET] Send coordinates?
[Re: Rasch]
#351776
12/28/10 14:27
12/28/10 14:27
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
As for the 1 Question(if i understood Anet correct^^), you have to use the Anet entity pointer(cause they are the same on all connected machines). use
enet_ent_globpointer(you);
to get a var holding the global Anet entity pointer. Send it and when received do
you = enet_ent_locpointer(globalpointer);
edit: globalpointer is the var you received(in this example, you can use any other var instead) Should work Greets Rackscha
Last edited by Rackscha; 12/28/10 14:28.
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: [ANET] Send coordinates?
[Re: Rasch]
#351843
12/28/10 20:39
12/28/10 20:39
|
Joined: Dec 2008
Posts: 1,218 Germany
Rackscha
Serious User
|
Serious User
Joined: Dec 2008
Posts: 1,218
Germany
|
if the entity_pointer is the received pointer, you can already use it as GLOBal pointer, cause its the global one So you do enet_ent_remove(entity_pointer);
MY Website with news of my projects: (for example my current Muliplayer Bomberman, GenesisPrecompiler for LiteC and TileMaster, an easy to use Tile editor) Sparetime-Development
|
|
|
Re: [ANET] Send coordinates?
[Re: Rasch]
#351847
12/28/10 21:22
12/28/10 21:22
|
Joined: Jul 2005
Posts: 1,930 Austria
Dark_samurai
Serious User
|
Serious User
Joined: Jul 2005
Posts: 1,930
Austria
|
Question 1 is already answered. Entities that need to have the same pointer on all connected hosts should be created with enet_ent_create() and thus get a global pointer.
Why don't you create the bullethole with an event? You could send the position and angle with the event and execute an ent_create() in the event function.
ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)! get free version
|
|
|
|