Jump to content

Need Help with Custom Hunger Values from Food for Character


Recommended Posts

I'm creating a character with the following perk:

 

*Eats a lot, but not often.

 

For this, I have doubled the characters max hunger and decreased the hunger rate by 25%.  To compensate, I want him to receive 25% less hunger from anything he eats.  I've tried the following ways to accomplish this:

Looking for advice or tutelage on the subject.  More information can be provided if necessary.  Thank you!

 

- Dominic

Link to comment
Share on other sites

@ViewtifulDom It's nice to see that you've taken the initiative to find a solution yourself.

 

You can change the Edible component depending on the character by checking GetPlayer(),prefab. (Not sure what you mean by "despite the clause")

GetPlayer = GLOBAL.GetPlayerAddComponentPostInit("edible", function(edible)    if GetPlayer().prefab == "your_char_prefab" then        -- Make changes here    endend)

-

 

Edit: Alternate, less efficient method.

You can change the hunger value right before consumption by replacing the Eater component's Eat function.

-- Where inst is the player instancelocal old_Eat = inst.components.eater.Eatfunction inst.components.eater:Eat(food)    food.components.edible.hungervalue = food.components.edible.hungervalue/2    local r = old_Eat(food)    food.components.edible.hungervalue = food.components.edible.hungervalue*2    return rend

 

Edit 2: This is a very well formatted question. Concise, to the point, and clearly explaining the attempted solutions and current standing of the issue. I just want to say, thank you.

 

Link to comment
Share on other sites

You can change the Edible component depending on the character by checking GetPlayer(),prefab. (Not sure what you mean by "despite the clause")

 

@Blueberrys Thanks for the kind words.  By the clause, I meant exactly what you have here, checking to see which player is eating the food.  When I first tried it, it affected all players despite having the check.  Now when I try it, for some reason, it just crashes entirely.  This is all I put:

AddComponentPostInit("edible", function(edible)    if GetPlayer().prefab == "domo" then        -- Make changes here    endend)

The game has also informed me that GetPlayer() is deprecated and that I should be using ThePlayer, but ThePlayer doesn't seem to do anything, and I can't find much documentation on it.

 

Any idea what's wrong?

 

I also apparently have no idea how to format my replies.  Sorry. : (

 

Link to comment
Share on other sites

@ViewtifulDom Ah.. you're making a DST mod. It's quite different in that case, you probably shouldn't be changing the component or foods themselves.

For now, I have a make-do work around. You can decrease the amount of hunger after eating food.

local function OnEat(inst, food)    local food_hunger = food.components.edible:GetHunger(inst)    local decrease = old_hunger/3 -- 1/3rd of the hunger will be removed    inst.components.hunger:DoDelta(-decrease)end-- Where inst is the player instance (Ideally in your player creation)inst.components.eater:SetOnEatFn(OnEat)

For a more robust solution, I suggest checking out the DST modding section. I assume something like this has been mentioned multiple times by now. This thread might be helpful too.

 

Edit: Also, about ThePlayer (and more).

 

Edit 2: Feel free to post there too if you don't find a solution.

Link to comment
Share on other sites

@Blueberrys Hey, sorry for the SUPER-delayed response.  I've actually tried what you suggested there, the only problem is that the last thing to occur is the subtraction of hunger, which means the hunger meter flashes red as if your character has eaten something bad.  While it technically works, it looks lousy, and I'd rather find a more aesthetics solution.

 

I didn't realize I was on the Don't Starve forum rather than the Don't Starve Together forum, or even that there was a difference.  I'll try posting over there and see what I get.  Thanks for your help.

Link to comment
Share on other sites

@ViewtifulDom

You can actually replace the eater component's Eat function of your character. One work around I can think of is modifying the food instances passed into it before and after, but that's not particularly efficient. It'll probably work though, if you can't come up with something else.

local old_Eat = inst.components.eater.Eatfunction inst.components.eater:Eat(food)    -- modify food..    local r = old_Eat(self, food)    -- revert food..    return rend

Edit: Note that the food may be removed upon use (if it's only 1).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...