RX Scripts Logo
Player

Functions

Server-side player functions and the powerful player object system.

The Player adapter provides a unified player object system that works across ESX and QBCore.

Main Functions

get

Gets a player object by source ID or identifier.

FM.player.get(id)
id
number|string required

Player source ID (number) or identifier (string)

Returns: Player|nil - Player object with methods and data, or nil if not found

Example:

RegisterNetEvent('myEvent', function()
    local src = source
    -- Get player by source
    local player = FM.player.get(src)

    -- Get player by identifier
    local player = FM.player.get("char1:110000104d8e3a8")  -- ESX
    local player = FM.player.get("ABC12345")                -- QB citizenid
end)

getFullnameByIdentifier

Get player full name by identifier (database query).

FM.player.getFullnameByIdentifier(identifier)
identifier
string required

Player identifier (ESX identifier or QB citizen ID)

Returns: string|nil - Player's full name (firstname lastname) or nil if not found

Example:

local name = FM.player.getFullnameByIdentifier("char1:110000104d8e3a8")
print(name) -- Output: "John Doe"

Player Object Methods

When you call FM.player.get(src), you receive a player object with the following methods:

getIdentifier

Returns the player's unique identifier.

player.getIdentifier()

Returns: string - Player's identifier (ESX) or citizenid (QB)

Example:

RegisterNetEvent('myEvent', function()
    local src = source
    local player = FM.player.get(src)
    local identifier = player.getIdentifier()
    print("Player ID:", identifier)
end)

getName / getFullName

Returns the player's full name.

player.getFullName()

Returns: string - Player's full name (firstname lastname)


getFirstName

Returns the player's first name.

player.getFirstName()

Returns: string - Player's first name


getLastName

Returns the player's last name.

player.getLastName()

Returns: string - Player's last name


getSource

Returns the player's source ID.

player.getSource()

Returns: number - Player source ID


getJob

Returns the player's job data.

player.getJob()

Returns: Job - Job data

Job Structure:

{
    name = "police",
    label = "Police",
    grade = 2,
    gradeLabel = "Sergeant"
}

getGang

Returns the player's gang data (QB only, ESX returns job as gang).

player.getGang()

Returns: Gang|nil - Gang data


getMoney

Gets the player's money amount for a specific type.

player.getMoney(type)
type
string

Money type (optional, defaults to 'money'). Common types: 'money', 'bank', 'black_money'

Returns: number - Money amount

Example:

RegisterNetEvent('checkBalance', function()
    local src = source
    local player = FM.player.get(src)
    local cash = player.getMoney('money')
    local bank = player.getMoney('bank')
    print("Cash:", cash, "Bank:", bank)
end)

addMoney

Adds money to the player's account.

player.addMoney(amount, type, transactionData)
amount
number required

Amount of money to add

type
string

Money type (optional, defaults to 'money')

transactionData
TransactionData

Optional transaction data for banking integration

TransactionData Structure:

{
    type = "payment",          -- 'payment', 'deposit', 'withdraw', 'transfer', 'interest'
    fromIban = "NL12345",      -- Source IBAN
    reason = "Salary payment"  -- Transaction reason
}

Example:

RegisterNetEvent('giveMoney', function()
    local src = source
    local player = FM.player.get(src)

    -- Add cash
    player.addMoney(500, 'money')

    -- Add to bank with transaction
    player.addMoney(1000, 'bank', {
        type = "payment",
        fromIban = "COMPANY001",
        reason = "Weekly salary"
    })
end)

removeMoney

Removes money from the player's account.

player.removeMoney(amount, type, transactionData)
amount
number required

Amount of money to remove

type
string

Money type (optional, defaults to 'money')

transactionData
TransactionData

Optional transaction data for banking integration

Example:

