AWS DEVELOPMENT / DOCUMENTATION

Your server. Our expertise.

Everything you need to install, configure and build.

94 guides • 11 resources • Always here to help
About resource versions

These guides include the original resource names. Use the folder and SQL names supplied with your downloaded version. A renamed AWS package may differ from the original EXIT release.

esx.lua

if Config.Framework ~= "esx" then
    return
end

Citizen.CreateThreadNow(function()
    ESX = exports["es_extended"]:getSharedObject()
end)

function GetPlayerIdentifier(source)
    local Player = GetPlayerId(source)
    if Player then
        return Player.identifier
    end
end

function GetPlayerId(source)
    local Player = ESX.GetPlayerFromId(source)
    return Player
end

function GetItemCountFromInventory(source, item)
    local xPlayer = ESX.GetPlayerFromId(source)
    local itemData = xPlayer.getInventoryItem(item)
    if itemData then
        return itemData.count
    end
end

function AddInventoryItem(src, item, quantity)
    local xPlayer = ESX.GetPlayerFromId(src)
    xPlayer.addInventoryItem(item, quantity)
end

function RemoveInventoryItem(item, quantity)
    local xPlayer = ESX.GetPlayerFromId(source)
    xPlayer.removeInventoryItem(item, quantity)
end

function AddMoney(source, price)
    local xPlayer = GetPlayerId(source)
    xPlayer.addAccountMoney('money', price)
end

function RemoveMoney(price, src)
    if src then
        local xPlayer = GetPlayerId(src)
        xPlayer.removeAccountMoney('money', price)
    else
        local xPlayer = GetPlayerId(source)
        xPlayer.removeAccountMoney('money', price)
    end
end

function GetMoney(source)
    local xPlayer = GetPlayerId(source)
    local money = xPlayer.getMoney()
    return money
end

function RegisterServerCallback(name, cb)
    ESX.RegisterServerCallback(name, cb)
end

function GetPlayers()
    local xPlayers = ESX.GetPlayers()
    return xPlayers
end

function GetPlayerFromIdentifier(identifier)
    local xPlayer = ESX.GetPlayerFromIdentifier(identifier)
    if xPlayer then
        return xPlayer.source
    else
        return nil
    end
end

function GetUserName(source)
    local xPlayer = ESX.GetPlayerFromId(source)
    if xPlayer then
        local firstname = xPlayer.get('firstName')
        local lastname = xPlayer.get('lastName')
        return firstname .. " " .. lastname
    else
        return 'Unknown'
    end
end