Help on getting started with Modding
Argi
Join Date: 2004-07-24 Member: 30069Members, Constellation, NS2 Playtester, Reinforced - Shadow
in Modding
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!
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
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.
Shrine does seem to hack around with the table to load its hooks. Makes total sense.
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.
That would be a start, anyhow.
From there,
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.