SrJardel Posted October 6, 2015 Share Posted October 6, 2015 Hi.I couldn't find anything on Unofficial API Documentation, and also couldn't figure something by myself, so, here we go. I'm using a mod that lets you harvest a item 1 time per day.What I want to do is to make the item harvestable 5x per day on Winter only, and then 3x per day while on other seasons. I took a look at this lines on prefabs\mod.lua:if (IsDLCEnabled(REIGN_OF_GIANTS)) then inst:AddComponent("harvestable") inst.components.harvestable:SetUp("item", 1, TUNING.ITEM_TIME) The solution would be to add this on modmain.lua (note the commented lines):AddPrefabPostInit("mod", modPrefabPostInit) local seg_time = 30 local total_day_time = seg_time*16 TUNING.ITEM_TIME = seg_time*5.3 //<-- MODIFIED FROM seg_time*16 TUNING.ITEM_WINTERTIME = seg_time*3.2 //<-- ADD THIS LINE and then add something like: (edited after the missing "then")if (IsDLCEnabled(REIGN_OF_GIANTS)) inst:AddComponent("harvestable") if TheWorld.state.iswinter then inst.components.harvestable:SetUp("item", 1, TUNING.ITEM_WINTERTIME) else inst.components.harvestable:SetUp("item", 1, TUNING.ITEM_TIME) endend but it fails to load and the game freeze on main screen. I'm sure the syntax is wrong, but I can't figure out where is the error, since I'm not familiar with coding at all.Could someone point me to the right way to write this? Thanks in advance! [EDIT]: I've forgot the word "then". Now it loads but gives the message about "TheWorld" not being specified..." so I assume TheWorld.state.iswinter is not a valid command in this case. Link to comment Share on other sites More sharing options...
Arkathorn Posted October 6, 2015 Share Posted October 6, 2015 In situations like these, when the mod throws an error during initialization, causing the game to freeze, go check your log.txt file. It should be located at Documents/Klei/DoNotStarve/log.txt on Windows. TheWorld is a value in Don't Starve Together, use GetWorld() instead. I'm not sure what you are doing with the tuning variables, but I want to point out that comments in Lua are made with a double-hyphen(--) instead of a double slash(//). Link to comment Share on other sites More sharing options...
SrJardel Posted October 6, 2015 Author Share Posted October 6, 2015 In situations like these, when the mod throws an error during initialization, causing the game to freeze, go check your log.txt file. It should be located at Documents/Klei/DoNotStarve/log.txt on Windows. TheWorld is a value in Don't Starve Together, use GetWorld() instead. I'm not sure what you are doing with the tuning variables, but I want to point out that comments in Lua are made with a double-hyphen(--) instead of a double slash(//). Those comments were just to help users to understand what I was changing from the original code, but thank you very much for the tip. I was already in my bed when I had to come back to my pc with an idea, most like you said:local is_winter = GetSeasonManager():IsWinter()if (IsDLCEnabled(REIGN_OF_GIANTS)) then inst:AddComponent("harvestable") if is_winter then inst.components.harvestable:SetUp("item", 5, TUNING.ITEM_WINTERTIME) else inst.components.harvestable:SetUp("item", 3, TUNING.ITEM_TIME) endendNot working on Winter tho. I still get 3 items per day. Maybe I should put that line somewhere else.About the TUNING variables, I believe it is for calculate the drop rate. The original waslocal seg_time = 30 local total_day_time = seg_time*16 TUNING.ITEM_TIME = seg_time*16so, I've assumed it was saying that "item drop time = seg_time*16 = 1 day" ,this is why I've changed values to match 3 items per day and addedTUNING.ITEM_WINTERTIME = seg_time*3.2to use while on winter. From my point of view, its just a matter of putting thatlocal is_winter = GetSeasonManager():IsWinter()in the right place. But again, I can be totally wrong. [EDIT FOR SOLVED]:if (IsDLCEnabled(REIGN_OF_GIANTS)) then inst:AddComponent("harvestable") if GetSeasonManager():IsWinter() then inst.components.harvestable:SetUp("item", 5, TUNING.ITEM_WINTERTIME) else inst.components.harvestable:SetUp("item", 3, TUNING.ITEM_TIME) endendIts working now! Link to comment Share on other sites More sharing options...
Mobbstar Posted October 6, 2015 Share Posted October 6, 2015 Are you sure it changes correctly when the seasons change? Link to comment Share on other sites More sharing options...
SrJardel Posted October 6, 2015 Author Share Posted October 6, 2015 Are you sure it changes correctly when the seasons change? I've made tests on Autumm and Winter only,but I suppose it will work like it should on other seasons as well. By the way, do you see something obvious in this code that would make it non functional? Im curious now. [EDIT:] I've took a look in your work on Dleowolf's Dusk Disc 2.0, very interesting and nicely done.It would have saved me from all the trouble if I had looked at it before. 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.