ESX = exports['es_extended']:getSharedObject() -- ===================== -- CALLBACKS -- ===================== ESX.RegisterServerCallback('mercyv-wash:getDirtyMoney', function(source, cb) local xPlayer = ESX.GetPlayerFromId(source) if not xPlayer then return cb(0) end local success, amount = pcall(function() return exports['codem-inventory']:GetItemsTotalAmount(source, Config.DirtyItem) end) if not success or not amount then amount = 0 local inv = xPlayer.getInventory() if inv then for _, item in pairs(inv) do if item and item.name == Config.DirtyItem then amount = amount + (tonumber(item.amount or item.count) or 0) end end end end cb(tonumber(amount) or 0) end) -- ===================== -- WASH EVENT -- ===================== RegisterNetEvent('mercyv-wash:wash') AddEventHandler('mercyv-wash:wash', function(amount, stationId) local source = source local xPlayer = ESX.GetPlayerFromId(source) if not xPlayer then return end -- Validate station local station = Config.WashStations[stationId] if not station then TriggerClientEvent('mercyv-wash:washResult', source, false, 'Ungueltige Station') return end -- Sanitize amount amount = math.max(1, math.floor(tonumber(amount) or 0)) -- Check player has enough dirty money local success, totalAmount = pcall(function() return exports['codem-inventory']:GetItemsTotalAmount(source, Config.DirtyItem) end) if not success then totalAmount = 0 local inv = xPlayer.getInventory() if inv then for _, item in pairs(inv) do if item and item.name == Config.DirtyItem then totalAmount = totalAmount + (tonumber(item.amount or item.count) or 0) end end end end totalAmount = tonumber(totalAmount) or 0 if totalAmount < amount then TriggerClientEvent('mercyv-wash:washResult', source, false, 'Nicht genug ' .. Config.DirtyLabel) return end -- Calculate clean amount local cleanAmount = math.floor(amount * Config.WashRate) local fee = amount - cleanAmount -- Remove dirty money local removeSuccess = pcall(function() exports['codem-inventory']:RemoveItem(source, Config.DirtyItem, amount) end) if not removeSuccess then xPlayer.removeInventoryItem(Config.DirtyItem, amount) end -- Add clean money xPlayer.addAccountMoney('money', cleanAmount) TriggerClientEvent('mercyv-wash:washResult', source, true, '$' .. amount .. ' gewaschen! $' .. cleanAmount .. ' erhalten ($' .. fee .. ' Gebuehr)') end)