Jump to content

Help with custom food item


Recommended Posts

I've made a character with custom food items, and I wanted a feature to have my character not receive as much health, sanity, and hunger from them as other characters. However, I'd also like to make it so my friend's character receives bonus values from my character's food.

However, while testing, I encountered this error:

image.thumb.png.f4fcb53e51c8ff52278f527d11761c5b.png

My code for the item in question is as follows:

local function SweetieShakesBurger (inst, eater)
	if eater:HasTag("frycook") then --If Whoopee eats it
        eater.components.sanity:DoDelta(-10) -- 10 Sanity for Whoopee
    	eater.components.health:DoDelta(-5) -- 5 Health for Whoopee
		eater.components.hunger:DoDelta(-10) -- 40 Hunger for Whoopee
	
	else if eater:HasTag("sswaitress") then --If Scrunchie eats it
		eater.components.sanity:DoDelta(+10) -- 30 Sanity for Scrunchie  <--This is line 20
    	eater.components.health:DoDelta(+5) -- 15 Health for Scrunchie
		eater.components.hunger:DoDelta(+10) -- 60 Hunger for Scrunchie
	end

local function fn()
	local inst = CreateEntity()
	
	inst.entity:AddTransform()
	inst.entity:AddAnimState()
    inst.entity:AddNetwork()
    
	MakeInventoryPhysics(inst)
    
	inst:AddTag("burger")
	inst:AddTag("whoopfood")
	
    inst.AnimState:SetBank("burger")
    inst.AnimState:SetBuild("burger")
    inst.AnimState:PlayAnimation("idle")
	
	if not TheWorld.ismastersim then
        return inst
    end
	
	inst:AddComponent("edible")
	inst.components.edible.healthvalue = (10)
    inst.components.edible.hungervalue = (50)
	inst.components.edible.sanityvalue = (20)
	inst.components.edible.foodtype = "MEAT"

Is there a different symbol I have to use, rather than a plus sign, to add to the base values?

Edit: I have noticed the formatting error regarding the "else if" line, and corrected it.

Edited by EverSoNitro
Link to comment
Share on other sites

You don't need any sign as far as i know, if you want to add it.

I'm also not sure you need () symbols here :


	inst.components.edible.healthvalue = (10)
    inst.components.edible.hungervalue = (50)
	inst.components.edible.sanityvalue = (20)

 

Link to comment
Share on other sites

I actually just encountered another issue with my food items. Well, not so much an issue as a feature.

I noticed on my most recent world spawn that there was a pig and his house nearby. So, like any good neighbour, I attempted to give him one of my burgers. Unfortunately, I wasn't given any sort of option to.

How can I make it so that I can share food with followers? And, on a related topic, how do I tag food as Monster Food (i.e. Monster Meat, Lasagna, and Durians)

Link to comment
Share on other sites


    inst:AddComponent("tradable")
    inst.components.tradable.goldvalue = TUNING.GOLD_VALUES.MEAT

Second line is for pig king, if you want to exchange your food for gold. As far as i know, adding the first line should be enough to allow you to give your food to classic pig.

Link to comment
Share on other sites

19 minutes ago, EverSoNitro said:

And, on a related topic, how do I tag food as Monster Food (i.e. Monster Meat, Lasagna, and Durians)

If you want that the food transform pig into werepig, downside to be ignored when eated by webber, add tag "monstermeat"

If you want the food to be a food ingredient, and give you monster lasagna when overused, give the cooking tag "monster" :

		AddIngredientValues({"mymonstermeat"}, {monster=1, meat=0.5})

for example.(this is in my modmain)

Edited by Lumina
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...