Posted By: exile
Quick help with removing entities - 12/24/11 08:31
As the title suggests, I am in a bit of a pickle. To keep it short and sweet when I fire a bullet from the server...
-Bullet is created and is set on its course.
-when bullet has hit something or is too far from the player, its removed.
-When bullet is removed, only the server can see it removed. Clients still see the bullet stuck wherever it hit.
And when I fire a bullet on the client side...
-bullet is created, however for one frame its in its default pan, tilt, and roll, then begins to move in the correct direction with the correct pan, tilt, roll.
- When the client bullet hits something, I get a crash on ALL clients.
-However, the server shows the bullet as "removed"
I am left to believe one of two things are happening. Either the server is deleting the bullet too early, thus returning an empty pointer on all clients, or when the client bullet is removed, it try's to remove anything with the "my" pointer. Im completely lost on this issue, and am in great need of help.
Posted By: SchokoKeks
Re: Quick help with removing entities - 12/28/11 12:46
I don't think that ent_create works well for something as short-lived as a bullet.
At least in older versions, you had to wait at least half a second until you could use ent_remove or any function that uses the network on the server after creation. On very slow connection, even half a second could possibly be too short. This might be the "bug"/feature you are encountering.
Also, your code is bad security wise. If you allow clients to use ent_create to create bullets, it would be very easy to write a script that would inject thousends of shots per second on all directions into the network traffic. But 3DGS native network security is nonexistent anyway, so you might as well ignore this.
Create your own network "protocol" for shooting.
Send skills or a struct that has all the necessary information to all clients, and let them handle the bullet locally (ent_createlocal).
Problem is that you'd have to rely on the local collision for removing the bullet, so it might not be perfectly on sync with the server.
You could also create a new entity-system just for bullets, by giving them IDs and removing them using these ids. That way you could have the server do the collision.
Posted By: exile
Re: Quick help with removing entities - 12/28/11 14:12
Oh no, thats not how it works. When then client shoots, a "client shot' message is sent to the server, then the bullets position and angles are sent to all of the clients and the bullet gets created on all clients. Essentially, the client is just informing the server they shot. The server does all the work.
Here is the source in case if anyone wants to see.
http://www.filedropper.com/multiplayer8cd
Posted By: SchokoKeks
Re: Quick help with removing entities - 12/28/11 18:27
okay, so how exactly does the bullet get created on all clients?
does the server do ent_create?
or do the clients use ent_createlocal?
If the server uses ent_create then my points above probably are still valid. The current manual says:
On multiplayer systems, it can take up to 0.5 seconds until the created entity is copied to all connected machines. During that time, the entity handle can not be used, entity skills can not be sent (►send_skill()) and the client_id parameter is not set. client_id can be polled for determining when the entity is ready on all machines: while (my.client_id != dplay_id) wait(1); .
thats a delay that should not happen on multiplayer systems. It doesn't clearly say whether this delay is shorter when the server uses ent_create.
Posted By: exile
Re: Quick help with removing entities - 12/29/11 06:09
Just download the file, its got the source and everything in it.
Posted By: exile
Re: Quick help with removing entities - 01/06/12 00:22
Any one else have any ideas? I re uploaded the file.
http://www.mediafire.com/?nvq2tzf8429p262