Help on getting started with Modding

ArgiArgi Join Date: 2004-07-24 Member: 30069Members, Constellation, NS2 Playtester, Reinforced - Shadow
Hey,

I'm wanting to create a new mod and one of the tasks I need to do is hook into the tech tree upgrades and send a notification to the client when a new research upgrade is started. For example, when shotguns research is started, the client should receive this notification. When a client joins a team, they should receive notifications on current research and the time remaining.

I'm trying to understand how to plug into the code to get the basic functionality of sending a notification on research start. I've been digging through existing mods, and the Shine-based mods seem to have a custom hooking mechanism to replace function calls presumably in the main NS code which provides some form of override behaviour that you would see in C# (sub classes can override virtual methods of their parents).

Is this the "normal" way of injecting code? I do see that there are some events but they are mainly related to the engine, and not the game logic.

Thanks!

Comments

  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    If you're a seasoned software developer, then by all means go ahead. Although, if you're just getting into programming I strongly suggest you start with something simpler.
    Be sure and peruse through the 'docs' folder. That will give you a good idea of what the C-Level API calls are, but for what you're wanting to do, you shouldn't really need these functions. However, for what you're wanting to do specifically isn't a quick thing.

    I suggest you try to not look at the source code from an OOP-Type perspective. While having that level of understanding is beneficial, it can also be confusing in some cases. This is due to how Lua works. Lua does not have a Class in the traditional sense of that concept. All of the "classes" are actually just Lua Tables.

    If you're wanting to make a Shine Addon, then definitely use the methods described in the Shine source files. If you're wanting to make a mod for NS2, I strongly recommend you use the existing Hooks-Framework. For the subject you've described you will run into a little bit of a problem. There is no good and clean way to override parts of any GUIScripts within the NS2 code-base. So, I recommend either creating a new GUIScript from scratch and then specifying it in your mods ClientUI.lua file, or overriding (completely) one of the existing GUIScripts.

    To get you started, take a look at MarineTechMap.lua, AlienTechMap.lua, and GUITechMap.lua. These files essentially have all the functionality you need. The TechTree is managed by the server and propigates to Clients already.
  • ArgiArgi Join Date: 2004-07-24 Member: 30069Members, Constellation, NS2 Playtester, Reinforced - Shadow
    edited June 2014
    This is due to how Lua works. Lua does not have a Class in the traditional sense of that concept. All of the "classes" are actually just Lua Tables.

    Shrine does seem to hack around with the table to load its hooks. Makes total sense.
    local function RecursivelyReplaceMethod( Class, Method, Func, Original )
    	local ClassTable = _G[ Class ]
    
    	if ClassTable[ Method ] ~= Original then return end
    
    	ClassTable[ Method ] = Func
    ...
    

    The GUI I'm less interested in [for the moment] until I have a mechanism for sending the data down.

    From what I can see in the code, it would be something along the lines of.
    1. Hook into Commander:AttemptToResearchOrUpgrade in Commander_Server.lua using Class_Reload (I think that's the hooking you're referring to)
    2. If original func returns true, get time remaining
    3. Send techId and time remaining to the client
    4. Client receives network message, writes out to the console.

    That would be a start, anyhow.

    From there,
    1. Hook into NS2Gamerules:JoinTeam
    2. If success, get list of currently researching tech
    3. Send client techId and time remaining for all upgrades currently being researched
  • McGlaspieMcGlaspie www.team156.com Join Date: 2010-07-26 Member: 73044Members, Super Administrators, Forum Admins, NS2 Developer, NS2 Playtester, Squad Five Blue, Squad Five Silver, Squad Five Gold, Reinforced - Onos, WC 2013 - Gold, Subnautica Playtester
    No need to go to that length. The Clients are already getting Tech and Tech-Status updates via the TechTree network traffic.

    Take a look at GUITechMap.lua, it is doing exactly what you are looking for. The easiest thing you could do, is modify the GUITechMap script, and add a sub-update routine to it. This new routine would operate on a local table (global in scope of the GUITechMap script), and get updated everytime the Update() function is called. Then all you need to do is create the new GUI elements to govern what, where, and how Researching Techs are shown. Just be sure you don't set these new elements as children to GUITechMap.background, as this element's visibility is toggled.

    You can also take a look at GUIProduction.lua for another way of handling it. Long story short, all of the underlying mechanisms you need are already in place. All that needs to be done IS the GUI work.

Sign In or Register to comment.