-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GetEntityHealth returns different value between server/client #2558
Comments
Can you verify that the same thing happens for non-player peds? |
you can use this Thread to place MaxHealth
|
You need to use The same applies for non-player peds. |
adding server.lua: RegisterCommand('create_test_ped', function(src)
local coords = GetEntityCoords(GetPlayerPed(src)) + vector3(2, 2, 1)
local ped = CreatePed(4, `s_m_y_cop_01`, coords.x, coords.y, coords.z, 0.0, true, true)
while not DoesEntityExist(ped) do Wait(0) end
print(NetworkGetNetworkIdFromEntity(ped))
print(GetEntityHealth(ped))
print(GetEntityMaxHealth(ped))
end)
RegisterCommand('report_ped_health', function(_, args)
local ped = NetworkGetEntityFromNetworkId(tonumber(args[1]))
print(GetEntityHealth(ped))
print(GetEntityMaxHealth(ped))
print(GetPedMaxHealth(ped))
end) client.lua RegisterCommand('set_test_ped_health', function(_, args)
local ped = NetworkGetEntityFromNetworkId(tonumber(args[1]))
SetPedMaxHealth(ped, 1100)
SetEntityMaxHealth(ped, 1100)
ReviveInjuredPed(ped)
Wait(0)
SetEntityHealth(ped, 1100)
print(GetEntityHealth(ped))
print(GetEntityMaxHealth(ped))
end) results:
|
I tested a couple of other things. Client A leaving the area and Client B setting health, Client A returning reports 200/200 Client A and B both report the expected elevated values for their player peds on the clientside in all scenarios though |
You shouldn't call (You can easily test this with calling |
That makes sense, and removing the SET_PED_MAX_HEALTH call from my code as well as the examples outlined above creates the desired result for me. Thanks! |
What happened?
GetEntityHealth values between client and server do not match expectations
Expected result
GetEntityHealth would report the same value on the server as the client
Reproduction steps
on client
on server
Setting values below 200 returns the same value on both client and server.
Importancy
There's a workaround
Area(s)
FiveM, RedM, FXServer
Specific version(s)
FiveM/b3095 - FXServer 8049 win32
Additional information
with the
GetPlayerMaxHealth
function I somewhat expected a similar function for getting health if the server was going to differ at all.In examining the CPedHealthDataNode definition, it looks like if the data for maxhealth is 0 it defaults to 200, but this was the only instance I could track down where that value might be coming from.
fivem/code/components/citizen-server-impl/include/state/SyncTrees_Five.h
Line 2184 in 0fc6406
I would like to sample the correct value on the server side either via a new
GetPlayerHealth
function, or preferably via the GetEntityHealth function.The text was updated successfully, but these errors were encountered: