mtasa-blue
mtasa-blue copied to clipboard
setElementHealth in onClientPlayerDamage bug
Describe the bug
Can't set player health to more than 1 in onClientPlayerDamage event if player have 1 HP
EDIT: It's weird bug. Because if player have 1 hp and i want set e.g 2 hp for him then don't working. But look into CODE2
To reproduce
addEventHandler('onClientPlayerDamage', root, function(att,weap)
if (weap == 41) then
cancelEvent();
end
if (weap == 41 and att and getElementType(att) == 'player') then
local hp = getElementHealth(source);
print('HP ', hp);
if (hp == 1) then
print('set hp to 5')
setElementHealth(source, 5);
print(getElementHealth(source));
end
local hp = getElementHealth(source);
if (hp < 100) then
setElementHealth(source, hp+1);
end
end
end);
CODE2: (Working)
addEventHandler('onClientPlayerDamage', root, function(att,weap)
if (weap == 41) then
cancelEvent();
end
if (weap == 41 and att and getElementType(att) == 'player') then
local hp = getElementHealth(source);
if (hp < 100) then
setElementHealth(source, hp+10);
end
end
end);
Working for hp+10, but not working for hp+1
Expected behaviour Should work
Screenshots

Version 1.5.8
Additional context
How about adding cancelEvent()? Or just use onPlayerDamage event instead.
Necro, cant reproduce. Its fixed in 1.6 ig. Can be closed