Jump to content

Recommended Posts

Hello,

 

I'm new to modding and I wanted to create a character that looked like he had a big stomach but really his stomach is just the same as Wilson, just doubled. I doubled the max hunger to 300 and doubled the rate of hunger so that it depletes in the same amount of time. However, I don't know how to double the food's value so that my hunger goes down faster than I can gather food.

How do I double the hunger I would normally get back from eating food?

I saw a multiplier in the edible.lua that  thought I could use in the character.lua , but I don't know how to change the local multiplier. I saw one thread that changed the multiplier but creating a new function but, I'm not sure how they did that.

I'm currently using these in the character.lua

    inst.components.hunger:SetMax(TUNING.WILSON_HUNGER * 2)
    inst.components.hunger:SetRate(TUNING.WILSON_HUNGER_RATE * 2)

Thank you in advance for your help!
 

@HugAProbe, this should do it.

local function edible_postinit(self, inst)    if inst.prefab == "your_character_prefab" then        self.old_GetHunger = self.GetHunger        self.GetHunger = function(self, eater)            local multiplier = 2            return self:old_GetHunger(eater) * multiplier        end    endendAddComponentPostInit("edible", edible_postinit)

Remember to change your_character_prefab accordingly.

 

Edit: Fixed some mistakes above.

 

Edited by Blueberrys

Alternatively, you could do something like this in your player prefab:

inst.components.eater:SetOnEatFn(function(inst, food)    local hunger = food.components.edible.hungervalue    inst.components.hunger:DoDelta(hunger)end)

@Blueberrys @debugman18 Thank you so much. I got them to work!

Also debugman18, I understand how Blueberrys' code works but I'm really confused by how yours works. Could you please explain it?

 

My code works by running a callback when the character eats. What happens is it gets the hunger value of the food being eaten, and it increases your hunger by that amount, on top of the hunger gained by eating the food. So basically, it doubles the hunger gain.

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
×
  • Create New...