xovoxx Posted September 30, 2020 Share Posted September 30, 2020 Hello, I'm trying to add a few new foodtypes to my mod. My endgoal is to have specific, existing items, and use them to feed a very picky NPC. I am encountering an issue where my "constants.lua" file, the one where all the foodtypes appear to be, does not get overwritten by my mod. I copied the "constants.lua" file in my mod's "scripts" folder, with the following additions : FOODTYPE = { GENERIC = "GENERIC", MEAT = "MEAT", 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", WOOD = "WOOD", GOODIES = "GOODIES", MONSTER = "MONSTER", -- Added in for woby, uses the secondary foodype originally added for the berries TIER2 = "TIER2", } (I only added the "Tier2" part, the rest was already there) And further down : TIER2 = { name = "TIER2", types = { FOODTYPE.TIER2, }, }, Then, in the "gem.lua" file, I added the line : inst.components.edible.foodtype = FOODTYPE.TIER2 However, when I'm trying to feed the red gem to the NPC, it won't accept it. This makes me believe that the new foodtype is not recognized by the gem prefab for some reason. Can someone point me in the right direction? Thank you! Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/ Share on other sites More sharing options...
penguin0616 Posted September 30, 2020 Share Posted September 30, 2020 @xovoxx You also have to modify the NPC's eater component to also accept your new food type. 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1376048 Share on other sites More sharing options...
Serpens Posted September 30, 2020 Share Posted September 30, 2020 (edited) see my comment here for an example: but try to think carefully, how you could make your mod compatible to game updates and also other mods (since foodtpye seems to exclusive). Unfortunately, as written in my comment there, I don't have a good idea for that right now. Edited September 30, 2020 by Serpens Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1376090 Share on other sites More sharing options...
xovoxx Posted September 30, 2020 Author Share Posted September 30, 2020 14 hours ago, penguin0616 said: @xovoxx You also have to modify the NPC's eater component to also accept your new food type. Right! I forgot to mention it in my post, but I did that. I do it right after the NPC eats something else : local function OnEatFirstMeal(inst) inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") inst.components.eater:SetDiet({ FOODGROUP.TIER2 }) if numberOfMeals == 0 then inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") end if numberOfMeals == 1 then inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") end numberOfMeals = numberOfMeals + 1 end 9 hours ago, Serpens said: see my comment here for an example: but try to think carefully, how you could make your mod compatible to game updates and also other mods (since foodtpye seems to exclusive). Unfortunately, as written in my comment there, I don't have a good idea for that right now. Thanks for the reply! I'm not too worried about compatibility with other mods, I'm doing something really personal for close friends. What I can see from your post is that writing GLOBAL.FOODTYPE.NIGHTMAREFUEL = "NIGHTMAREFUEL" in modmain declares this new foodtype, and then I can use it anywhere in my mod? 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1376197 Share on other sites More sharing options...
penguin0616 Posted September 30, 2020 Share Posted September 30, 2020 @xovoxx How is it supposed to be able to accept the new food type if it doesn't get set until after it eats it? You need to set the diet BEFORE. 1 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1376236 Share on other sites More sharing options...
xovoxx Posted October 7, 2020 Author Share Posted October 7, 2020 On 9/30/2020 at 5:50 PM, penguin0616 said: @xovoxx How is it supposed to be able to accept the new food type if it doesn't get set until after it eats it? You need to set the diet BEFORE. I think you might be misunderstanding what I'm trying to do. I want to be able to feed it anything from its original diet, and THEN adjust its diet so it becomes more picky. Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377611 Share on other sites More sharing options...
penguin0616 Posted October 7, 2020 Share Posted October 7, 2020 (edited) Yeah. You still have to set the initial diet. Edited October 7, 2020 by penguin0616 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377617 Share on other sites More sharing options...
xovoxx Posted October 7, 2020 Author Share Posted October 7, 2020 17 minutes ago, penguin0616 said: Yeah. You still have to set the initial diet. Even if it's for an existing NPC? (I'm editing the moleworm) Also, I added the following to my modmain : GLOBAL.FOODTYPE.TIER2 = "TIER2" AddPrefabPostInit("gem",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.TIER2 inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) Which seems to work. However, this is still not working : local function OnEatFirstMeal(inst) inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") inst.components.eater:SetDiet({ FOODGROUP.TIER2 }) if numberOfMeals == 0 then inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") end if numberOfMeals == 1 then inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") end numberOfMeals = numberOfMeals + 1 end What happens is this : - I feed the moleworm his usual meal (Since it has its usual diet, that I did not change). - After feeding it once, it looks as if the game did not recognize my FOODGROUP.TIER2 constant, and the moleworm no longer eats anything. Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377624 Share on other sites More sharing options...
penguin0616 Posted October 7, 2020 Share Posted October 7, 2020 3 minutes ago, xovoxx said: Even if it's for an existing NPC? (I'm editing the moleworm) Yep. 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377625 Share on other sites More sharing options...
xovoxx Posted October 7, 2020 Author Share Posted October 7, 2020 3 minutes ago, penguin0616 said: Yep. Okay... I'm not sure I understand what you're suggesting. The mole.lua prefab already contains inst.components.eater:SetDiet({FOODTYPE.ELEMENTAL}) I did not remove it. What more am I supposed to do? Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377626 Share on other sites More sharing options...
penguin0616 Posted October 7, 2020 Share Posted October 7, 2020 @xovoxx What did you mean by that it wasn't accepting the red gem? 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377628 Share on other sites More sharing options...
xovoxx Posted October 7, 2020 Author Share Posted October 7, 2020 (edited) @penguin0616 I'll try to rephrase what I'm trying to do. I'm probably not clear enough! What I want to happen : - Feed the moleworm any "ELEMENTAL" food once. - Then, I want to be able to feed "TIER2" food, and only "TIER2" food, to the moleworm What actually happens : - I feed the moleworm any "ELEMENTAL" food once, successfully. - Then, when I attempt to feed the red gem (A "TIER2" food item, thanks to the script in modmain) to the moleworm, the "feed" prompt does not show up. - Additionally, any "ELEMENTAL" food is no longer accepted (the "feed" prompt does not show up). Does that make more sense? Edited October 7, 2020 by xovoxx Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377630 Share on other sites More sharing options...
penguin0616 Posted October 7, 2020 Share Posted October 7, 2020 In your inst.components.eater:SetDiet({ FOODGROUP.TIER2 }), you have "FOODGROUP" Everywhere else, you have "FOODTYPE" That's my first guess as to why your issue exists. 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377631 Share on other sites More sharing options...
xovoxx Posted October 7, 2020 Author Share Posted October 7, 2020 /facepalm that couldn't have helped. However, I fixed it and it doesn't work any better. Is there a way to add this function to modmain? Instead of having it in mole.lua, where it currently is. local function OnEatFirstMeal(inst) inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") inst.components.eater:SetDiet({ FOODTYPE.TIER2 }) if numberOfMeals == 0 then inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") SpawnPrefab("flowerhat").Transform:SetPosition(inst.Transform:GetWorldPosition()) end if numberOfMeals == 1 then inst.components.inspectable:SetDescription("He's not hungry anymore! Nice!") SpawnPrefab("amulet").Transform:SetPosition(inst.Transform:GetWorldPosition()) end numberOfMeals = numberOfMeals + 1 end Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377633 Share on other sites More sharing options...
penguin0616 Posted October 7, 2020 Share Posted October 7, 2020 (edited) You shouldn't be replacing DST prefabs. That being said, local function OnEatFirstMeal(inst) -- too lazy to copy your code -- also, you can use eater:TimeSinceLastEating() to figure out when they last ate. end AddPrefabPostInit("mole", function(inst) inst.eater:SetOnEatFn(OnEatFirstMeal) -- will now trigger whenever moleworm eats something end) Edited October 7, 2020 by penguin0616 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377634 Share on other sites More sharing options...
xovoxx Posted October 7, 2020 Author Share Posted October 7, 2020 (edited) Thanks @penguin0616 ! That makes sense. That being said, I get the same result as before. Here's my updated "modmain" code : GLOBAL.FOODTYPE.TIER2 = "TIER2" AddPrefabPostInit("gem",function(inst) inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.TIER2 inst.components.edible.healthvalue = 10 inst.components.edible.hungervalue = 20 inst.components.edible.sanityvalue = 5 end) local function OnEatFirstMeal(inst) inst.components.eater:SetDiet({ GLOBAL.FOODTYPE.TIER2 }) inst.components.inspectable:SetDescription("He looks better, but still hungry! He would love something shiny.") SpawnPrefab("flowerhat").Transform:SetPosition(inst.Transform:GetWorldPosition()) end AddPrefabPostInit("mole", function(inst) inst.components.eater:SetOnEatFn(OnEatFirstMeal) -- will now trigger whenever moleworm eats something end) I should note that the description does get updated to "He looks better, but still hungry! He would love something shiny." Thanks a lot for your help! I'm learning a lot thanks to your input Edited October 7, 2020 by xovoxx Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377638 Share on other sites More sharing options...
penguin0616 Posted October 7, 2020 Share Posted October 7, 2020 @xovoxx There are no prefabs called "gem" in the game. You need to specify an actual gem. 1 Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1377643 Share on other sites More sharing options...
xovoxx Posted October 14, 2020 Author Share Posted October 14, 2020 OMG that did it. Thanks a lot! I thought for sure that prefabs had the same "ID" as the name of their file... Thanks! Link to comment https://forums.kleientertainment.com/forums/topic/122132-trying-to-add-newfoodtypes/#findComment-1379381 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