Help with network co-op RPG logic please

Hello everyone!

I really need help from some experienced one about multiplayer. I’m making a Diablo like game with coop for up to 4 players and i’m going nuts with lots of coffusion i found in the way about networking.

The problem is, i got lost when learning about server-client authority and client lockstep, which one is more appropriate for my game design, and i am facing a lot of problems on state synchonization. I dont know if it is better to make a client based game, and make the players communicate between them only using the server as some kind of router, or if is better have everyone synched to the server and let the server make the decisions and calculations.
One of the worst problems is synchronize the characters stats and equipments, my current setup is every single stat being an object, so instead of having like “public int strength” i have “public CharacterStat strength”. I made this way to have better controll over bonus stats, fixed stats and temporary bonuses for those stats. And the same for weapons, but they use a inheritence of others classes like:
Item > EquipmentItem > WeaponItem

And inside the WeaponItem i have a list of applicable CharacterStat bonuses aside of other properties.

For the offline single player this archtecture is working just fine, but for the multiplayer it caused a BIG conffusion about what should i sync, and how. Considering that players can join any time, how can i make sure every player can see the current game state?
And the SyncVars is limitted to 32 per script, i’m afraid this limitation has something to do with performance and my characters will have lots of stats (nearly 30 or maybe more in the future), then i guess this would lead to poor network performance, right?
Should i serialize the CharacterStats for every client and use SyncVars to keep them on server side, or should i make some sort of custom buffer to load each character when a player joins the game?

So i just wanted suggestions about what should i seek for, or if some one can point me some source to learn, this conffusion is driving me nuts.

  • Sorry for my bad english, its not my first lang

i suggest you don’t sync every stat var all the time, just the stuff that changes. if stats are based off like level and equipment, then you probably don’t need to sync that stuff at all…just send an rpc/command whenever a client changes their gear, indicating what their new gear Id is. of course when a player first connects, they might need to send a bigger snapshot of all their stats/loadouts as a starting point, but doing this once during initialization shouldn’t be a problem.

i’m don’t have a ton to say about your lockstep problems. doing lockstep stuff is a pain, and your work will be easier if you can avoid crossing that bridge. lockstep stuff is great if you have tons of enemies you need to sync at once, though. but be prepared to make deterministic game logic and/or physics.

thanks very much for your reply!

yes, i dont think i might need a lockstep here like on a RTS game or something, there will be a small number of characters on the screen. what i’m doing now is something like you suggested, whenever one of the players changes equipments, or they levelup, or get any buffs, i have the CharacterStat fields encapsulated so on “SetStat” i serialize it and update via RPC for all clients. but them another question comes up, is it OK to serialize a stat via byte array and update whenever it changes?

for exemple, if my character receive a temporary buff that grants it +50 maximum hp for 10 seconds, i would serialize the stat into byte array and make a RPC to update it for all clients, and after 10 seconds another RPC updating the MaxHP stat to remove that bonus.

again, thanks for your help! :smile:

Are you sure you need to update stats for all clients? If for example you used server authority for everything, likely only the server needs to know what a player’s stats are for the purpose of movement speeds and battle effects. The client which owns the player would need stat updates for display purposes, but it is unlikely all the other clients need stat updates.

Yeees, like i said i’m very confused xD. Now i already discarded the total sync, but like you said, i still need to send the info for the player when it needs to display something. Could you help me a bit more on this subject? Thats exactly what im trying to do right now but i dont know when should i send the stats for the local player (i mean the one who owns the character), should i send stat by stat depending on demand? e.g. when i update the maxHP stat, i manually sync ONLY the maxHP stat using RPC? Or should i use the Unet OnSerialize/OnDeserialize and update all the stats but only for the local player? Thanks for your reply!