Trying to include lua in a combat mode level
bp2008
Join Date: 2012-11-28 Member: 173581Members, Reinforced - Shadow, WC 2013 - Gold
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?
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
<a href="https://github.com/JimWest/ExtraEntitesMod/blob/master/lua/NS2Gamerules_hook.lua" target="_blank">https://github.com/JimWest/ExtraEntitesMod/...erules_hook.lua</a>
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...
(But I haven't tried if this works together with combat, you have to try it).
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?
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.
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.
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.
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!