icantevenname Posted March 30, 2021 Share Posted March 30, 2021 I've had a vampire character around for a while, but just now it hits me that she should have the ability to eat Telltale Hearts and Blood Sacks for Sanity and either Health or Hunger. Or maybe all three? I haven't decided yet. How do I make it so characters can eat normally inedible items? Link to comment Share on other sites More sharing options...
-LukaS- Posted March 30, 2021 Share Posted March 30, 2021 You just have to add the 'edible' component. You can check some basic food items or the component itself in scripts/components. Use AddPrefabPostInit() to edit existing prefabs. 1 Link to comment Share on other sites More sharing options...
inferjus4 Posted March 30, 2021 Share Posted March 30, 2021 1 hour ago, -t- said: You just have to add the 'edible' component. You can check some basic food items or the component itself in scripts/components. Use AddPrefabPostInit() to edit existing prefabs. Wouldn't it make item edible for everyone? Link to comment Share on other sites More sharing options...
-LukaS- Posted March 30, 2021 Share Posted March 30, 2021 (edited) Ah, you're right. My mistake. For a specific character that needs a bit more work. You'd have to add a new FOODTYPE. You would still have to make telltale heart edible but you would set the foodtype to your custom one. Then make your character be able to eat this foodtype. Edited March 30, 2021 by -t- 2 Link to comment Share on other sites More sharing options...
icantevenname Posted March 30, 2021 Author Share Posted March 30, 2021 3 hours ago, -t- said: Ah, you're right. My mistake. For a specific character that needs a bit more work. You'd have to add a new FOODTYPE. You would still have to make telltale heart edible but you would set the foodtype to your custom one. Then make your character be able to eat this foodtype. Think I screwed up. The character won't eat nothing at all. I used the code Wigfrid had to make this if inst.components.eater ~= nil then inst.components.eater:SetDiet(nil, { FOODTYPE.VAMPFOOD, FOODGROUP.OMNI }) end Is the left side supposed to be foods that can't be eaten? Or did I guess wrong? And in the telltale heart on blood sacks, I added inst.components.edible.foodtype = "VAMPFOOD" Link to comment Share on other sites More sharing options...
-LukaS- Posted March 30, 2021 Share Posted March 30, 2021 'FOODTYPE' is a table which stores different values. It's in the constants.lua if you want to check it out. So when trying to refer to the 'VAMPFOOD' by typing 'FOODTYPE.VAMPFOOD' you're trying to put in the value of the element called 'VAMPFOOD' from the FOODTYPE table. Since this table doesn't contain a 'VAMPFOOD' element it doesn't set up the diet correctly. Instead of putting in 'FOODTYPE.VAMPFOOD' you should just type in "VAMPFOOD" with quotation marks. Also, this: if inst.components.eater ~= nil then inst.components.eater:SetDiet(nil, { FOODTYPE.VAMPFOOD, FOODGROUP.OMNI }) end The first value being 'nil' is what causes your character to not be able to eat anything. This value determines what foods are edible for this character. In order to make your character be able to eat 'VAMPFOOD' food you'll have to set the first value to { FOODGROUP.OMNI, "VAMPFOOD" }. The second value can stay as { FOODGROUP.OMNI }. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted March 30, 2021 Author Share Posted March 30, 2021 15 minutes ago, -t- said: 'FOODTYPE' is a table which stores different values. It's in the constants.lua if you want to check it out. So when trying to refer to the 'VAMPFOOD' by typing 'FOODTYPE.VAMPFOOD' you're trying to put in the value of the element called 'VAMPFOOD' from the FOODTYPE table. Since this table doesn't contain a 'VAMPFOOD' element it doesn't set up the diet correctly. Instead of putting in 'FOODTYPE.VAMPFOOD' you should just type in "VAMPFOOD" with quotation marks. Also, this: if inst.components.eater ~= nil then inst.components.eater:SetDiet(nil, { FOODTYPE.VAMPFOOD, FOODGROUP.OMNI }) end The first value being 'nil' is what causes your character to not be able to eat anything. This value determines what foods are edible for this character. In order to make your character be able to eat 'VAMPFOOD' food you'll have to set the first value to { FOODGROUP.OMNI, "VAMPFOOD" }. The second value can stay as { FOODGROUP.OMNI }. The character can eat stuff again, still not the heart though. Am I missing something? I take out the foodtype from the heart's file and she can eat it. I put it back in and she won't. Link to comment Share on other sites More sharing options...
-LukaS- Posted March 30, 2021 Share Posted March 30, 2021 Hmm, weird. Everything seems correct. It should work. When a character tries to eat something they check for a specific tag, "edible_"..FOODTYPE. And if a food has this tag they can eat it. By setting the foodtype on the heart to "VAMPFOOD" and adding "VAMPFOOD" to the 'diet' the character should be able to eat that food. I don't know for now how to do it, especially since it's 1:20 AM currently. I'll look more into it tomorrow. 1 Link to comment Share on other sites More sharing options...
-LukaS- Posted April 3, 2021 Share Posted April 3, 2021 (edited) Ok, so I've found what was wrong. Apparently you have to add the new food type into the FOODTYPE table, you can't just type it in the diet. I don't really know why it works that way but at least it does. You'll have to add this new food type like this: GLOBAL.FOODTYPE.VAMPFOOD = "VAMPFOOD" And add a diet to your character: inst.components.eater:SetDiet({ GLOBAL.FOODGROUP.OMNI, GLOBAL.FOODTYPE.VAMPFOOD }) -- OMNI + your special food type And add the VAMPFOOD food type to the 'reviver', that's what the telltale hearts prefab is called: AddPrefabPostInit("reviver", function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.VAMPFOOD inst.components.edible.healthvalue = GLOBAL.TUNING.HEALING_HUGE inst.components.edible.hungervalue = GLOBAL.TUNING.CALORIES_HUGE inst.components.edible.sanityvalue = GLOBAL.TUNING.SANITY_HUGE end) Edited April 3, 2021 by -t- 1 Link to comment Share on other sites More sharing options...
icantevenname Posted April 3, 2021 Author Share Posted April 3, 2021 (edited) Er... Two things... When I select my character, the game would lock up. So I switched the code back to if inst.components.eater ~= nil then inst.components.eater:SetDiet({ FOODGROUP.OMNI, "VAMPFOOD" }, { FOODGROUP.OMNI }) end And that leads to the other thing, the game crashes when a heart is spawned. According to the client log, it's "[00:02:47]: Assert failure 'false && "cNetworkConnection::AllocReplica Invalid Prefab"' at ..\source\networklib\NetworkConnection.cpp(121): Trace follows..." Edited April 3, 2021 by icantevenname Added info Link to comment Share on other sites More sharing options...
-LukaS- Posted April 3, 2021 Share Posted April 3, 2021 Can you post the entire code for your character? And, do you get any messages when the game crashes when you spawn a telltale heart? Or does it just stop and disconnect you? I tested this exact code and it worked for me so I think the problem lies in how you implemented this. 1 Link to comment Share on other sites More sharing options...
icantevenname Posted April 3, 2021 Author Share Posted April 3, 2021 8 hours ago, -t- said: Can you post the entire code for your character? And, do you get any messages when the game crashes when you spawn a telltale heart? Or does it just stop and disconnect you? I tested this exact code and it worked for me so I think the problem lies in how you implemented this. No, I don't even get a error report, as soon as heart spawns, crafted, via commands, or by it being a starting item, it just flat out crashes. Though now that you've brought up implementation, I've been meaning to ask, GLOBAL.FOODTYPE goes in modmain, right? dark.lua Link to comment Share on other sites More sharing options...
-LukaS- Posted April 3, 2021 Share Posted April 3, 2021 (edited) Try without GLOBAL in front of FOODGROUP.OMNI and FOODTYPE.VAMPFOOD. GLOBAL.FOODTYPE.VAMPFOOD = "VAMPFOOD" and AddPrefabPostInit("reviver", function(inst) if not GLOBAL.TheWorld.ismastersim then return inst end inst:AddComponent("edible") inst.components.edible.foodtype = GLOBAL.FOODTYPE.VAMPFOOD inst.components.edible.healthvalue = GLOBAL.TUNING.HEALING_HUGE inst.components.edible.hungervalue = GLOBAL.TUNING.CALORIES_HUGE inst.components.edible.sanityvalue = GLOBAL.TUNING.SANITY_HUGE end) need to go in modmain.lua. Edited April 3, 2021 by -t- 1 1 Link to comment Share on other sites More sharing options...
icantevenname Posted April 4, 2021 Author Share Posted April 4, 2021 Now it's working! Thank you so much! Think I can do the same thing to mosquito sacks. 1 Link to comment Share on other sites More sharing options...
Aurorance Posted April 5, 2021 Share Posted April 5, 2021 Hi! I'm having this problem too! I wanna add nightmare fuel to diet of my character and make it eatable I copied the chunk you recommended modmain.lua Spoiler and also this in character.lua Spoiler the game didn't crash but nothing happened (the character still cannot eat nightmare fuel) and for the added chunk in character.lua, I don't understand what does the FOODGROUP.OMNI mean (not sure is it a special perk for the character "Dark") If yes, how should I change that? Thanks! Link to comment Share on other sites More sharing options...
-LukaS- Posted April 6, 2021 Share Posted April 6, 2021 23 hours ago, Aurorance said: Hi! I'm having this problem too! I wanna add nightmare fuel to diet of my character and make it eatable I copied the chunk you recommended modmain.lua Hide contents and also this in character.lua Hide contents the game didn't crash but nothing happened (the character still cannot eat nightmare fuel) and for the added chunk in character.lua, I don't understand what does the FOODGROUP.OMNI mean (not sure is it a special perk for the character "Dark") If yes, how should I change that? Thanks! -------------- You've added the edible component to nightmare fuel correctly. To add this new food type to your characters diet you have to type in 'FOODTYPE.CURSE' instead of 'CURSE'. Also, FOODGROUP.OMNI is just the default diet set to most character so that they can eat basic foods, like meat, berries, crockpot foods etc. By setting the diet to 'FOODGROUP.OMNI' and 'FOODTYPE.CURSE' you allow your character to eat these basic foods + nightmare fuel. 1 Link to comment Share on other sites More sharing options...
Aurorance Posted April 7, 2021 Share Posted April 7, 2021 Thanks for the help! At first i typed foodtype.curse but then realize the second bracket also needs to add foodtype.curse too! (orginally only foodtype.omni after the last comma) and idk why it works lol Link to comment Share on other sites More sharing options...
-LukaS- Posted April 7, 2021 Share Posted April 7, 2021 Happy it works for you. Btw, if the second table in 'SetDiet' is the same as the first one you can remove it. 3 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