Jump to content

Health problem


Sendy

Recommended Posts

function armor(loss)
local Health = getElementHealth(source) 
local Armour = getPedArmor(source) 
setPedArmor(source, Armour - loss)
        if Armour < 0 then
        setElementHealth(source, Health - loss) 
    end
end
addEvent("ArMoR", true)
addEventHandler("ArMoR", getRootElement(), armor)

Please can anyone tell me why if i have armor 100 and health 1 and ped damage to me i'am dead? if i have health 100 and armor 100 its working first loos armor then health..

Edited by Sendy
Link to comment
function armor(loss)
	local Health = getElementHealth(source)
	local Armour = getPedArmor(source)
  
	if Armour - tonumber(loss) >= 0 then
		setPedArmor(source, Armour - tonumber(loss))
	else
		setPedArmor(source, 0)
	end
  
    if getPedArmor(source) == 0 then
        setElementHealth(source, Health + (Armour - tonumber(loss)))
    end
end
addEvent("ArMoR", true)
addEventHandler("ArMoR", getRootElement(), armor)

 

Link to comment
17 hours ago, Sendy said:

Thanks but not work :( i have 1 health and 100 armor and when ped attack to me i'am dead.. when i have 2 and more health and armor 100 and peds attack to me its working loss

I test it in local server and everything works fine. Maybe you're problem in "ArMoR" event.

Link to comment

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...