Janfon1 Posted May 20, 2019 Share Posted May 20, 2019 Hi! I've been scouring through the forums to see if this issue has already been resolved, buuuuut things didn't go as smoothly as I hoped they would. It looks like I do need to ask for help with this one. The character's name is Constantine and the custom foodtype CANNIBAL is supposed to make said bonuses specific only to him. I'd like him to eat bone shards and also change up the stats of all monster meats. Here's the code I've placed in the constantine.lua folder. It made the game crash in the character selection screen. Added the custom foodtype: Spoiler -- Stats inst.components.health:SetMaxHealth(130) inst.components.hunger:SetMax(100) inst.components.sanity:SetMax(200) inst.components.eater.ablefoods = { "CANNIBAL", "MEAT", "VEGGIE", "INSECT", "SEEDS", "GENERIC" } inst.components.eater.foodprefs = { "CANNIBAL", "MEAT", "VEGGIE", "INSECT", "SEEDS", "GENERIC" } And the coding for the bone shards and the monster meat: Spoiler GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("boneshard", function(inst) if GetPlayer().prefab == "constantine" then inst:AddComponent("edible") inst.components.edible.foodtype = "CANNIBAL" inst.components.edible.healthvalue = -0.75 inst.components.edible.sanityvalue = -0.75 inst.components.edible.hungervalue = 25.5 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("monstermeat", function(inst) if GetPlayer().prefab == "constantine" then inst:AddComponent("edible") inst.components.edible.foodtype = "CANNIBAL" inst.components.edible.healthvalue = -3 inst.components.edible.sanityvalue = -3 inst.components.edible.hungervalue = 18.75 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("cookedmonstermeat", function(inst) if GetPlayer().prefab == "constantine" then inst:AddComponent("edible") inst.components.edible.foodtype = "CANNIBAL" inst.components.edible.healthvalue = -1.5 inst.components.edible.sanityvalue = 0 inst.components.edible.hungervalue = 18.75 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("monstermeat_dried", function(inst) if GetPlayer().prefab == "constantine" then inst:AddComponent("edible") inst.components.edible.foodtype = "CANNIBAL" inst.components.edible.healthvalue = 0 inst.components.edible.sanityvalue = 0 inst.components.edible.hungervalue = 25 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("monsterlasagna", function(inst) if GetPlayer().prefab == "constantine" then inst:AddComponent("edible") inst.components.edible.foodtype = "CANNIBAL" inst.components.edible.healthvalue = 8 inst.components.edible.sanityvalue = 8 inst.components.edible.hungervalue = 45 end end) constantine.lua Here's the .lua file for my character. Thanks in advance for the help! Link to comment Share on other sites More sharing options...
Eusong Posted May 20, 2019 Share Posted May 20, 2019 (edited) In the script file constants.lua you can find this Spoiler FOODTYPE = { GENERIC = "GENERIC", MEAT = "MEAT", WOOD = "WOOD", VEGGIE = "VEGGIE", ELEMENTAL = "ELEMENTAL", GEARS = "GEARS", HORRIBLE = "HORRIBLE", INSECT = "INSECT", SEEDS = "SEEDS", BERRY = "BERRY", --hack for smallbird; berries are actually part of veggie RAW = "RAW", -- things which some animals can eat off the ground, but players need to cook BURNT = "BURNT", --For lavae. ROUGHAGE = "ROUGHAGE", GOODIES = "GOODIES", } FOODGROUP = { OMNI = { name = "OMNI", types = { FOODTYPE.MEAT, FOODTYPE.VEGGIE, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.GENERIC, FOODTYPE.GOODIES, }, }, WOODIE = { name = "WOODIE", types = { FOODTYPE.MEAT, FOODTYPE.VEGGIE, FOODTYPE.INSECT, FOODTYPE.SEEDS, FOODTYPE.GENERIC, FOODTYPE.WOOD, FOODTYPE.ROUGHAGE, FOODTYPE.GOODIES, }, }, BERRIES_AND_SEEDS = { name = "BERRIES_AND_SEEDS", types = { FOODTYPE.SEEDS, FOODTYPE.BERRY, }, }, BEARGER = { name = "BEARGER", types = { FOODTYPE.MEAT, FOODTYPE.VEGGIE, FOODTYPE.BERRY, FOODTYPE.GENERIC, }, }, Goose = { name = "Goose", types = { FOODTYPE.MEAT, FOODTYPE.VEGGIE, FOODTYPE.SEEDS, }, }, } Perhaps adding to it postinit will help. EDIT: Also there are no such variables as ablefoods and foodprefs in the eater component as far as I can tell. Edited May 20, 2019 by Eusong Link to comment Share on other sites More sharing options...
Janfon1 Posted June 22, 2019 Author Share Posted June 22, 2019 Still trying to add a custom food group and change up stats of monster meat. Looked into other threads, even dug into script files of mods on the workshop but I just can't seem to get my answer. I apologize for replying so late New version of the code: Spoiler GLOBAL.FOODTYPE.CANNIBAL="CANNIBAL" -- adding the new food group inst.components.eater.ablefoods = { "CANNIBAL, MEAT, VEGGIE, INSECT, SEEDS, GENERIC" } inst.components.eater.foodprefs = { "CANNIBAL, MEAT, VEGGIE, INSECT, SEEDS, GENERIC" } -- let constantine eat spoiled food inst.components.eater.ignoresspoilage = true inst.components.eater.stale_hunger = 3 inst.components.eater.stale_health = 1 -- make boneshard edible AddPrefabPostInit("boneshard", function(inst) if GetPlayer().prefab == "constantine" then inst:AddComponent("edible") inst.components.edible.foodtype = "CANNIBAL" inst.components.edible.healthvalue = -0.75 inst.components.edible.sanityvalue = -0.75 inst.components.edible.hungervalue = 25.5 end end) -- change stats of monster meat GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("monstermeat", function(inst) if GetPlayer().prefab == "constantine" then inst.components.edible.healthvalue = -3 inst.components.edible.sanityvalue = -3 inst.components.edible.hungervalue = 18.75 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("cookedmonstermeat", function(inst) if GetPlayer().prefab == "constantine" then inst.components.edible.healthvalue = -1.5 inst.components.edible.sanityvalue = 0 inst.components.edible.hungervalue = 18.75 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("monstermeat_dried", function(inst) if GetPlayer().prefab == "constantine" then inst.components.edible.healthvalue = 0 inst.components.edible.sanityvalue = 0 inst.components.edible.hungervalue = 25 end end) GetPlayer = GLOBAL.GetPlayer AddPrefabPostInit("monsterlasagna", function(inst) if GetPlayer().prefab == "constantine" then inst.components.edible.healthvalue = 8 inst.components.edible.sanityvalue = 8 inst.components.edible.hungervalue = 45 end end) And the error that followed the code: Spoiler Link to comment Share on other sites More sharing options...
Wolf_EX Posted June 24, 2019 Share Posted June 24, 2019 (edited) for custom food group use this in modmain local FOODTYPE = GLOBAL.FOODTYPE local FOODGROUP = GLOBAL.FOODGROUP FOODTYPE.BONE = "BONE" FOODGROUP.CANNIBAL = {} FOODGROUP.CANNIBAL.name = "CANNIBAL" FOODGROUP.CANNIBAL.types = { "BONE", "MEAT", "VEGGIE", "INSECT", "SEEDS", "GENERIC", } function boneshardpostinit(inst) inst:AddTag("edible_"..FOODTYPE.BONE) if TheWorld.ismastersim then inst:AddComponent("edible") inst.components.edible.healthvalue = -0.75 inst.components.edible.sanityvalue = -0.75 inst.components.edible.hungervalue = 25.5 end end AddPrefabPostInit("boneshard", boneshardpostinit) to change stat gain/losses from monster meat give your character an oneat function inst.components.eater:SetOnEatFn(OnEat) and monstermeatfoods = { monstermeat = { health = 17, sanity = 12, hunger = 0, }, cookedmonstermeat = { health = 18.5, sanity = 15, hunger = 0, }, } and in OnEat use local function OnEat(inst, food) if food and monstermeatfoods[food.prefab] and food.components.edible then inst.components.health.DoDelta(monstermeatfoods[food.prefab].health) inst.components.sanity.DoDelta(monstermeatfoods[food.prefab].sanity) inst.components.hunger.DoDelta(monstermeatfoods[food.prefab].hunger) end end I didn't test any of this code, so there are probably some errors in there. Edited July 11, 2019 by Wolf_EX Link to comment Share on other sites More sharing options...
Janfon1 Posted June 25, 2019 Author Share Posted June 25, 2019 I am terribly sorry for depending on you so much, but I just couldn't do any of this without your help. I hope I'm not being too much of a bother Now the game gives me a warning: "An error has occured while starting the game. Check your log for details." And the line in the log that interests us: Spoiler [00:00:31]: [string "../mods/Constantine Throatspeak/modmain.lua"]:106: attempt to index global 'inst' (a nil value) a.k.a this line of code Spoiler inst.components.eater:SetOnEatFn(OnEat) out of the entire code that I've strapped together using tape. Spoiler local FOODTYPE = GLOBAL.FOODTYPE local FOODGROUP = GLOBAL.FOODGROUP FOODTYPE.BONE = "BONE" FOODGROUP.CANNIBAL = {} FOODGROUP.CANNIBAL.name = "CANNIBAL" FOODGROUP.CANNIBAL.types = { "BONE", "MEAT", "VEGGIE", "INSECT", "SEEDS", "GENERIC", } function boneshardpostinit(inst) inst:AddTag("edible_"..FOODTYPE.BONE) if TheWorld.ismastersim then inst:AddComponent("edible") inst.components.edible.healthvalue = -0.75 inst.components.edible.sanityvalue = -0.75 inst.components.edible.hungervalue = 25.5 end end AddPrefabPostInit("boneshard", boneshardpostinit) -- the moment where an issue appears inst.components.eater:SetOnEatFn(OnEat) monstermeatfoods = { monstermeat = { health = 5, sanity = 10, hunger = 0, }, cookedmonstermeat = { health = 18.5, sanity = 15, hunger = 0, }, -- also added dried monster meat monstermeat_dried = { health = 20, sanity = 20, hunger = 35, }, } local function OnEat(inst, food) if food and monstermeatfoods[food] and food.components.edible then inst.components.health.DoDelta(monstermeatfoods[foods].health) inst.components.sanity.DoDelta(monstermeatfoods[foods].sanity) inst.components.hunger.DoDelta(monstermeatfoods[foods].hunger) end end I hope this helps Link to comment Share on other sites More sharing options...
TemporarySolutn Posted June 26, 2019 Share Posted June 26, 2019 I would look at wortox and see how it changes his food stats Link to comment Share on other sites More sharing options...
Wolf_EX Posted June 26, 2019 Share Posted June 26, 2019 (edited) this goes in constantine.lua Spoiler -- the moment where an issue appears inst.components.eater:SetOnEatFn(OnEat) monstermeatfoods = { monstermeat = { health = 5, sanity = 10, hunger = 0, }, cookedmonstermeat = { health = 18.5, sanity = 15, hunger = 0, }, -- also added dried monster meat monstermeat_dried = { health = 20, sanity = 20, hunger = 35, }, } local function OnEat(inst, food) if food and monstermeatfoods[food] and food.components.edible then inst.components.health.DoDelta(monstermeatfoods[foods].health) inst.components.sanity.DoDelta(monstermeatfoods[foods].sanity) inst.components.hunger.DoDelta(monstermeatfoods[foods].hunger) end end this goes in your master_postinit, everything else is outside it. inst.components.eater:SetOnEatFn(OnEat) Edited June 26, 2019 by Wolf_EX Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now