# CFX::GET_PLAYER_FROM_STATE_BAG_NAME

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

## Signature

```c
int GET_PLAYER_FROM_STATE_BAG_NAME(char* bagName);
```

## Parameters

- `bagName` (`char*`) — An internal state bag ID from the argument to a state bag change handler.

## Returns

`int` — The player handle or 0 if the state bag name did not refer to a player, or the player does not exist.

## Description

*Source: Cfx.re native reference*

On the server this will return the players source, on the client it will return the player handle.

## Usage

### Lua

```lua
local retval = GetPlayerFromStateBagName(bagName)

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

### JavaScript

```js
const retval = GetPlayerFromStateBagName(bagName);

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

### C#

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

## Examples

*Source: Cfx.re native reference*

```js
AddStateBagChangeHandler("isDead", null, async (bagName, key, value /* boolean */) => {
    const ply = GetPlayerFromStateBagName(bagName);
    // The player doesn't exist!
    if (ply === 0) return;
    console.log(`Player: ${GetPlayerName(ply)} ${value ? 'died!' : 'is alive!'`)
})
```

*Source: Cfx.re native reference*

```lua
AddStateBagChangeHandler("isDead", nil, function(bagName, key, value) 
    local ply = GetPlayerFromStateBagName(bagName)
    -- The player doesn't exist!
    if ply == 0 then return end
    print("Player: " .. GetPlayerName(ply) .. value and 'died!' or 'is alive!')
end)
```

*Sources: Cfx.re native reference.*
