# CFX::GET_PLAYER_FROM_SERVER_ID

- **Hash:** `0x344EA166`
- **Namespace:** CFX
- **Runtime name (Lua/JS):** `GetPlayerFromServerId`
- **Side:** client (Cfx runtime native)
- **Name status:** official
- **Documentation:** described with examples
- **URL:** https://natives.borderlinerp.com/natives/CFX/GET_PLAYER_FROM_SERVER_ID

## Signature

```c
Player GET_PLAYER_FROM_SERVER_ID(int serverId);
```

## Parameters

- `serverId` (`int`) — The player's server ID.

## Returns

`Player` — A valid Player ID if one is found, `-1` if not.

## Description

*Source: Cfx.re native reference*

Gets a local client's Player ID from its server ID counterpart, assuming the passed `serverId` exists on the client.

If no matching client is found, or an invalid value is passed over as the `serverId` native's parameter, the native result will be `-1`.

It's worth noting that this native method can only retrieve information about clients that are culled to the connected client.

## Usage

### Lua

```lua
local retval = GetPlayerFromServerId(serverId)

-- always available, by hash
local retval = Citizen.InvokeNative(0x344ea166, serverId, Citizen.ResultAsInteger())
```

### JavaScript

```js
const retval = GetPlayerFromServerId(serverId);

// by hash
const retval = Citizen.invokeNative('0x344ea166', serverId, Citizen.returnResultAnyway(), Citizen.resultAsInteger());
```

### C#

```csharp
int retval = Function.Call<int>((Hash)0x344ea166, serverId);
```

## Examples

*Source: Cfx.re native reference*

```lua
--We will assume the serverId is '4' in this scenario and that it's a valid serverId.

-- Passing invalid Player IDs such as 'nil' or IDs that don't exist will result in playerId being -1.

local playerId = GetPlayerFromServerId(serverId);

-- If the resulting playerId is not invalid (not equal to -1)
if playerId ~= -1 then
    -- Do our stuff on this player.
end
```

*Sources: Cfx.re native reference.*
