Gamerev147
Member
Background
I have a fairly basic server system setup, and it is as follows:
My server and client are two separate projects. My server simply receives data from each client and sends that data back out to every client that is connected. This way, on the client end I can say something like “if my id isn’t the same as the one being sent to me, update the instance of that id”. My client retrieves the data sent from the server and decides what to do with it and who to assign it to in the Async Networking event.
Issue Description
I’m attempting to create bots (I.e Police or Swat team) that players connected to the server will have to work together to defeat. Within attempting this, I realized I have no idea how to do this, as I’m pretty familiar with player PvP and such in GM's networking (not bots). So I used GravityShift Game’s tutorial on Native Networking NPC’s for reference. I created an object to spawn and also send the data of these enemies on the client-side.
The code I’m using to try and create these bots is listed below. I organized it in the best way that I could.
obj_net_SpawnEnemy - Create Event
obj_net_SpawnEnemy - Step Event
The server then receives this data and sends it back to all of the clients.
Obj_Client - Async Networking
Obviously, the issue is that about a million instances of the enemy spawns because there’s nothing really keeping track of them. How could I implement a way to track each instance of the enemy, and sync that with all of the other clients? Any help would be appreciated.
Thanks!
I have a fairly basic server system setup, and it is as follows:
My server and client are two separate projects. My server simply receives data from each client and sends that data back out to every client that is connected. This way, on the client end I can say something like “if my id isn’t the same as the one being sent to me, update the instance of that id”. My client retrieves the data sent from the server and decides what to do with it and who to assign it to in the Async Networking event.
Issue Description
I’m attempting to create bots (I.e Police or Swat team) that players connected to the server will have to work together to defeat. Within attempting this, I realized I have no idea how to do this, as I’m pretty familiar with player PvP and such in GM's networking (not bots). So I used GravityShift Game’s tutorial on Native Networking NPC’s for reference. I created an object to spawn and also send the data of these enemies on the client-side.
The code I’m using to try and create these bots is listed below. I organized it in the best way that I could.
obj_net_SpawnEnemy - Create Event
GML:
instance_create_layer(x, y, layer, net_SwatEnemy);
Code:
//Send the data of each enemy to the server
for (var i = 0; i < instance_number(net_SwatEnemy); i++) {
var enemy = instance_find(net_SwatEnemy, i);
//Send our data
var ebuff = buffer_create(64, buffer_grow, 1);
buffer_seek(ebuff, buffer_seek_start, 0);
buffer_write(ebuff, buffer_u8, network.swat);
buffer_write(ebuff, buffer_u16, enemy.enemy_id);
buffer_write(ebuff, buffer_s16, enemy.x);
buffer_write(ebuff, buffer_s16, enemy.y);
buffer_write(ebuff, buffer_s16, enemy.image_angle);
network_send_packet(obj_Client.client, ebuff, buffer_tell(ebuff));
buffer_delete(ebuff);
}
Obj_Client - Async Networking
Code:
//Snippet from full code:
case network.swat:
var _enemy_id = buffer_read(packet, buffer_u16);
var _enemy_x = buffer_read(packet, buffer_s16);
var _enemy_y = buffer_read(packet, buffer_s16);
var _enemy_angle = buffer_read(packet, buffer_s16);
var e = instance_create_layer(_enemy_x, _enemy_y, layer, net_SwatEnemy);
e.enemy_id = _enemy_id;
e.image_angle = _enemy_angle;
break;
Thanks!