Jump to content

Eating Telltale Hearts


Recommended Posts

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

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.

  • Like 1
Link to comment
Share on other sites

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

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 by -t-
  • Like 2
Link to comment
Share on other sites

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

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

  • Like 1
Link to comment
Share on other sites

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

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.

  • Like 1
Link to comment
Share on other sites

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 by -t-
  • Like 1
Link to comment
Share on other sites

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 by icantevenname
Added info
Link to comment
Share on other sites

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.

  • Like 1
Link to comment
Share on other sites

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

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 by -t-
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

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

image.png.5d22bc5b4711a4d4c4796819bf128e88.png

and also this in character.lua

Spoiler

image.png.e7976a34309d1f2f2329b8284f3114bd.png

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

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

image.png.5d22bc5b4711a4d4c4796819bf128e88.png

and also this in character.lua

  Hide contents

image.png.e7976a34309d1f2f2329b8284f3114bd.png

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.

  • Like 1
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...