Jump to content

Recommended Posts

You can manipulate most Lua scripts using so-called Post-Init functions. You probably know "AddPrefabPostInit()" already. The rest can be seen in data/modutil.lua or in the API example mod.

Mods can also contain a copy of a game file (must be in the same directory, e.g. "../scripts/prefabs"), which will be loaded instead of the original. If two mods do this, the game crashes, I think. So if you do it, make sure to set a priority in modinfo.lua, whereat a high number means your modmain gets loaded first and your files override the other mods' files and a negative number means your mod loads last and your file overrides get ignored if necessary.

Edited by Mobbstar
2 hours ago, Mobbstar said:

You can manipulate most Lua scripts using so-called Post-Init functions. You probably know "AddPrefabPostInit()" already. The rest can be seen in data/modutil.lua or in the API example mod.

Mods can also contain a copy of a game file (must be in the same directory, e.g. "../scripts/prefabs"), which will be loaded instead of the original. If two mods do this, the game crashes, I think. So if you do it, make sure to set a priority in modinfo.lua, whereat a high number means your modmain gets loaded first and your files override the other mods' files and a negative number means your mod loads last and your file overrides get ignored if necessary.

alright. Since one of my mods is supposed to configure Charlie's attack, sanity and frequency (so that people can make darkness easier for noobs, or harder for experienced players) and since the grue is a component and not a prefab, the only thing I can change is the attack value since it's defined by tuning, which I know how to override with mod configurations. If I reference self. values from grue.lua in the configuration settings, will it override correctly? or should I add and edit a grue component lua file within the mod folder?

@mf99k You should be able to use the following (warning: "ThatFunction" is not real):

AddComponentPostInit("grue",function(self)

    local oldfn = self.ThatFunction

    self:ThatFunction(...)

--preedit

        oldfn(...)

--postedit

    end

end)

17 hours ago, Mobbstar said:

@mf99k You should be able to use the following (warning: "ThatFunction" is not real):

AddComponentPostInit("grue",function(self)

    local oldfn = self.ThatFunction

    self:ThatFunction(...)

--preedit

        oldfn(...)

--postedit

    end

end)

So, in theory, I would replace "ThatFunction" with the function I want to configure. How would I apply the modconfigdata to this/is that what I put inside the (...)?

Also, would this code go into modmain.lua?

Just now, mf99k said:

So, in theory, I would replace "ThatFunction" with the function I want to configure. How would I apply the modconfigdata to this/is that what I put inside the (...)?

Also, would this code go into modmain.lua?

Yes, "ThatFunction" can be replaced by an actual function name. You can get mod config data using GetModConfigData("name"), I recommend you save the data in a local variable. The (...) is a special thing in Lua which means it takes all arguments and just passes them on. If you want to use some of the arguments of "ThatFunction", you need to spell them all out (you can just copy the original ones).

And yes, modmain.lua and modworldgenmain.lua are the only files that has these functions (not counting imported files, which are basically part of the parent file).

On 2/2/2016 at 11:04 PM, Mobbstar said:

Yes, "ThatFunction" can be replaced by an actual function name. You can get mod config data using GetModConfigData("name"), I recommend you save the data in a local variable. The (...) is a special thing in Lua which means it takes all arguments and just passes them on. If you want to use some of the arguments of "ThatFunction", you need to spell them all out (you can just copy the original ones).

And yes, modmain.lua and modworldgenmain.lua are the only files that has these functions (not counting imported files, which are basically part of the parent file).

I finally edited the mod to something I think will work, but Mod Tools doesn't seem to like how I set up the configuration code. I checked and double checked all the brackets and commas and I'm still getting the "modinfo is either missing or invalid" error.

 

modinfo.lua

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
  • Create New...