mtasa-blue
mtasa-blue copied to clipboard
setElementHealth working incorrectly.
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
- 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
)
- Use command /emptyhealth and then constantly try /increasehealth
- 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.
#486 related