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.

qb.lua

function DependencyCheck(data)
    for k, v in pairs(data) do
        if GetResourceState(k):find('started') ~= nil then
            return v
        end
    end
    return false
end

local frameworks = {
    ['es_extended'] = 'esx',
    ['qb-core'] = 'qb',
    ['qbx_core'] = 'qb'
}

Config.Framework = DependencyCheck(frameworks) or 'none'

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

Citizen.CreateThreadNow(function()
    if Config.Framework == 'qb' then
        QBCore = exports['qb-core']:GetCoreObject()
    end
end)

RegisterNetEvent('QBCore:Server:OnPlayerLoaded', function()
    local src = source
    -- print('Loaded player:', src)
    CreateQuests(src)
end)

CreateThread(function()
    for k, v in pairs(QBCore.Functions.GetPlayers()) do
        if v then
            -- print('Loaded player:', v)
            CreateQuests(v)
        end
    end
end)

function GetPlayers()
    local xPlayers = QBCore.Functions.GetPlayers()
    return xPlayers
end

function GetPlayeridentifier(source)
    local Player = QBCore.Functions.GetPlayer(source) or false
    if Player then
        return Player.PlayerData.citizenid
    end
end

function GetPlayerId(source)
    local Player = QBCore.Functions.GetPlayer(source)
    return Player
end

function GetItemCountFromInventory(src, item)
    if not src then src = source end
    local xPlayer = GetPlayerId(src)
    if not xPlayer then return 0 end
    
    local function normalize(str)
        if not str then return "" end
        return str:lower():gsub("%s+", ""):gsub("_", ""):gsub("[^%w]", "")
    end
    
    local target = normalize(item)
    local count = 0
    
    -- 1. Try direct exports for best accuracy
    if GetResourceState('exit-inventory') == 'started' then
        count = exports['exit-inventory']:GetItemCount(src, item)
    elseif GetResourceState('ox_inventory') == 'started' then
        count = exports.ox_inventory:GetItemCount(src, item)
    end

    -- 2. If exports didn't work (or 0), try PlayerData items with smart matching
    if count == 0 and xPlayer.PlayerData and xPlayer.PlayerData.items then
        for _, invItem in pairs(xPlayer.PlayerData.items) do
            if invItem and (invItem.name or invItem.label) then
                local normName = normalize(invItem.name)
                local normLabel = normalize(invItem.label)
                if normName == target or normLabel == target or string.find(normName, target) then
                    count = count + (invItem.amount or 0)
                end
            end
        end
    end
    
    if count > 0 then
        -- print(string.format("^2[Lumberjack Debug]^7 Found %d x %s for Player %s (%s)", count, item, GetPlayerName(src), src))
    end
    
    return count
end

function AddInventoryItem(src, item, quantity)
    local xPlayer = GetPlayerId(src)
    xPlayer.Functions.AddItem(item, quantity)
end

function RemoveInventoryItem(item, quantity)
    local src = source
    if not src or src == 0 then return end
    local xPlayer = GetPlayerId(src)
    if not xPlayer then return end
    
    -- print(string.format("^3[Lumberjack Debug]^7 Removing %d x %s from %s", quantity, item, GetPlayerName(src)))
    
    if GetResourceState('exit-inventory') == 'started' then
        exports['exit-inventory']:RemoveItem(src, item, quantity)
    elseif GetResourceState('ox_inventory') == 'started' then
        exports.ox_inventory:RemoveItem(src, item, quantity, nil)
    else
        xPlayer.Functions.RemoveItem(item, quantity)
        TriggerClientEvent('inventory:client:ItemBox', src, QBCore.Shared.Items[item], "remove")
    end
end

function AddMoney(source, price) --MODIFICACION
    if source then
        local xPlayer = GetPlayerId(source) or false
        if xPlayer then
            xPlayer.Functions.AddMoney('cash', price)
        end
    end
end

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

function GetMoney(source)
    local xPlayer = GetPlayerId(source)
    local money = xPlayer.PlayerData.money["cash"]
    return money
end

function RegisterServerCallback(name, cb)
    QBCore.Functions.CreateCallback(name, cb)
end

function GetPlayerFromIdentifier(identifier) --MODIFICACION
    local xPlayer = QBCore.Functions.GetSource(identifier)
    if xPlayer then
        return xPlayer
    else
        return nil
    end
end