mtasa-blue icon indicating copy to clipboard operation
mtasa-blue copied to clipboard

setElementHealth in onClientPlayerDamage bug

Open FileEX opened this issue 4 years ago • 1 comments

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 image

Version 1.5.8

Additional context

FileEX avatar May 11 '21 12:05 FileEX

How about adding cancelEvent()? Or just use onPlayerDamage event instead.

lopezloo avatar Jul 06 '22 02:07 lopezloo

Necro, cant reproduce. Its fixed in 1.6 ig. Can be closed

TracerDS avatar Jul 24 '23 15:07 TracerDS