Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/22/24 13:41
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AemStones, AndrewAMD, gamers, Kingware), 1,590 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
LucasJoshua, Baklazhan, Hanky27, firatv, wandaluciaia
19054 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
[ANET] Send coordinates? #351490
12/25/10 20:56
12/25/10 20:56
Joined: Jun 2008
Posts: 428
Rasch Offline OP
Senior Member
Rasch  Offline 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.
Code:
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.

Code:
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 laugh

Re: [ANET] Send coordinates? [Re: Rasch] #351514
12/26/10 07:15
12/26/10 07:15
Joined: Dec 2010
Posts: 63
C
Ceryni Offline
Junior Member
Ceryni  Offline
Junior Member
C

Joined: Dec 2010
Posts: 63
do it like they done it i the simple 3d demo

str_cpy((g_data->pstring)[1],msg);

or try aut the enet_send_array function you can find it in the manual.

Re: [ANET] Send coordinates? [Re: Ceryni] #351695
12/27/10 22:35
12/27/10 22:35
Joined: Jun 2008
Posts: 428
Rasch Offline OP
Senior Member
Rasch  Offline OP
Senior Member

Joined: Jun 2008
Posts: 428
thanks but that donīt really help cause...

1) i want to know how to send these datas with the "event send" function and how to receive.

2) if i send via array the problem is how should that work? Sending the array first, waiting a few frames and then sending the event?

Thanks

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 Offline
Serious User
Dark_samurai  Offline
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!):
Code:
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:
Code:
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 wink


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 Offline OP
Senior Member
Rasch  Offline OP
Senior Member

Joined: Jun 2008
Posts: 428
Thank you very much Dark_samurai. It works perfectly grin

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:

Code:
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 grin

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 Offline
Serious User
Rackscha  Offline
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

Code:
enet_ent_globpointer(you);



to get a var holding the global Anet entity pointer.

Send it and when received do

Code:
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: Rackscha] #351838
12/28/10 20:21
12/28/10 20:21
Joined: Jun 2008
Posts: 428
Rasch Offline OP
Senior Member
Rasch  Offline OP
Senior Member

Joined: Jun 2008
Posts: 428
Thank you very much it works great. Iīm now getting the pointer "id" and can use it with these one.

Code:
you = enet_ent_locpointer(entity_pointer); // Set the pointer
enet_ent_remove(enet_ent_globpointer(you)); // remove entity



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 Offline
Serious User
Rackscha  Offline
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 wink

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: Rackscha] #351845
12/28/10 21:13
12/28/10 21:13
Joined: Jun 2008
Posts: 428
Rasch Offline OP
Senior Member
Rasch  Offline OP
Senior Member

Joined: Jun 2008
Posts: 428
Ok you are right. That also works.

Thank you very much laugh

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 Offline
Serious User
Dark_samurai  Offline
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
Page 1 of 2 1 2

Moderated by  HeelX, Spirit 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1