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

setElementHealth working incorrectly.

Open jjustns opened this issue 2 years ago • 1 comments

Describe the bug

When adding or subtracting 1 to the player's health, incorrect values are assigned or in the case of increasing health, sometimes not increasing at all.

Steps to reproduce

  1. Create a server-sided script with this code:

addCommandHandler('emptyhealth', -- When testing increasehealth
    function(player)
        setElementHealth(player, 1)
        outputChatBox("Health is now empty", player)
    end
)


addCommandHandler('fullhealth', -- When testing decreasehealth
    function(player)
        setElementHealth(player, 100)
        outputChatBox("Health is now full again", player)
    end
)

addCommandHandler('decreasehealth',
    function(player)
        setElementHealth(player, getElementHealth(player) - 1)
        outputChatBox("Health decreased to "..getElementHealth(player), player)
    end
)

addCommandHandler('increasehealth',
    function(player)
        setElementHealth(player, getElementHealth(player) + 1)
        outputChatBox("Health increased to "..getElementHealth(player), player)
    end
)
  1. Use command /emptyhealth and then constantly try /increasehealth
  2. Use command /fullhealth and then constantly try /decreasehealth

Version

Client & Server: 1.6-release-22650

Additional context

Alone in my local server, I did additional testing with runcode

Subtracting -1 (Starting from 100):

justn executed command: setElementHealth(getRandomPlayer(), 100)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 100 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 98 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 97 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 96 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 94 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 93 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 92 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) - 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 90 [number]

Adding +1 (Starting from 1):

justn executed command: setElementHealth(getRandomPlayer(), 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 1 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) + 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 2 [number]
justn executed command: setElementHealth(getRandomPlayer(), getElementHealth(getRandomPlayer()) + 1)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 2 [number]
justn executed command: setElementHealth(getRandomPlayer(), 3)
Command results: true [boolean]
justn executed command: getElementHealth(getRandomPlayer())
Command results: 2 [number]

Relevant log output

No response

Security Policy

  • [X] I have read and understood the Security Policy and this issue is not security related.

jjustns avatar Aug 02 '24 19:08 jjustns

#486 related

TracerDS avatar Aug 07 '24 12:08 TracerDS