Modding newbie problems

TyphonTyphon Join Date: 2002-11-01 Member: 1899Members
edited August 2012 in Modding
<div class="IPBDescription">what am I doing wrong?</div>Decided to try to learn how to do some basic modding for ns2. First step, just wanted to mess with the minimap colors. So I open the ns2 project in decoda, get to the minimap code (GUIMinimap.lua), create a local game, find this line:

GUIMinimap.kTeamColors[kMinimapBlipTeam.Friendly] = Color(0, 1, 0, 1)

Change it to

GUIMinimap.kTeamColors[kMinimapBlipTeam.Friendly] = Color(0, 1, 1, 1)

(just wanting to confirm that Color takes R, G, B, Alpha), save the file, alt-tab back into game, and....problems. I don't see any color change, and some of my GUI has frozen (arrow indicating player's position won't animate, alien vision blips not updating, etc.)

Is there something special I need to do to make the dynamic loading of altered LUA files work?

Comments

  • DghelneshiDghelneshi Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
    edited August 2012
    The problem is that the game can't know what to uninitialize and what not when reloading the Lua files. You can't reinitialize every single class instance in the game or it will just be as good as creating a new game which then isn't really hot-loading anymore. UWE could go through every single class and tell the game whether it should reload this or not, but that's a few man hours spent.

    So, the old instances of your HUD elements are not being uninitialized, which is why they are still on your screen. They are stuck because they are from before reloading the file and cannot be referenced by the game anymore. Whenever you change any HUD elements, go back to the readyroom before doing any changes (since there are no HUD elements in the RR apart from name tags on players). You should also start the game in windowed mode, otherwise you will have a few seconds to minutes of lag whenever you alt+tab back into the game because the local server has to "catch up" with what has happened in the meantime because it is in some sort of sleep mode when it is in the background and in full-screen mode.
    If you make changes to server side files, you will unfortunately have to recreate the game 99% of the time because the server usually completely breaks when reinitializing one of the classes (e.g. error spam in console).

    By the way, <b>never</b> change the original files. Always copy them to a new folder alongside ns2 with the same folder structure and use "-game foldername" on the shortcut to start the game with the modded files (<a href="https://pickhost.eu/images/0005/3950/Natural_Selection_2_Mod_Setup.jpg" target="_blank">this is what my setup looks like</a>). This way, if you accidently break something, you won't have to verify integrity and lose all of your changes in the process and you also have an overview of what files you've changed and which changes you've made. The only downside is that Decoda can be really confused and break stuff if you open two files with the same name in different folders, so don't do that. I personally use a text editor with syntax highlighting support for modding (most people use Notepad++, it's free) and have the NS2 project open in Decoda in the background when I want to search for something (the Find in Files function [Ctrl+Shift+F] is incredibly useful).

    If you need any more help or just didn't understand anything of what I just said, <a href="http://steamcommunity.com/id/dghelneshi" target="_blank">hit me up on Steam</a>.
  • TyphonTyphon Join Date: 2002-11-01 Member: 1899Members
    Ok, that makes sense, although after hearing all the pr about how the engine supports dynamic reloading and how easy that makes development its a little disappointing.

    Is there any way to know before hand if a particular change is going to be dynamic reloading compatible or not other than just trying it and seeing if anything breaks?

    Is there any way to directly call certain functions from the console? For example I can see that GUIMinimap has a very obvious Initialize and Uninitialize functions, is there any way to just open the console and tell it to run GUIMinimap:Uninitialize then GUIMinimap:Initialize (assuming that if this were possible it would fix my problem)?
  • 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
    The UI frames getting stuck is because of this line in GUIManager.lua
    local gGUIManager = nil

    Its the variable that holds the single created instance of GUIManager that keeps track of and updates frames. Whenever a hot reload happens gGUIManager is reset to nil which causes GetGUIManager() to create new instance of GUIManager that knows nothing about all the existing frames created
    If you remove local from the variable declaration it should fix frames getting stuck

    <!--quoteo--><div class='quotetop'>QUOTE </div><div class='quotemain'><!--quotec-->Is there any way to directly call certain functions from the console? For example I can see that GUIMinimap has a very obvious Initialize and Uninitialize functions, is there any way to just open the console and tell it to run GUIMinimap:Uninitialize then GUIMinimap:Initialize (assuming that if this were possible it would fix my problem)?<!--QuoteEnd--></div><!--QuoteEEnd-->

    This snippet of code should create console command to recreate the minimap I haven't tested but in theory it should work

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->Event.Hook("Console_reloadmap", function()
      GetGUIManager():DestroyGUIScriptSingle("GUIMinimap")

      local player = Client.GetLocalPlayer()
      player.minimapScript = GetGUIManager():CreateGUIScriptSingle("GUIMinimap")
    end)<!--c2--></div><!--ec2-->
  • plausiblesargeplausiblesarge Join Date: 2012-08-02 Member: 154558Members
    Can I add any of you fine gentlemen on steam? My LUA skills are below sub-par
Sign In or Register to comment.