# CFX::GET_PLAYER_PEER_STATISTICS

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

## Signature

```c
int GET_PLAYER_PEER_STATISTICS(char* playerSrc, int peerStatistic);
```

## Parameters

- `playerSrc` (`char*`) — The player to get the stats of
- `peerStatistic` (`int`) — The statistic to get, this will error if its out of range

## Returns

`int` — See `ENetStatisticType` for what this will return.

## Description

*Source: Cfx.re native reference*

```cpp
const int ENET_PACKET_LOSS_SCALE = 65536;

enum PeerStatistics
{
	// PacketLoss will only update once every 10 seconds, use PacketLossEpoch if you want the time
	// since the last time the packet loss was updated.

	// the amount of packet loss the player has, needs to be scaled with PACKET_LOSS_SCALE
	PacketLoss = 0,
	// The variance in the packet loss
	PacketLossVariance = 1,
	// The time since the last packet update in ms, relative to the peers connection time
	PacketLossEpoch = 2,
	// The mean amount of time it takes for a packet to get to the client (ping)
	RoundTripTime = 3,
	// The variance in the round trip time
	RoundTripTimeVariance = 4,
	// Despite their name, these are only updated once every 5 seconds, you can get the last time this was updated with PacketThrottleEpoch
	// The last recorded round trip time of a packet
	LastRoundTripTime = 5,
	// The last round trip time variance
	LastRoundTripTimeVariance = 6,
	// The time since the last packet throttle update, relative to the peers connection time
	PacketThrottleEpoch = 7,
};
```

These statistics only update once every 10 seconds.

## Usage

### Lua

```lua
local retval = GetPlayerPeerStatistics(playerSrc, peerStatistic)

-- always available, by hash
local retval = Citizen.InvokeNative(0x9a928294, playerSrc, peerStatistic, Citizen.ResultAsInteger())
```

### JavaScript

```js
const retval = GetPlayerPeerStatistics(playerSrc, peerStatistic);

// by hash
const retval = Citizen.invokeNative('0x9a928294', playerSrc, peerStatistic, Citizen.returnResultAnyway(), Citizen.resultAsInteger());
```

### C#

```csharp
int retval = Function.Call<int>((Hash)0x9a928294, playerSrc, peerStatistic);
```

## Examples

*Source: Cfx.re native reference*

```js

setInterval(() => {
	const ENET_PACKET_LOSS_SCALE = 65536;

	const PLAYER_SERVER_ID = 1;

	const packetLoss = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 0 /* PacketLoss */);
	const packetLossVariance = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 1 /* PacketLossVariance */);
	const packetLossEpoch = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 2 /* PacketLossEpoch */)
	const rtt = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 3 /* RoundTripTime */);
	const rttVariance = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 4 /* RoundTripTimeVariance */);
	const lastRtt = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 5 /* LastRoundTripTime */);
	const lastRttVariance = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 6 /* LastRoundTripTimeVariance */);
	const packetThrottleEpoch = GetPlayerPeerStatistics(PLAYER_SERVER_ID, 7 /* PacketThrottleEpoch */);

	console.log(`packetLoss: ${packetLoss}`);
	console.log(`packetLossVariance: ${packetLossVariance}`);
	console.log(`packetLossEpch: ${packetLossEpoch}`);

	console.log(`packetLossScaled: ${packetLoss / ENET_PACKET_LOSS_SCALE}`);
	console.log(`packetLossVarianceScaled: ${packetLossVariance / ENET_PACKET_LOSS_SCALE}`);

	console.log(`rtt: ${rtt}`);
	console.log(`rttVariance: ${rttVariance}`);

	console.log(`lastRtt: ${lastRtt}`);
	console.log(`lastRttVariance: ${lastRttVariance}`);
	console.log(`packetThrottleEpoch: ${packetThrottleEpoch}`);
}, 10000)
```

*Sources: Cfx.re native reference.*
