So i have an hp bar over the top of a building to show the hp and i replicated it successfully on both client and server ends here’s the code:
Note: the pins on the events are the damage amount
now the issue here is that for some reason the client fires 1 extra time Only the first time the building takes damage so it makes the building’s hp on the client less than the server in the end.
not sure if it can be in the screenshot…the one on the left is the server and the right is the client
my guess is probably i should add something like a “switch has authority” node somewhere maybe? i ain’t sure really
Server should Apply and Set damage.
Clients should only READ the replicated values.
i am a bit confused here…i am using an RPC for the Damage to be set by the server and the Multicast is to apply the damage on the clients…it’s the only way i could come up with to set a direct and non restricting interaction between the actor (building) and whatever that would damage it…executing the whole thing just through the server by using an RPC custom event (which i tried) didn’t update on client since it’s just happening on the server , doing it through the Gamemode or Controller would be very restricting too since this is a thing that will occur on units (RTS game) as well.
don’t get me wrong…i don’t mean to dismiss your solution, it’s just the whole server/client dynamic confuses me so i dont know exactly how i can get the server to apply and set damage in a reliable way through the actor itself yet still update on the clients.
First the Server should be doing the Hits that calc dmg. Clients should never send a value to apply as dmg. There’s nothing stopping a malicious client from saying it did 10,000 dmg.
Second the server should be doing the Math and Setting a replicated var. That value will get replicated to every client. You do not need to have every client do the math. This is the whole point of replicated vars.
Alternatively you can set the HP variable as Rep Notify which will execute its OnRep Function. That function can be made to virtually anything on the client.