moneyEditable.lua
local cashAmount = 0
local bankAmount = 0
local function updateMoney(cash, bank, addOrRemove)
sendNui("updateMoneyData", {
cash = cash,
bank = bank
})
if addOrRemove then
sendNui("addRemoveMoney", addOrRemove)
end
end
function fristLoginMoney(PlayerData)
if config.framework == "esx" then
if not PlayerData.accounts then return end
for _, data in pairs(PlayerData.accounts) do
if data.name == "bank" then
bankAmount = data.money
elseif data.name == "money" then
cashAmount = data.money
end
end
elseif config.framework == "qb" then
cashAmount = PlayerData.money.cash
bankAmount = PlayerData.money.bank
end
updateMoney(cashAmount, bankAmount)
end
RegisterNetEvent("esx:setAccountMoney", function(account)
local addOrRemove = nil
if account.name == "money" then
if account.money ~= cashAmount then
local newValue = account.money - cashAmount
addOrRemove = {
money = newValue < 0 and math.abs(newValue) or newValue,
isMinus = newValue < 0
}
end
cashAmount = account.money
elseif account.name == "bank" then
bankAmount = account.money
end
updateMoney(cashAmount, bankAmount, addOrRemove)
end)
RegisterNetEvent("QBCore:Client:OnMoneyChange")
AddEventHandler("QBCore:Client:OnMoneyChange", function(moneyType, amount, addOrRemove)
if moneyType == "cash" then
cashAmount = addOrRemove == "add" and (cashAmount + amount) or (cashAmount - amount)
elseif moneyType == "bank" then
bankAmount = addOrRemove == "add" and (bankAmount + amount) or (bankAmount - amount)
end
updateMoney(cashAmount, bankAmount, moneyType == "cash" and {
money = amount,
isMinus = addOrRemove == "remove"
})
end)
Last updated