I was planning to make a mod that uses mech horn slot as weapons and such but it seems that I need to change the lua about the mech. Is there any way to overwrite or patch the lua? Either that, or any modding advice would be nice.
You can overwrite scripts simply by putting the same scripts in your mod. Note that this may lead to mod conflicts as Lua scripts can't be patched, and only the 'last' loaded version of the script will be used (which may or may not be yours).
You can create a patch to the mech itself to point to an alternate script you would then provide. Of course, should another mod change and/or also patch a new script, you can expect some obvious difficulties.
You can the best way is to write a separate lua file for the changes you want to make and then make a patch that would include the script where the lua script you want to mod is being used. You should do it like this so you can limit the number of changes you make to the lua script and thus increase compatibility with other mods and helps with keeping the mod working across updates. If you are not removing methods or function calls then you can do something like this: oldfunction = originalfunction function originalfunction(variables) your code here oldfunction(variables) maybe more of your code here end This can further increase compatibility with other mods because now you are limiting your changes to specific variables in the script at worst or you could be adding your own variables and function calls which should not conflict with other mods if you name them properly If another mod is also patching the same script if they use this method it most likely will be fine if they are not editing the same variable but if they are just completely replacing the script or function you should still be fine as long as you mod is loaded after theirs.
Thanks for all the help, guys. I did started working on the mod I was trying to make and was able to get the new lua running for the mech, but it kept getting crashes when using the custom weaponized horn. Hmm... I think I should try Mobius58's way one more time.
OK I was just trying to do what you said, but how do I add one more script on this? This is the sample of the original 'modularmech.vehicle' { "name" : "modularmech", "boundBox" : [-32.0, -32.0, 32.0, 32.0], "slaveControlTimeout" : 2.0, "slaveControlHeartbeat" : 1.0, "canBeHit" : true, "keepAlive" : true, "persistent" : false, "clientEntityMode" : "ClientMasterAllowed", "script" : "/vehicles/modularmech/modularmech.lua", "scriptDelta" : 1, "animation" : "/vehicles/modularmech/modularmech.animation", and so on..... Um... Do I just add? Or do I have to fix the scriptDelta too? (What is it by the way?!)
Some assets use a "scripts" parameter, rather than a "script" parameter, which is an array of strings rather than a single string. You can try replacing the script line with a scripts array, but chances are high it won't work. Code: "scripts": [ "/vehicles/modularmech/modularmech.lua", "/scripts/myMechScript.lua", ],
Tried it but didn't work. In fact, it seems that the only choice I have is to overwrite modularmech.lua itself and even that does not prove to work I think I shall let this go and work on more simpler mod I had in mind. Anyway, thanks for all the help!