blindcoder Posted September 4, 2014 Share Posted September 4, 2014 Hello. I want to change some behaviour in the current trapping system. For that, I want to override ISTrap:addBait and ISTrap:removeBait. Is that possible by just creating a media/lua/server/Traps/ISTrap.lua and re-defining those two functions? Or is there some more magic to do so? Link to comment Share on other sites More sharing options...
Jatta Pake Posted September 4, 2014 Share Posted September 4, 2014 I am brand spankin new to this LUA stuff but I *think* the answer is yes. Any LUA in the mods folder with same named functions will overwrite base code LUA. I'm interested in hearing if someone can confirm. I'd like to embed new functions to existing base functions for my next mod. Link to comment Share on other sites More sharing options...
RoboMat Posted September 4, 2014 Share Posted September 4, 2014 You'll have to make sure that your module is loaded after the vanilla one ... which can be tricky in Zomboid since all scripts are loaded at the same time. Link to comment Share on other sites More sharing options...
wsensor Posted September 4, 2014 Share Posted September 4, 2014 Hmm maybe give it a priority ranking? 1-9 with each one in order of how it should be loaded? IE: Each number would load after the original scripts but the higher the number the later it loads? Link to comment Share on other sites More sharing options...
EnigmaGrey Posted September 4, 2014 Share Posted September 4, 2014 If you watch the loader, you'll find the %username%\mods\ directory is now always loaded last, its contents itself loaded alphabetically. A require statement should slightly change the order but . . . well . . . it might not, too. Link to comment Share on other sites More sharing options...
RoboMat Posted September 4, 2014 Share Posted September 4, 2014 \o/ Link to comment Share on other sites More sharing options...
Jatta Pake Posted September 4, 2014 Share Posted September 4, 2014 Just to dive further down the rabbit hole, Blindcoder doesn't need to overwrite the entire ISTrap.lua if he's only altering specific functions within ISTrap.lua (assuming ISTrap.lua has multiple functions inside - I can't check at the moment), correct? He could create his own file called ISBlindCoderTrap.lua, include only the functions he is tweaking but use the base function name, drop it in the proper mod folder, and he would be good to go? Link to comment Share on other sites More sharing options...
RoboMat Posted September 4, 2014 Share Posted September 4, 2014 No, as long as the function isn't local to the file it is in you can overwrite it. local oldFunction = table.function; -- store old functiontable.function = newFunction; -- overwrite the old function Link to comment Share on other sites More sharing options...
Jatta Pake Posted September 4, 2014 Share Posted September 4, 2014 Do you mean "No, he doesn't need to overwrite the entire file" or "No, Jatta Pake you are incorrect and he does need to overwrite the entire file"? Sorry for not understanding your reply, I'm not the sharpest tool in the shed and I'm on hour 36 with no sleep. Link to comment Share on other sites More sharing options...
RoboMat Posted September 4, 2014 Share Posted September 4, 2014 No he can just overwrite the functions he wants to change, not the entire file. I've done that back in the day for my sleeping mod. Jatta Pake 1 Link to comment Share on other sites More sharing options...
blindcoder Posted September 5, 2014 Author Share Posted September 5, 2014 Great, thanks! I'll try that and get back to you all Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now