Jump to content

Recommended Posts

So I'm basically trying to make it so that every 5 seconds you get healed for 50 (test) if you are full. The problem is it does nothing and idk why

 

local function hunger_heal (inst, owner)if (owner.components.health and owner.components.health:IsHurt()) and (owner.components.hunger and owner.components.hunger.current > 5  )theninst.task = inst:DoPeriodicTask(1, owner.components.health:DoDelta(50) )end end

this is basically what im trying

 

If you are hurt and are not hungry

 

heal for 50 every second 

Link to comment
https://forums.kleientertainment.com/forums/topic/30364-self-heal/
Share on other sites

local function onhungerchange(inst, data)if inst.components.hunger:GetPercent() < DESIRED AMOUNT theninst.components.health:StartRegen(50, 5) elseinst.components.health:StopRegen()
end
end

inst:ListenForEvent("hungerdelta", onhungerchange)

 

I have yet to test this, and am too busy to test it at the moment. But it may work.

local function onhungerchange(inst, data)if inst.components.hunger:GetPercent() < DESIRED AMOUNT theninst.components.health:StartRegen(50, 5) elseinst.components.health:StopRegen()
end
end

inst:ListenForEvent("hungerdelta", onhungerchange)

 

I have yet to test this, and am too busy to test it at the moment. But it may work.

 

 

 

So i essentially copied and pasted and i got an error to be specific when I introduced the last line that listens for the event 

 

it says "attempt to index 'global' (nill value ) 

local function hunger_heal (inst, data)	 	if inst.components.hunger:GetPercent() < 80 then 		inst.components.health:StartRegen(50,5)		else 	inst.components.health:StopRegen()	end endinst:ListenForEvent("hungerdelta", onhungerchange)

I understand pretty much everything you wrote but what is "hungerdelta" i thought the event that is being listened for is on hungerchange so im confused on what is  "hungerdelta"

 

Also is there a site that you can introduce me to that explains some of the things like Dodelta and inst is? Ive checked out the tutorials that the forums have but doesn't explains these things

 

Thank you for everything 

Edited by Frankenmoo

So i essentially copied and pasted and i got an error to be specific when I introduced the last line that listens for the event 

 

it says "attempt to index 'global' (nill value ) 

local function hunger_heal (inst, data)	 	if inst.components.hunger:GetPercent() < 80 then 		inst.components.health:StartRegen(50,5)		else 	inst.components.health:StopRegen()	end endinst:ListenForEvent("hungerdelta", onhungerchange)

I understand pretty much everything you wrote but what is "hungerdelta" i thought the event that is being listened for is on hungerchange so im confused on what is  "hungerdelta"

 

Also is there a site that you can introduce me to that explains some of the things like Dodelta and inst is? Ive checked out the tutorials that the forums have but doesn't explains these things

 

Thank you for everything 

 

You are correct. Now I can see I've made a mistake, but my brain's failing to pick it up. Try "if inst.components.hunger.current </> AMOUNT"?

I'll be passing out (sick) now, so if that doesn't work, and no one else has any suggestions, I'll be a while. I've something very similar to this before, so I should know how to do this. Anyway, I'll be off now.

Edited by Mr. Tiddles

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