Jump to content

Self heal


Frankenmoo

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
Share on other sites

Something like:

If not inst. components. hunger: GetPercet (amount you wany) thenStartregen (amount, rate  of regeneration)

Bit busy right now, but I'll post the proper coding soon. Just letting you know I may have an idea how to make this work.

Link to comment
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.

Link to comment
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.

 

 

 

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 

Link to comment
Share on other sites

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.

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