Jump to content

How to override tuning values?


Recommended Posts

Hey everyone,

 

I have previously created a couple of mods that worked before RoG. They are now broken because of API or other changes. I've started playing the game again to get ready for DST, and I wanted to fix up my mods.

 

When I looked at my mods, I noticed that I had previously gotten them to work by overriding script files in the game, which according to the mod page isn't recommended. I figured I would try to do the right thing this time and make my changes via the API. Problem is, I can't get it to work at all.

 

Here's an example. The first mod is just a simple change to the number of chops necessary to cut down trees, because I got really sick of watching characters chop trees (yes, I know that you can get pigs to do it for you). Looking at it again, I realized I could accomplish all that i wanted by altering some of the global TUNING values, and then overriding the init function of the golden axe. Here's the code for that:

 

[codesyntax]local function TuneAxeAndChops(inst)

-- trees
TUNING.EVERGREEN_CHOPS_SMALL = 3
TUNING.EVERGREEN_CHOPS_NORMAL = 6
TUNING.EVERGREEN_CHOPS_TALL = 9
TUNING.MUSHTREE_CHOPS_SMALL = 6
TUNING.MUSHTREE_CHOPS_MEDIUM = 6
TUNING.MUSHTREE_CHOPS_TALL = 9

if GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS) then
TUNING.DECIDUOUS_CHOPS_NORMAL = 6
TUNING.DECIDUOUS_CHOPS_SMALL = 3
TUNING.DECIDUOUS_CHOPS_TALL = 9
TUNING.DECIDUOUS_CHOPS_MONSTER = 7
end

-- axes
TUNING.AXE_USES = 90
end

local function GoldenAxeChop(inst)
inst.components.tool:SetAction(ACTIONS.CHOP,3)
inst.components.weapon.attackwear = 3 / TUNING.GOLDENTOOLFACTOR
end

AddSimPostInit( TuneAxeAndChops )
AddPrefabPostInit( "common/inventory/goldenaxe", GoldenAxeChop )[/codesyntax]

 

I know that this code is being executed, because I made some syntax errors initially, and they caused my mod to crash. However, the changes to the Tuning values don't seem to actually work. Also, my call to SetAction() with a higher effectiveness also doesn't work.

 

What gives? My previous mod basically did the exact same thing as the above, but did so by directly overriding and altering the relevant lines of axe.lua and trees.lua, and it worked fine.

Link to comment
Share on other sites

In modmain.lua, at the top, outside of any functions you need to import some variables from the global environment:

TUNING = GLOBAL.TUNINGACTIONS = GLOBAL.ACTIONS

When registering a PrefabPostInit function, you need to register it to the prefab using the name of the prefab, not the full path.

AddPrefabPostInit( "goldenaxe", GoldenAxeChop )
Link to comment
Share on other sites

Thanks for the help, Corrosive.

 

I did both the changes you mentioned. The golden axe change now works, but the TUNING overrides still don't stick. All of my code is in modmain.lua, here it is:

TUNING = GLOBAL.TUNINGACTIONS = GLOBAL.ACTIONSlocal function TuneAxeAndChops(inst)		-- trees	TUNING.EVERGREEN_CHOPS_SMALL = 3	TUNING.EVERGREEN_CHOPS_NORMAL = 6	TUNING.EVERGREEN_CHOPS_TALL = 9	TUNING.MUSHTREE_CHOPS_SMALL = 6	TUNING.MUSHTREE_CHOPS_MEDIUM = 6	TUNING.MUSHTREE_CHOPS_TALL = 9	if GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS) then		TUNING.DECIDUOUS_CHOPS_NORMAL = 6		TUNING.DECIDUOUS_CHOPS_SMALL = 3		TUNING.DECIDUOUS_CHOPS_TALL = 9		TUNING.DECIDUOUS_CHOPS_MONSTER = 7	end	-- axes	TUNING.AXE_USES = 90endlocal function GoldenAxeChop(inst)	inst.components.tool:SetAction(ACTIONS.CHOP,3)    inst.components.weapon.attackwear = 3 / TUNING.GOLDENTOOLFACTORendAddSimPostInit( TuneAxeAndChops )AddPrefabPostInit( "goldenaxe", GoldenAxeChop )

Am I still missing something?

Link to comment
Share on other sites

Strange, it still doesn't work for me. I don't know what else to do. Could it be the priority of the mod? How does that work?

 

Could it be somehow that it's not reloading it correctly on my machine? Is there a way to force the mod to refresh? I tried disabling it, exiting the mod menu, re-entering the mod menu and enabling it again, and it still didn't work.

 

I've tried different priorities and all kinds of things. I think I'm just going to give up, and work around it by using a PrefabPostInit to alter the regular axe the same way I altered the golden axe. I could use a value of 1.67 to the action to achieve the same affect, and then alter the gold axe to 5.

 

Thanks for your help, Corrosive.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...