Page cover

İtem Money

This document explains the required modifications in `qb-core` and `qb-inventory` for money functions and inventory events. Code blocks are copy-paste ready.

RemoveMoney Function

Description: qb-core/server/player.lua Replace self.Functions.RemoveMoney with the following:


     function self.Functions.RemoveMoney(moneytype, amount, reason)
        source = self.PlayerData.source
        reason = reason or 'unknown'
        moneytype = moneytype:lower()
        amount = tonumber(amount)
        if amount < 0 then return end
        if not self.PlayerData.money[moneytype] then return false end
        for _, mtype in pairs(QBCore.Config.Money.DontAllowMinus) do
            if mtype == moneytype and moneytype == not 'cash' then
                if (self.PlayerData.money[moneytype] - amount) < 0 then
                    return false
                end
            end
        end
        if moneytype == 'cash' then
            
            if exports['qb-inventory']:HasItem(source,'cash') then
                local totalmoney = self.Functions.GetMoney('cash')
                if totalmoney >= amount then
                    self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
                    local slots = exports['qb-inventory']:GetSlotsByItem(self.PlayerData.items,'cash')
                    for k,v in pairs(slots) do
                        local toRemove = math.min(exports['qb-inventory']:GetItemBySlot(source,slots[k]).amount,amount)
                        exports['qb-inventory']:RemoveItem(source,'cash',toRemove,slots[k],nil,"qb-core:addmoney")
                        TriggerClientEvent('inventory:client:ItemBox',source, QBCore.Shared.Items['cash'], "remove",toRemove)
                    end
                    
                else
                    return false
                end
            else
                return false
            end
        else
            self.PlayerData.money[moneytype] = self.PlayerData.money[moneytype] - amount
        end
        

        if not self.Offline then
            self.Functions.UpdatePlayerData()
            if amount > 100000 then
                TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason, true)
            else
                TriggerEvent('qb-log:server:CreateLog', 'playermoney', 'RemoveMoney', 'red', '**' .. GetPlayerName(self.PlayerData.source) .. ' (citizenid: ' .. self.PlayerData.citizenid .. ' | id: ' .. self.PlayerData.source .. ')** $' .. amount .. ' (' .. moneytype .. ') removed, new ' .. moneytype .. ' balance: ' .. self.PlayerData.money[moneytype] .. ' reason: ' .. reason)
            end
            TriggerClientEvent('hud:client:OnMoneyChange', self.PlayerData.source, moneytype, amount, true)
            if moneytype == 'bank' then
                TriggerClientEvent('qb-phone:client:RemoveBankMoney', self.PlayerData.source, amount)
            end
            TriggerClientEvent('QBCore:Client:OnMoneyChange', self.PlayerData.source, moneytype, amount, "remove", reason)
            TriggerEvent('QBCore:Server:OnMoneyChange', self.PlayerData.source, moneytype, amount, "remove", reason)
        end

        return true
    end

AddMoney Function

Description: qb-core/server/player.lua Replace self.Functions.AddMoney with the following:


SetMoney Function

Description: qb-core/server/player.lua Replace self.Functions.SetMoney with the following:


🔍 GetMoney Function

Description: qb-core/server/player.lua Replace self.Functions.GetMoney with the following:


🔍 AddItem Function

Description: qb-inventory/server/open_server.lua Replace the AddItem function with the following:


🔍 RemoveItem Function

Description: qb-inventory/server/open_server.lua Replace the RemoveItem function with the following:


📦 Inventory Event: inventory:server:SetInventoryData

Description: qb-inventory/server/open_server.lua Replace the inventory:server:SetInventoryData event with the following:

Last updated