Jump to content

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.

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 )

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?

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.

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