We are developing a multiplayer FPS game and have encountered a problem with ammo counting.
AmmoInventory[4] -= 1.f; should deduct 1 ammo from the rocket launcher. However, for some reason, the first time it does this, 2 ammo is deducted instead of 1.
This bug occurs only in multicast. 1 ammo is correctly removed on the server.
So, for example, if our Rocket Launcher has max 30 ammo and I fire one shot, I erroneously get 28 rocket ammo left on multicast and 29 on the server.
Without seeing your code, it’s pretty impossible to tell what’s going on.
However, I’m going to take a wild guess and ASSUME from the little information you’ve provided that you’re calling the function twice because your logic is being ran on both the server and the client. If you don’t tell the code to stop on the client, that client is probably calling the function that removes the ammo on their own version (putting them at 29) while the Server is recieving that same command for whoever shot, calling the function on its end (resulting in 29). BUT the server just called a Multicast, which means it’s going to send that signal to the client (but not the server, because it already ran the function) which is going to be ran on the client only, putting your total count to 28 because it just ran twice for the client.
Hi. I’m the project programmer. I solved the problem doing a check on the server, and then calling a multicast event for the projectile spawning. Now it works perfectly.
On the AmmoInventory[4] -= 1; instruction, I made a Role == ROLE_Authority check, so the operation will be executed only on the server.