GetEntityHealth on the server-side returns incorrect value

GetEntityHealth on the server-side returns an incorrect value

  1. Client (production/canary) and FXServer version
    Canary / FXServer 4162 / CitizenFX.Core.Server.1.0.4163

  2. What you expected to happen
    In my case, GetEntityHealth on the server should have returned 400, but it returned 200.
    That’s because I set players’ max health to 400, and the health bar was full and GetEntityHealth returned 400 on the client.

  3. What actually happens
    When the player’s health is 100% full, it returns 200 on the server, regardless of the actual max health, but if it’s even a small bit below full health, then it returns the correct value, e.g. 395.

image

  1. Category of bug (eg. client, server, weapons, peds, native)
    Natives

  2. Reproducible steps, preferably with example script(s)

  • set player’s max health to 400
  • set player’s health to max (400)
  • print the result of GetEntityHealth on the server
  • set player health to something below, let’s say 350
  • print again

In the first case, it prints 200, but in any other case it returns the correct value.

maxHealth is not being persisted over the lifetime of the entity and only uses information from its last parse.

Defaulting to 200 is also meh due to the value being encoded with 13 bits (also see pedhealth.meta).

1 Like