Jump to content

Looking to rebalance food values


Recommended Posts

So I've set my mind to making a mod to rebalance things to hopefully make the game more interesting by encouraging people to make use of the available features. The thing I have the biggest problem with is the sanity and especially health values of crock pot food and most especially jerky (20 health and 15 sanity for a piece of dried meat it's a solution to all problems!) The thing is looking at the API examples I see this


local function BetterCarrotInit(prefab)
prefab.components.edible.hungervalue = 200 -- carrots are the best food ever!!
AddPrefabPostInit("carrot", BetterCarrotInit)
Just to change the hunger value of a carrot. And I think to myself "Wow! This will be a pain to build and maintain if I want to change values across the board." But then I think to myself I can just build something to generate the code from a .csv or something and maybe I can mine the data from the wiki. Finally I thought maybe someone has already thought all this before. So before I go to the effort of building a code gen tool and mining/hand copying data from the wiki I thought I would ask. Does anyone have all the current food data in a usable format? And has anyone already built out such a code gen tool and is willing to share? Thanks much!
Link to comment
Share on other sites

This doesn't answer the question you asked but this should make it so you don't have to write as much code. Start with this block:

local function AdjustFoodPostInit(prefab, hunger, sanity, health)    AddPrefabPostInit(prefab, function(inst)        if not inst.components.edible then return end        if type(hunger) == "number" then            inst.components.edible.hungervalue = hunger        end        if type(sanity) == "number" then            inst.components.edible.sanityvalue = sanity        end        if type(health) == "number" then            inst.components.edible.healthvalue = health        end    end)end

Then, instead of writing a whole new local function for each food prefab, you can do it in a single line. For any argument that you pass 'nil', it'll use that food's default value.

AdjustFoodPostInit("carrot", 200, 200, 200) --carrots are awesome, docAdjustFoodPostInit("meat_dried", nil, 0, 10) --default hunger, 0 health, 10 sanityAdjustFoodPostInit("bonestew", -10, -20, -30) --I never liked meaty stew anyway

Be advised that I haven't tested this in a mod myself, so I'm not 100% sure it'll work as written. If it doesn't, I'll be happy to try to help debug.

Link to comment
Share on other sites

Thanks for responding so quickly! Your suggestion that should cut down on the code a bit and make it more readable but i still plan on making a code generator since a csv file will allow me to sort and compare for later tweaking much easier than a huge code file. 



Link to comment
Share on other sites

1) All the current food data in a usable format is on the wiki:





And also on russian wiki including various mods:





2) There is no such code yet if you mean just rebalancing existing food. But I thought about it. And even add "Fix Mod" to my calculator (however it doesn't exist yet). I thought not just about food stats but about cooking in general.


Now I'm going to make a mod which additionally adds more foods for crock pot. It's for balancing purposes. But at first I have to finish another mod (Aquarium aka Aqvarium, it'is not finished because it must produce roe).


My mod will include:

 - new stats for existing foods (as fewer as possible)

 - new stats for existing foods in mods (take into account the fact that mods can be not installed)

 - changing in recipes

 - new recipes

 - new art (new dishes)

 - may be new game mechanics for food

 - may be vitamins

Link to comment
Share on other sites

Yeah... That's not what I meant by usable. For any form of decent code generation I need just the Health, Hunger and sanity values mapped to the in game prefab name preferrably with the display name available. The data is there but it's not currently in a format i can use for code gen.

Link to comment
Share on other sites

local function explode(str,delemiter)

return string.match(str,"(.*)"..delemiter.."(.*)"..delemiter.."(.*)"..delemiter.."([^\n\r]*)")


local f=io.open("foods.csv","r")

for s in f:lines() do

local prefab_name, hunger, sanity, health = explode(s,",")

if (sanity) then

AdjustFoodPostInit(prefab_name, hunger, sanity, health) --func from post #2




Link to comment
Share on other sites


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