RegisterNetEvent('purchase', function()
    local src = source
    local player = FM.player.get(src)

    -- Remove cash
    if player.getMoney('money') >= 500 then
        player.removeMoney(500, 'money')
        player.notify("You paid $500", "success")
    else
        player.notify("Insufficient cash", "error")
    end

    -- Remove from bank with transaction
    player.removeMoney(100, 'bank', {
        type = "withdraw",
        toIban = "PLAYER123",
        reason = "ATM withdrawal"
    })
end)

getItem

Gets information about a specific item in the player's inventory.

player.getItem(item)
item
string required

Item name

Returns: Item|nil - Item data or nil if not found

Item Structure:

{
    name = "water",
    label = "Water",
    amount = 5
}

Example:

RegisterNetEvent('checkItem', function()
    local src = source
    local player = FM.player.get(src)
    local water = player.getItem("water")
    if water then
        print("Player has", water.amount, "water bottles")
    end
end)

getItems

Gets all items in the player's inventory.

player.getItems()

Returns: table<number, Item> - Table of items indexed by slot


addItem

Adds an item to the player's inventory.

player.addItem(item, amount, metadata, ignoreCheck)
item
string required

Item name

amount
number required

Amount to add

metadata
table

Item metadata (optional)

ignoreCheck
boolean

Skip weight/space check (optional, defaults to false)

Returns: boolean - True if item was added successfully

Example:

RegisterNetEvent('giveItem', function()
    local src = source
    local player = FM.player.get(src)

    -- Add item
    if player.addItem("water", 5) then
        player.notify("Received 5 water bottles", "success")
    else
        player.notify("Inventory full", "error")
    end

    -- Add with metadata
    player.addItem("weapon_pistol", 1, {
        ammo = 50,
        durability = 100,
        serial = "ABC123"
    })
end)

removeItem

Removes an item from the player's inventory.

player.removeItem(item, amount, slotId, metadata)
item
string required

Item name

amount
number required

Amount to remove

slotId
number

Specific slot to remove from (optional)

metadata
table

Specific metadata to match (optional)

Example:

RegisterNetEvent('useItem', function()
    local src = source
    local player = FM.player.get(src)
    player.removeItem("water", 1)
    player.notify("You drank water", "success")
end)

canAddItem

Checks if the player can add an item (weight/space check).

player.canAddItem(item, amount)
item
string required

Item name

amount
number required

Amount to check

Returns: boolean - True if player can carry the item


hasItemAmount

Checks if the player has a specific amount of an item.

player.hasItemAmount(item, amount)
item
string required

Item name

amount
number required

Required amount

Returns: boolean - True if player has at least the specified amount

Example:

RegisterNetEvent('craft', function()
    local src = source
    local player = FM.player.get(src)
    if player.hasItemAmount("iron", 10) then
        print("Player has enough iron")
    end
end)

notify

Sends a notification to the player.

player.notify(message, type)
message
string required

Notification message

type
'success'|'error'|'info'

Notification type (optional)

Example:

RegisterNetEvent('doAction', function()
    local src = source
    local player = FM.player.get(src)
    player.notify("Action completed!", "success")
    player.notify("An error occurred", "error")
end)

setJob

Sets the player's job.

player.setJob(jobName, grade)
jobName
string required

Job name

grade
number required

Job grade

Example:

RegisterNetEvent('promotePlayer', function()
    local src = source
    local player = FM.player.get(src)
    player.setJob("police", 2)
    player.notify("You are now a Sergeant", "success")
end)

setGang

Sets the player's gang (QB only).

player.setGang(gangName, grade)
gangName
string required

Gang name

grade
number required

Gang grade


isAdmin

Checks if the player is an admin.

player.isAdmin()

Returns: boolean - True if player is admin

Note: This checks for admin group in ESX, 'admin' or 'god' permission in QB, or ACE permissions.

getGroup

Gets the player's permission group.

player.getGroup()

Returns: string - Permission group name

Exports

All player functions are available as exports:

exports['fmLib']:player_get(id)
exports['fmLib']:player_getFullnameByIdentifier(identifier)