scionkiller Posted March 18, 2015 Share Posted March 18, 2015 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)-- treesTUNING.EVERGREEN_CHOPS_SMALL = 3TUNING.EVERGREEN_CHOPS_NORMAL = 6TUNING.EVERGREEN_CHOPS_TALL = 9TUNING.MUSHTREE_CHOPS_SMALL = 6TUNING.MUSHTREE_CHOPS_MEDIUM = 6TUNING.MUSHTREE_CHOPS_TALL = 9if GLOBAL.IsDLCEnabled(GLOBAL.REIGN_OF_GIANTS) thenTUNING.DECIDUOUS_CHOPS_NORMAL = 6TUNING.DECIDUOUS_CHOPS_SMALL = 3TUNING.DECIDUOUS_CHOPS_TALL = 9TUNING.DECIDUOUS_CHOPS_MONSTER = 7end-- axesTUNING.AXE_USES = 90endlocal function GoldenAxeChop(inst)inst.components.tool:SetAction(ACTIONS.CHOP,3)inst.components.weapon.attackwear = 3 / TUNING.GOLDENTOOLFACTORendAddSimPostInit( 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 More sharing options...
Corrosive Posted March 18, 2015 Share Posted March 18, 2015 In modmain.lua, at the top, outside of any functions you need to import some variables from the global environment:TUNING = GLOBAL.TUNINGACTIONS = GLOBAL.ACTIONSWhen 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 More sharing options...
scionkiller Posted March 19, 2015 Author Share Posted March 19, 2015 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 More sharing options...
Corrosive Posted March 19, 2015 Share Posted March 19, 2015 @scionkiller, That code works fine for me. You might want to move mushtrees down into the RoG block though. Link to comment Share on other sites More sharing options...
scionkiller Posted March 19, 2015 Author Share Posted March 19, 2015 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 More sharing options...
Corrosive Posted March 19, 2015 Share Posted March 19, 2015 I don't think you can give actions a non-integer effectiveness (at least not meaningfully). From inside the game, in the console, try doing print(TUNING.EVERGREEN_CHOPS_TALL) to see if your values are being set. Link to comment Share on other sites More sharing options...
Blueberrys Posted March 19, 2015 Share Posted March 19, 2015 @scionkiller Do you have RoG set to false in your modinfo? You might also be interested in this mod. Link to comment Share on other sites More sharing options...
Recommended Posts
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.