Jump to content

Does anyone know about modding tuning

Recommended Posts

I'm looking to make a mod function that will allow
configuration of calories (hunger) satisfied by food items

I was simply going to change the tuning

where the variable Food_Quality would be set by the configuration

But then a thought occurred to me, If I change the tuning for the host, would this also change for the client?
Or does the client look at their own tuning.lua on their own machine

Unfortunately its hard to test  If this would only change the value on the host side,
But, if so, then I will have to find another way to approach it.

I suppose, it should work that the mod is installed by all clients with the configuration set by the host, so it should work either way?

Wondering if anyone who understands the code a bit better would know off hand if this would work.



Link to comment
Share on other sites

Yes, changing a TUNING-variable affects all things and players in the game, since they're all created/spawned by the server. Be careful changing TUNING-variables, though. They may be used for other things than you think. It's always good practice to search through the game code for your TUNING-variable, to see where it's being used, and for what. In this case, I'm sorry to say, I think that variable is used for more than you're aiming to change. There are other ways to deal with this, though.

Something like this:

AddComponentPostInit("edible", function(comp)
	comp.inst:DoTaskInTime(0, function(inst)
		if inst.components.edible and inst.components.edible.hungervalue ~= nil then
			inst.components.edible.hungervalue = comp.hungervalue * FOOD_QUALITY

Put that at the bottom of your modmain.lua, and it should work.

AddComponentPostInit runs the given function (parameter 2) for every component of the type given as parameter 1, which in this case would be the "edible"-components. Since components have to be added before you can change their values, these edible prefabs add the component, then our function is called as part of the adding of the component, and then the prefabs set the values. This means we can't just multiply their value immediately, since their starting value hasn't been set yet. We need to delay the running of our code, which is what the DoTaskInTime function is for. We delay the multiplication until next game tick, after which all the prefabs have finished their spawning, by telling it to wait for 0 seconds.

Edited by Ultroman
Link to comment
Share on other sites

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