πŸ”₯All scripts on our website are 50% off!πŸ”₯
Logo

Server Functions

The script includes four main server functions to handle reward distribution across both ESX and QBCore frameworks.

Give Items

function GiveItemToPlayer(playerID, itemName, amount)
    if Config.Framework == "esx" then
        local xPlayer = ESX.GetPlayerFromId(playerID)
        xPlayer.addInventoryItem(itemName, amount)
        return true
    else
        local xPlayer = QBCore.Functions.GetPlayer(playerID)
        xPlayer.Functions.AddItem(itemName, amount)
        return true
    end
end

This function adds items to the player's inventory based on the configured framework.

Give Money

function GiveMoneyToPlayer(playerID, amount)
    if Config.Framework == "esx" then
        local xPlayer = ESX.GetPlayerFromId(playerID)
        xPlayer.addMoney(amount)
        return true
    else
        local xPlayer = QBCore.Functions.GetPlayer(playerID)
        xPlayer.Functions.AddMoney('cash', amount, "Reward")
        return true
    end
end

This function adds cash money to the player based on the configured framework.

Give Weapons

function GiveWeaponToPlayer(playerID, weapon, amount)
    if Config.Framework == "esx" then
        local xPlayer = ESX.GetPlayerFromId(playerID)
        xPlayer.addWeapon(weapon, amount)
        return true
    else
        local xPlayer = QBCore.Functions.GetPlayer(playerID)
        xPlayer.Functions.AddItem(weapon, amount)
        return true
    end
end

This function gives weapons to the player. Note that in QBCore, weapons are handled as items.

Give Vehicles

function GiveVehicleToPlayer(playerID, vehicleProps)
    if Config.Framework == "esx" then
        local xPlayer = ESX.GetPlayerFromId(playerID)
        SqlFunc(Config.Mysql, 'execute',
            'INSERT INTO owned_vehicles (owner, plate, vehicle, stored) VALUES (@owner, @plate, @vehicle, @stored)', {
                ['@owner'] = xPlayer.identifier,
                ['@plate'] = vehicleProps.plate,
                ['@vehicle'] = json.encode(vehicleProps),
                ['@stored'] = 1
            })
        return true
    else
        local xPlayer = QBCore.Functions.GetPlayer(playerID)
        SqlFunc(Config.Mysql, 'execute',
            'INSERT INTO player_vehicles (citizenid, plate, mods, stored) VALUES (@citizenid, @plate, @mods, @state)', {
                ['@citizenid'] = Player.PlayerData.citizenid,
                ['@plate'] = vehicleProps.plate,
                ['@mods'] = json.encode(vehicleProps),
                ['@state'] = 1
            })
        return true
    end
end

This function registers vehicles in the database for the player. The vehicle is added to the player's owned vehicles table.

Framework Compatibility

All server functions automatically detect the configured framework and use the appropriate methods:

  • ESX: Uses standard ESX functions like addInventoryItem, addMoney, addWeapon
  • QBCore: Uses QBCore functions like AddItem, AddMoney

The functions return true on successful execution, allowing for error handling in your code.