NetworkVars
Dghelneshi
Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
Hey guys,
I'm currently in the process of making a mod for Skycam to give spectators a useful UI with all the information on the current game you could ever want.
After a few failed attempts I am finally settling with expanding TeamInfo to convey information from the playing teams to the spectators. I would like to have a complete tech tree for both teams, including all upgrades and research (rmor/weapons 1/2/3, weapons, advanced armory, etc.) and my problem right now is that I don't know how to set a networkVar in TeamInfo for this.
I have never seen a table as a data type for networkVars and "table" doesn't work. I'd really hate to have to do a bitmask for this, as I can't get a research progress percentage into a bitmask, for example. The type isn't even just a normal table, it's a nested table with techTree being a numeric table of elements which are tables containing "researched" and "researching" as booleans and "progress" as float.
Another question would be whether it's even feasible having a potentially huge table networked (I'm currently planning to initialize from 1 to kTechIdMax and insert into techTree[techId] for ease of coding, though I could make it smaller if it's too much). I don't really know at all how networkVars and such work so if you could give me some general elucidation, it would be very much appreciated.
Thanks for taking the time to read, I hope someone has an idea how to do this.
I'm currently in the process of making a mod for Skycam to give spectators a useful UI with all the information on the current game you could ever want.
After a few failed attempts I am finally settling with expanding TeamInfo to convey information from the playing teams to the spectators. I would like to have a complete tech tree for both teams, including all upgrades and research (rmor/weapons 1/2/3, weapons, advanced armory, etc.) and my problem right now is that I don't know how to set a networkVar in TeamInfo for this.
I have never seen a table as a data type for networkVars and "table" doesn't work. I'd really hate to have to do a bitmask for this, as I can't get a research progress percentage into a bitmask, for example. The type isn't even just a normal table, it's a nested table with techTree being a numeric table of elements which are tables containing "researched" and "researching" as booleans and "progress" as float.
Another question would be whether it's even feasible having a potentially huge table networked (I'm currently planning to initialize from 1 to kTechIdMax and insert into techTree[techId] for ease of coding, though I could make it smaller if it's too much). I don't really know at all how networkVars and such work so if you could give me some general elucidation, it would be very much appreciated.
Thanks for taking the time to read, I hope someone has an idea how to do this.
Comments
Server.SendNetworkMessage(player, "TechNodeBase", BuildTechNodeBaseMessage(techNode), true)
function BuildTechNodeBaseMessage(techNode)
local t = {}
t.techId = techNode.techId
t.techType = techNode.techType
t.prereq1 = techNode.prereq1
t.prereq2 = techNode.prereq2
t.addOnTechId = techNode.addOnTechId
t.cost = techNode.cost
t.available = techNode.available
t.time = techNode.time
t.researchProgress = techNode.researchProgress
t.prereqResearchProgress = techNode.prereqResearchProgress
t.researched = techNode.researched
t.researching = techNode.researching
t.requiresTarget = techNode.requiresTarget
return t
end
server sends node by node to the player, that player stores all nodes (next update overwrites that then). so basically all you need to do is to add the spectators in the list of players which should receive those techtree updates.
on client side you have this
Client.HookNetworkMessage("TechNodeBase", OnCommandTechNodeBase)
the problem with this now is that the client assumes that he belongs to one team, and maintains the techtree for one team only. you would need to extent the network message by another boolean (isTeamOne or something) and add support for that client side.
once we give the spectator ui an overhaul i will possibly make those changes and also add support to display research/construction queues, although it would be easier (not better) to create kind of a "SpectatorInfo" class that contains a big list of boolean/integer netvars since not everything in the techtree is important
edit:
for your second question take a look at function GetTextureCoordinatesForIcon(techId, isMarine) in GUIUtility.lua
edit2:
i will maybe rewrite some day the tech tree and make it entity based. that creates a bit of overhead (position and so on), but other than with network messages sending updates are managed by the engine and no messages are send unless the entity changes. that would simplify the techtree and we could use the same functionality on server and client without having to worry about sending updates
Huge thanks for the reply. :)
I've got it working with two bitmasks in TeamInfo now. I think I will keep using this for now, as I've already tried things like a SpectatorInfo class and other things but I just can't get it to do what I want. I'm happy I've got something working at all. Maybe I'll give it another try when I have built up enough courage to try again.