I think I had the same problem, I made some modifications but it is in Spanish, although I don’t think it will affect it. I hope it helps you. Replace the code in /bridge/server/qbcore.lua
local Config = require("shared.sh_config")
local Locales = require("shared.sh_locales")
-- Verifica que el framework sea qbcore
if Config.Framework ~= "qbcore" then return end
local QBCore = exports["qb-core"]:GetCoreObject()
local inShop = {}
-- Obtener el jugador por su ID
local function GetPlayerId(source)
if not source or source == 0 then return nil end
return QBCore.Functions.GetPlayer(source)
end
-- Verifica si el jugador puede llevar una cierta cantidad de un artículo
local function CanCarryItem(source, itemName, itemQuantity)
-- Usando qb-inventory para verificar si puede llevar el artículo
return exports["qb-inventory"]:CanAddItem(source, itemName, itemQuantity)
end
-- Agregar un artículo al inventario del jugador
local function AddItem(source, itemName, itemQuantity)
-- Usando qb-inventory para agregar el artículo
return exports["qb-inventory"]:AddItem(source, itemName, itemQuantity, false, false, "cloud-shop:AddItem")
end
-- Verificar si el jugador tiene una licencia específica
local function HasLicense(source, licenseType)
if not source or source == 0 then return false end
if not licenseType then return false end
local Player = GetPlayerId(source)
if not Player then return false end
return Player.PlayerData.metadata.licences[licenseType] ~= nil
end
-- Comprar una licencia para el jugador
local function BuyLicense(source, shopData)
if not source or source == 0 then return false, "Fuente inválida" end
if not shopData or next(shopData) == nil then return false, "Datos de la tienda inválidos o vacíos" end
if not inShop[source] then return false, "No estás en la tienda" end
local Player = GetPlayerId(source)
if not Player then return false, "Jugador no encontrado" end
local licenseType = shopData.License.Type
local amount = shopData.License.Price
-- Obtener dinero disponible en efectivo y banco
local moneyAvailable = Player.Functions.GetMoney("cash") -- Usamos "cash" para dinero en efectivo
local bankAvailable = Player.Functions.GetMoney("bank") -- Usamos "bank" para dinero del banco
local accountType
if moneyAvailable >= amount then
accountType = "cash" -- Usamos "cash" si hay suficiente efectivo
elseif bankAvailable >= amount then
accountType = "bank" -- Usamos "bank" si hay suficiente dinero en la cuenta bancaria
else
ServerNotify(source, Locales.License.NoMoney:format(licenseType), "error")
return false, "No tienes suficiente dinero"
end
-- Quitar el dinero del jugador
Player.Functions.RemoveMoney(accountType, amount)
-- Agregar la licencia al jugador
local licenseTable = Player.PlayerData.metadata.licences
licenseTable[licenseType] = true
Player.Functions.SetMetaData("licences", licenseTable)
ServerNotify(source, Locales.License.PurchaseSuccess:format(licenseType, amount), "info")
return true, "Licencia comprada con éxito"
end
-- Si no se usa armas como artículos ni ox_inventory
if not Config.WeaponAsItem then
-- Función para verificar si el jugador tiene un arma
function HasWeapon(source, weaponName)
-- Implementa la lógica para verificar si el jugador tiene el arma
end
-- Función para agregar un arma al jugador
function AddWeapon(source, weaponName)
-- Implementa la lógica para agregar el arma al jugador
end
end
-- Procesar la transacción de compra en la tienda
local function ProcessTransaction(source, type, cartArray)
if not source or source == 0 then return false, "Fuente inválida" end
if not cartArray or #cartArray == 0 then return false, "Carrito vacío o inválido" end
if not inShop[source] then return false, "No estás en la tienda" end
local Player = GetPlayerId(source)
if not Player then return false, "Jugador no encontrado" end
-- Determinar el tipo de cuenta (banco o efectivo)
local accountType = (type == "bank" and "bank") or "cash" -- Usamos "cash" si el tipo es "cash", de lo contrario "bank"
local totalCartPrice = 0
for _, item in ipairs(cartArray) do
-- Obtener la cantidad de dinero disponible
local availableMoney = Player.Functions.GetMoney(accountType) or 0 -- Aseguramos que availableMoney sea un número
local totalItemPrice = (item.price * item.quantity) or 0 -- Aseguramos que totalItemPrice sea un número
-- Verificar que el dinero disponible sea suficiente para la compra
if availableMoney >= totalItemPrice then
-- Si el artículo es un arma y no se permite como artículo
if item.name:sub(1, 7):lower() == "weapon_" and not Config.WeaponAsItem then
if not HasWeapon(source, item.name) then
-- Quitar el dinero del jugador
Player.Functions.RemoveMoney(accountType, totalItemPrice)
AddWeapon(source, item.name)
totalCartPrice = totalCartPrice + totalItemPrice
else
ServerNotify(source, Locales.Notification.HasWeapon:format(item.label), "error")
end
else
-- Verificar si el jugador puede llevar el artículo
if CanCarryItem(source, item.name, item.quantity) then
-- Quitar el dinero del jugador y agregar el artículo
Player.Functions.RemoveMoney(accountType, totalItemPrice)
AddItem(source, item.name, item.quantity)
totalCartPrice = totalCartPrice + totalItemPrice
else
ServerNotify(source, Locales.Notification.CantCarry:format(item.label), "error")
end
end
else
ServerNotify(source, Locales.Notification.NoMoney:format(item.label), "error")
end
end
if totalCartPrice > 0 then
ServerNotify(source, Locales.Notification.PurchaseSuccess:format(totalCartPrice), "success")
return true, ("Artículo(s) comprado(s) por $%s"):format(totalCartPrice)
end
return false, "No se compraron artículos"
end
-- Registro de los callbacks para la tienda
lib.callback.register("cloud-shop:server:HasLicense", HasLicense)
lib.callback.register("cloud-shop:server:BuyLicense", function(source, shopData)
local success, reason = BuyLicense(source, shopData)
return success, reason
end)
lib.callback.register("cloud-shop:server:ProcessTransaction", function(source, type, cartArray)
local success, reason = ProcessTransaction(source, type, cartArray)
return success, reason
end)
lib.callback.register("cloud-shop:server:InShop", function(source, status)
inShop[source] = status
end)