Jump to content

Recommended Posts

31 minutes ago, ToastyStoat said:

An easy way to handle this would be to multiply the health regeneration value by 1% of your character's hunger percentage. You can get that hunger value with YourCharacter.components.hunger:GetPercent()*0.01

I think I screwed up something health regeneration isn't working at all right now

inst.components.health:StartRegen(5, 1)

then I changed it to

inst.components.health:StartRegen(inst.components.hunger:GetPercent()*0.01, 1)

also I'm using Singleplayer don't starve

EDIT: I tried this and the game just crashes

inst.components.hunger:GetPercent(inst.components.health:StartRegen(1, 1)*0.01

 

Edited by Scupake
inst.components.health:StartRegen(5 * inst.components.hunger:GetPercent()*0.01,1)

Let me know if this helps any.

I have a feeling this would only scale the regeneration from the hunger value the character would spawn in with.

You might want to try something a bit more dynamic if you'd like the regen to constantly scale with hunger:

local,hu,he = inst.components.hunger,inst.components.health
local amount_healed = 1
local interval_in_seconds = 1
inst:DoPeriodicTask(interval_in_seconds,function()
    if hu and he and not he:IsDead() then
      he:DoDelta(amount_healed * hu:GetPercent()*0.01,false,"regen")
    end
end)

amount_healed and interval_in_seconds are just for demonstration purposes.

Edited by ToastyStoat
36 minutes ago, ToastyStoat said:

inst.components.health:StartRegen(5 * inst.components.hunger:GetPercent()*0.01,1)

Let me know if this helps any.

I have a feeling this would only scale the regeneration from the hunger value the character would spawn in with.

You might want to try something a bit more dynamic if you'd like the regen to constantly scale with hunger:


local,hu,he = inst.components.hunger,inst.components.health
local amount_healed = 1
local interval_in_seconds = 1
inst:DoPeriodicTask(interval_in_seconds,function()
    if hu and he and not he:IsDead() then
      he:DoDelta(amount_healed * hu:GetPercent()*0.01,false,"regen")
    end
end)

amount_healed and interval_in_seconds are just for demonstration purposes.

I did some changes to the first one and it's working perfectly

Thanks for the help

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