Trying to replicate my weapons system, issues with replicated map of strings

Well, maps cannot replicate, so you’ll have to find a different way to do this.

Looking at your graphs, using a map and having as many branches as map keys, seems counterproductive to me. The whole point of using such a data structure would be to refactor everything into a single execution flow. In your graph, you’d be better off with using direct variables instead of a map, ie. one variable for the Primary weapon struct, one for Secondary weapon struct, and one for the Nuke weapon struct.

Another point worth mentioning is, checks should always be made on the server. Do the client(s) really need to make them ? As a general rule, server should never trust clients, but on the opposite, clients can trust the server.

Finally, if you really wanna stick to such a data structure, simply switch to Array instead. Arrays replicate fine and in an optimized way. So instead of having the key in the map, put it in the weapon info struct. Then when you need to find “Secondary”, iterate the array (foreach) and look for the first item with key “Secondary”. This may look suboptimal, but keep in mind accessing a Map is not instantaneous either, it requires hashing the key which may even be slower than iterating array when the array is small.
Alternatively, instead of referencing by string “Secondary” “Primary” etc, assign an arbitrary index to each weapon type, ie. 0=Primary, 1=Secondary, 2=Nuke, etc. then just access the array at desired index. Just make sure to pre-define array size at initialization to avoid indexing out of bounds.

1 Like