I am doing a multiplayer game with several players. In this game, player can choose to create little groups to explore world and fight AI.
Question is, I would like to create a UI where I can see the Life of other players in my group. The problem is that I have a solution, but it doesn’t really satisfy me.
My solution is, when my life change, I call an event run on server which will say to the other player of my group that my life change. The problem with this solution is that since I have a regen of life that happens every five seconds, when I am in fight I will call the run on server every five seconds…
I thought that if I have a lot of player in the map, with a lot of groups it will overload the server. But I am not sure that I have any better issue…
hey, I am also working on a multiplayer game and I also had this problem.
my solution was to call this event every few seconds (you called this event life change), except for calling it every time.
by this method you can change the delay of the configuration and see what is good to your internet and what satisfying you
Yes, it is a solution that I find too, my regen is done every 5 seconds so I can update the life every 5 seconds or even every 2 or 3 seconds but I was wondering if it was possible that a better solution exist (but it seems that we haven’t other choice). Thank you for your answer by the way
I will look at your question but not sure that I have the answer.
The life of your players should be managed by the server, not by the client.
Your client should never send its life to the server, that’s a wide open door for invulnerability cheats.
Health changes, whether it is damage or regeneration, should happen on the server code, and then be replicated to clients.
For that kind of replication you want to favor using a replicated variable, rather than a RPC. The variable replication will be all automatic and managed by the engine with builtin bandwidth considerations.
Furthermore if you want to keep an event-based approach for the UI, you can enable RepNotify replication mode, and act upon the OnRep function which is triggered whenever variable is updated on clients.
If you really want to stick with clients managing their own health and sending it over to the server, then yes a “Run On Server” event is your only solution. That will only send the health over to server however, so you still need to replicate health from server to all other clients. A replicated variable is still a good option.
No, I think you misunderstood. When I say that the player may communicate together and send their life, it was only for cosmetic purposes. If someone cheat and send a false life, then I don’t care since it is only to display it, not to manage regen or damage
And the problem here is mainly to know the life of other player in my group, not my life. For my life I manage to do it well
My solution is, when my life change, I call an event run on server which will say to the other player of my group that my life change.
From this quote it seemed like your life changes are happening on the client.
I don’t know how your stuff works so more context might be required.
If you are already doing life updates on the server, and your client displays his own life fine, then that means you are already replicating it. How are you replicating it ? Variable? RPC? On which class?
If you have a life/health variable in your character class that is set to replicate, then you can already read that variable on every other client and don’t have to do anything extra, just display it.