Trying to include lua in a combat mode level

bp2008bp2008 Join Date: 2012-11-28 Member: 173581Members, Reinforced - Shadow, WC 2013 - Gold
edited December 2012 in Modding
Hi all!

I am new to lua coding and NS2 modding in general, so I have a very basic question.

I built a very dark and mostly outdoor level for <a href="http://www.unknownworlds.com/ns2/forums/index.php?showtopic=119151" target="_blank">Combat Mode</a>. I want to increase the range of marine and exo flashlights using lua and include the code in my level mod. That part is easy. The part I'm missing is a <b>clean </b>way to make NS2 load my lua code without using a game_setup.xml. You see, Combat Mode has a game_setup.xml too and apparently NS2 can only use one of these.

I could do it <b>the noob way</b> and modify the default Marine.lua and Exo.lua and include the modified versions in my level mod. But that is, like I said, the noob way and it is just asking for trouble.

Is there another way to do this?

Comments

  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    Use a hooking mechanism, here's an example:
    <a href="https://github.com/JimWest/ExtraEntitesMod/blob/master/lua/NS2Gamerules_hook.lua" target="_blank">https://github.com/JimWest/ExtraEntitesMod/...erules_hook.lua</a>
  • bp2008bp2008 Join Date: 2012-11-28 Member: 173581Members, Reinforced - Shadow, WC 2013 - Gold
    That is exactly the method I used to modify the flashlight properties :)

    But, like I said, I don't know <b>how to make the game engine load my .lua files</b>. As far as I could tell, Combat Mode gets the engine to load its lua files via the game_setup.xml file which is obviously not an option because Combat Mode is already using it.

    If only there was a decent modding tutorial...
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    If you don't use the game_setup, you need to create a Server.lua and Client.lua file that load your files and the load the original files
    (But I haven't tried if this works together with combat, you have to try it).
  • bp2008bp2008 Join Date: 2012-11-28 Member: 173581Members, Reinforced - Shadow, WC 2013 - Gold
    Hmm. I've been working under the assumption that it is impossible to reference the original file that you've overridden with a file of the same name.

    For example, lets assume that I create a Client.lua file and put it in my mod/lua directory, causing the game engine to load mine instead of the original.

    <!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->// MyMod/lua/Client.lua
    Script.Load("lua/Client.lua") // Load the original Client.lua?  Wouldn't this line actually try to load THIS Client.lua recursively instead?
    Script.Load("lua/Marine_Flashlights.lua")
    Script.Load("lua/Exo_Flashlights.lua")<!--c2--></div><!--ec2-->

    Is it even possible to reference the original Client.lua file if I've overridden it with a modded version?
  • MCMLXXXIVMCMLXXXIV Join Date: 2010-04-14 Member: 71400Members
    It's best to give your one a different name. I think that the Soul Catcher example uses e.g. "lua/SoulCatcher/Client.lua". Combat uses "lua/combat_Client.lua".

    I think the main NS2 code is designed so that it can be loaded multiple times, but this can have strange effects on mods that make overrides after the main script has been loaded. I think that as long as yours loaded before Combat, and used the hooks mechanism, it should work fine, but I haven't looked into this in great detail yet.
  • bp2008bp2008 Join Date: 2012-11-28 Member: 173581Members, Reinforced - Shadow, WC 2013 - Gold
    I can't believe it is this much trouble to accomplish such a <b>basic</b> task.

    Every lua mod I've seen gets the code to load in one of two ways:

    1. The author uses a game_setup.xml file to point at a custom, renamed Client.lua (and/or Server.lua). From here, they load the original default Client.lua which they can do because they haven't overridden "lua/Client.lua". If you want to use two mods which both use this game_setup.xml method, you are out of luck. You get only one at a time.

    AND/OR

    2. They modify one of ns2's default lua files and drop it in their mod to override the original. This effectively replaces the default version of the file. So as far as I can tell there is no way to access or load the default version. Instead, you are forced to copy dozens or hundreds of lines of game code into your mod which has the consequence of tying you to a specific version of NS2 - AND your mod is incompatible with any other mod that changed the same file.

    -------------

    Is there really no way for me to say "Hey, NS2, load <b>this_file.lua</b> please" without doing one of the above two things? #1 is impossible and #2 is just silly.
  • JimWestJimWest Join Date: 2010-01-03 Member: 69865Members, Reinforced - Silver
    Ok I have what you want :-)
    Will include an entity (logic_lua) which makes you load costum scripts directly into the map.
    The engine will load them and you don't need to take care that they will be loaded.

    You can then even push the map as level (workshop will not complain when you have a lua folder).

    This is working already but I'm testing it.
  • DghelneshiDghelneshi Aims to surpass Fana in post edits. Join Date: 2011-11-01 Member: 130634Members, Squad Five Blue, Reinforced - Shadow
    edited December 2012
    Can't you forcefully load the original Client.lua with Script.Load("../ns2/lua/Client.lua")? (or "../../ns2/lua/Client.lua"?)
  • xDragonxDragon Join Date: 2012-04-04 Member: 149948Members, NS2 Playtester, Squad Five Gold, NS2 Map Tester, Reinforced - Shadow
    I believe you can do that, but it still presents a problem not having a proper mod loader for NS2, as multiple mods that use game_setup.xml to load simply override eachother, with only one getting loaded.
  • bp2008bp2008 Join Date: 2012-11-28 Member: 173581Members, Reinforced - Shadow, WC 2013 - Gold
    <!--quoteo(post=2040533:date=Dec 5 2012, 02:25 PM:name=JimWest)--><div class='quotetop'>QUOTE (JimWest @ Dec 5 2012, 02:25 PM) <a href="index.php?act=findpost&pid=2040533"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Ok I have what you want :-)
    Will include an entity (logic_lua) which makes you load costum scripts directly into the map.
    The engine will load them and you don't need to take care that they will be loaded.

    You can then even push the map as level (workshop will not complain when you have a lua folder).

    This is working already but I'm testing it.<!--QuoteEnd--></div><!--QuoteEEnd-->

    Awesome! You're building this into Combat Mode and Extra Entities Mod? :D

    <!--quoteo(post=2040554:date=Dec 5 2012, 03:05 PM:name=Dghelneshi)--><div class='quotetop'>QUOTE (Dghelneshi @ Dec 5 2012, 03:05 PM) <a href="index.php?act=findpost&pid=2040554"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->Can't you forcefully load the original Client.lua with Script.Load("../ns2/lua/Client.lua")? (or "../../ns2/lua/Client.lua"?)<!--QuoteEnd--></div><!--QuoteEEnd-->

    For some reason it didn't occur to me to try that.

    <!--quoteo(post=2040605:date=Dec 5 2012, 04:40 PM:name=xDragon)--><div class='quotetop'>QUOTE (xDragon @ Dec 5 2012, 04:40 PM) <a href="index.php?act=findpost&pid=2040605"><{POST_SNAPBACK}></a></div><div class='quotemain'><!--quotec-->I believe you can do that, but it still presents a problem not having a proper mod loader for NS2, as multiple mods that use game_setup.xml to load simply override eachother, with only one getting loaded.<!--QuoteEnd--></div><!--QuoteEEnd-->

    Yeah, I was surprised to find that NS2 doesn't have a proper mod loading scheme!
Sign In or Register to comment.