Jump to content

Issue with custom food and individual return values


Recommended Posts

My character has a set of food items that he can craft and share with players. One of the quirks to this ability is that he doesn't receive the full return from them if he himself eats it.

The function I've set up 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
	
	elseif eater:HasTag("sswaitress") then --If Scrunchie eats it
		eater.components.sanity:DoDelta(10) -- 30 Sanity for Scrunchie
        eater.components.health:DoDelta(5) -- 15 Health for Scrunchie
		eater.components.hunger:DoDelta(10) -- 60 Hunger for Scrunchie
		 
	end
end

--irrelevant lines

	inst:AddComponent("edible")
	inst.components.edible:SetOnEatenFn(SweetieShakesBurger)
	inst.components.edible.healthvalue = (10)
    inst.components.edible.hungervalue = (50)
	inst.components.edible.sanityvalue = (20)
	inst.components.edible.foodtype = "MEAT"

I've noticed through testing, however, that if he's within a certain range of max health/hunger/sanity and he eats one of his burgers, he comes up with a net loss in that given stat. It's really a small issue, and not something that would be likely to affect play drastically, but I'd like to make this mod as clean as possible. Is there some way to fix the issue with the net losses?

Link to comment
Share on other sites

You mean, like, if you have full sanity, eat a food (should gain 20-10 sanity, so you still should be full), but you end with max-10 ? I guess it's because the gain and loss don't happen at the same time, so you are at max, gain sanity (20), still at max, then lose 10, ending at max-10.

You could make a check so you don't lose stat if your sanity is above max-10 ? Same for the other stats.

Link to comment
Share on other sites

Actually, in the time since I posted this, I think I've come up with a possible solution, simply having Whoopee's intended values as the base, and having the command run an "if not" check for the frycook tag. So, if someone other than Whoopee eats it, then I can simply add Delta values instead of subtracting.

I do actually have another question though. Is there any way to have a specific food item grant bonus follow time if given to a pig?

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