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' and (Config.Framework ~= 'auto' or GetResourceState('es_extended') ~= 'started' or GetResourceState('qb-core') == 'started') then return end


local ESX = exports['es_extended']:getSharedObject()
Bridge = {}

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

function Bridge.GetPoliceCount()
    local count = 0
    for _, xPlayer in pairs(ESX.GetExtendedPlayers('job', 'police')) do
        count = count + 1
    end
    return count
end

function Bridge.HasItem(source, item)
    if GetResourceState('ox_inventory') == 'started' then
        local count = exports.ox_inventory:Search(source, 'count', item)
        return count and count > 0
    end
    
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    local itm = xPlayer.getInventoryItem(item)
    return itm and itm.count > 0
end

function Bridge.RemoveItem(source, item, amount)
    if GetResourceState('ox_inventory') == 'started' then
        return exports.ox_inventory:RemoveItem(source, item, amount)
    end
    
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    local itm = xPlayer.getInventoryItem(item)
    if itm and itm.count >= amount then
        xPlayer.removeInventoryItem(item, amount)
        return true
    end
    return false
end

function Bridge.AddMoney(source, type, amount, reason)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    local actType = type
    if actType == 'cash' then actType = 'money' end
    xPlayer.addAccountMoney(actType, amount, reason)
    return true
end

function Bridge.AddItem(source, item, amount)
    local xPlayer = ESX.GetPlayerFromId(source)
    if not xPlayer then return false end
    xPlayer.addInventoryItem(item, amount)
    return true
end

function Bridge.CreateUseableItem(item, cb)
    ESX.RegisterUsableItem(item, function(source)
        cb(source, item)
    end)
end

function Bridge.AlertPolice(coords)
    local xPlayers = ESX.GetExtendedPlayers('job', 'police')
    for _, xPlayer in pairs(xPlayers) do
        TriggerClientEvent('corner-selling:client:CallDispatch', xPlayer.source, coords)
    end
end