How to get a player by its server id?

Hi, I would like to know how could I get a player by its server id, for example, to make a command to kill or heal a player. I would like the command to be something similar to this: kill [id] and the id to be a number. So then get the player and with the player get the ped or even it steam identifier

Is there any way to do this? thanks in advance :slight_smile:

You can actually use this native to retrieve the ped:

with this you can do whatever you want.
To get the steamIdentifier use this one:

getPlayerIdentifier(args[1])[1] – args[1] is most probably within your script the targetId. and accessing [1] on the identifiers table should be the steamId.

Like the example you said you can

local ped = GetPlayerPed(id)
SetEntityHealth(ped, 0) — kills the ped

If I do what suggested @Dvergar about the identifier then it works of course in the server file, but if instead of using that example I try to get the ped of the player using the other native GetPlayerPed(args[1]) then it doesn’t return the ped, why?

–In the Server File

RegisterCommand("test_server", function(source, args)

    print(GetPlayerIdentifier(args[1])) --This works

    print(GetPlayerPed(args[1])) --But this doesn't, returns 0 which means isn't working. But also doesn't works even using source

end)

I am doing anything wrong, thanks in advance for both answers :wink:

@Dvergar
@FAIMAN

No, your code is correct. It should work fine for you.

But it doesn’t, the ped returns 0 and if I try doing something with the ped, doesn’t work

1 Like

You need to use onesync for server side usage of this natives that involves entity

How do I enable onesync correctly?

Hello,
If you use es_extended, the command exist already and you can use it like that: slay [ID]

I am not using es_extended, thanks anyway for the answer