I’m working on a first person coop zombie shooter for a group project using Unreal Engine 4.27 and the problem is basically in the title. The zombies can chase the client but can’t attack him, they can attack the server only but when they do, the client also takes damage and they both die. I’ve attached and image of the zombie blueprint where the AttackPlayer event is and how the health variable is declared in the PlayerCharacter.h (maybe that has something to do with both taking damage at the same time), I’m still somewhat new to unreal and not familiar with a lot of things. Any help will appreciated.
Casting to the player character and removing health will probably result in the incorrect players having health removed if not all of them especially being called from the server without an instigator. You’ll need to be more specific with whom the damage is being dealt and from who the damage is being dealt to. “Event Any Damage” can give you this flexibility.
For dealing damage over the server you can use “Apply Damage” and pass those variables through a Run on Server event and plug in those respective variables when applying the damage to discern who is causing damage. On the Event Any Damage you can pull those variables to decide what you want to do with the damaged player or player causing damage.
The server event that you can pass this information:
The event that you can apply the damage:
(in this case, the damaged actor is the actor you cast to when applying this damage and the “Killer Player Controller” is the controller variable set from the player controller on event begin play or other such method)
Lastly, the Event Any Damage, is where you can discern who, what, when or where of the damage. The optional Damage Type Class gives a lot of flexibility on what damage occurred:
If you pull off instigated by and have a valid player controller reference, you can add a kill or points to the player causing damage by casting to your player controller and it should reference the correct player causing damage.
If you simply applied damage from this node it would apply to the correct player since it was casting to that player character and “Self” causing the damage, but the other variables would allow that player/server to award points or whatnot to the correct player by allowing you to separate the events with these variables.
Adding a death to that specific player in my case is just a cast to the player state from "Get Controller->Player State-> Cast to your player state and add the death to a replicated integer variable there. You could probably do this on the player controller, but if other players would like to see their replicated stats then the player state is a better option.
If you pull off “Damage Type”, you can “Get Class” and see what damage type was done provided you created a damage type class and passed that variable through to the Event Any Damage.
There are other methods, but this works well for me over a network with many players and offers a lot of control over what you want to do. It allows you to find out who killed you, with what, how much damage was done, and much more. This damage system can be extended to practically any weapon systems you have in place.
Long post… Hope this helps.