[HELP] SetEntityHealth


#1

Hello I try to create a medic job so i want to heal a player near to me, I can get his ped but when I’m calling SetEntityHealth(ped, 200) with his ped it doesn’t work but work if it’s on me…

Citizen.CreateThread(function() -- create a thread
    while true do -- loop through this code infinitely
        Citizen.Wait(0) -- required in an infinite loop or it will crash
        if (IsControlJustPressed(1, 57)) then
            local player = getNearPlayer()
            if (player ~= nil) then
                local ped = GetPlayerPed(player)
                SetEntityHealth(ped, GetEntityMaxHealth(ped))
            end
        end
        if (IsControlJustPressed(1, 56)) then
            SetEntityHealth(GetPlayerPed(-1), GetEntityMaxHealth(GetPlayerPed(-1)))
        end
    end
end)

#2

Are you sure that the getNearPlayer is returning what you need / a correct value.

I quickly looked online and found that the native GetNearestPlayerToEntity(entity) may be what you’re after.


#3

Yes I’m pretty sure because when I do :
SetEntityHealth(ped, GetEntityMaxHealth(ped))
I’ve got a notification about the player death but he doesn’t die :cry:
But I’ll retry with your function but I think I’ve already try :wink:


#4

But, doesn’t SetEntityHealth(ped, GetEntityMaxHealth(ped)) set the ped’s health to max? Not killing him?

I haven’t got much experience with this native but, setting it to max doesn’t seem like it would kill the player :stuck_out_tongue:


#5

Yes sorry I would say SetEntityHealth(ped, 0), I made a mistake in the reply but it doesn’t work