Jump to content

Recommended Posts

When making a mod to change certain things inside the game, in most cases I can only think of including a replacement script for whatever it is, that contains the code I'd have to change. Naturally, this replaces that particular source file completely, thus it will remain as it was written by the modder, so long as the mod was enabled.

Of course this might be a necessity in some cases, and I understand that the modder and user of the mod chooses whatever consequence that may bring.

But it would be nice to learn ways to minimize the need for making mods this way, to make changes with the lowest amount of file swaps.
Surely there must be other means to make X component function differently, without removing the whole thing, and re-adding a carbon copy with only a couple of edited lines?

My own projects usually involves changing/tweaking a component here, a prefab there. Some of the game/game world mechanics.

I'd love to hear some advice on 'proper' modding practices, where the modder could tweak some game mechanics without too much messing up of the standard source files.
Obviously this would also greatly improve the mod's compatibility with other mods, and I've gotten the impression that skilled makers of large mods are able to do that (whenever achievable).

 

An example, one of my mods currently relies on swapping out the components/map.lua
But it only really needs to change/remove 3-ish lines of code inside one of the functions.
I've tried to come up with a better solution, but i'm not experienced enough for that 😃 Which is why I'm asking here.
Initially I was looking at the behaviour of another prefab that my mod had swapped out, to see if it calls this particular component, but it does not. Otherwise I maybe could've done a different thing in there.

Would there be a way to make the game run the normal map.lua file, with the exceptions of lines such and such, so and so? Or add a seperate file that overwrites or rewrites a particular function from the map.lua component?

I use upvalue hacking. Not a pleasant process, but it allows me to modify just a single function or table.

In your case, maybe you can do something like:

AddComponentPostInit("map", function(self)
    local old_fn = self.SetTile -- or whichever function you're trying to intercept
    self.SetTile = function(...)
        print("Test")
        return old_fn(...) -- SetTile doesn't actually return a value, but this is future compatible
    end
end

(You'd leave out the old_fn stuff if you're trying to replace it completely.)

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...