NetworkVars

DghelneshiDghelneshi Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
edited April 2012 in Modding
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.

Comments

  • DghelneshiDghelneshi Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
    edited April 2012
    Hm. I have another problem. For my upgrade display, I'd like to make a function that maps kTechIds to a specific UI item so I can make a proper loop instead of having to write hundreds of if-statements which are excruciatingly tedious to change. I also want to dynamically create new UI elements with one of the mapped items as parent, but as there are no pointers in Lua, I can't see how this should work. Any ideas?
  • SewlekSewlek The programmer previously known as Schimmel Join Date: 2003-05-13 Member: 16247Members, NS2 Developer, NS2 Playtester, Squad Five Gold, Subnautica Developer
    edited April 2012
    the techtree is send through network messages (you cannot use tables in network vars because they have dynamic size)

    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
  • fsfodfsfod uk Join Date: 2004-04-09 Member: 27810Members, NS2 Developer, Constellation, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Subnautica Playtester, NS2 Community Developer, Pistachionauts
    edited April 2012
  • DghelneshiDghelneshi Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
    edited April 2012
    <!--quoteo(post=1924598:date=Apr 12 2012, 03:42 PM:name=Sewlek)--><div class='quotetop'>QUOTE (Sewlek @ Apr 12 2012, 03:42 PM) <a href="index.php?act=findpost&pid=1924598"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->snip<!--QuoteEnd--></div><!--QuoteEEnd-->
    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.
Sign In or Register to comment.