133 lines
6.4 KiB
Lua
133 lines
6.4 KiB
Lua
|
|
framework = 'bigdaddy' --VALUES CAN BE 'nat', 'qb', 'esx', 'nd', 'bigdaddy' or 'custom'
|
|
|
|
reason = 'Bus Fare' --reason for the transaction will notify using framework methods
|
|
|
|
useSociety = false
|
|
toSocietyaccount = ''
|
|
local currencySymbol = '$'
|
|
|
|
if framework == 'nat' then
|
|
print('Framework set to nat')
|
|
elseif framework == 'qb' then
|
|
QBCore = exports['qb-core']:GetCoreObject()
|
|
elseif framework == 'esx' then
|
|
ESX = exports["es_extended"]:getSharedObject()
|
|
elseif framework == 'nd' then
|
|
NDCore = exports.ND_Core:GetCoreObject()
|
|
elseif framework == 'bigdaddy' then
|
|
print('Framework set to Big Daddy')
|
|
elseif framework == 'custom' then
|
|
print('LOAD CORE OBJECT HERE IF REQUIRED, if not then you may disregard this statement.')
|
|
else
|
|
print('FRAMEWORK IS NOT SET PROPERLY FOR RESOURCE! Check server.lua in ' .. GetCurrentResourceName() .. ' for money events. The current value is set to ' .. framework .. ', and this is not a valid selection.' )
|
|
end
|
|
|
|
RegisterNetEvent('BigDaddy-Jobs-BusDriver:Pay', function(amount, playerId)
|
|
local src = source
|
|
|
|
if framework == 'nat' then
|
|
local account = exports.money:getaccount(src)
|
|
if (tonumber(account.bank) >= tonumber(amount)) then
|
|
local newbalance = tonumber(account.cash) - tonumber(amount)
|
|
exports.money:updateaccount(src, {cash = newbalance, bank = account.bank})
|
|
exports.money:bankNotify(src, reason .. ' ' .. currencySymbol .. amount )
|
|
TriggerClientEvent('BigDaddy--Jobs-BusDriver:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy--Jobs-BusDriver:IsPaid', src, false)
|
|
end
|
|
return true
|
|
elseif framework == 'qb' then
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
if (Player.Functions.GetMoney(cash) >= tonumber(amount)) then
|
|
Player.Functions.RemoveMoney('cash', tonumber(amount), reason)
|
|
if (useSociety) then
|
|
exports['qb-management']:AddMoney(toSocietyaccount, tonumber(amount))
|
|
end
|
|
TriggerClientEvent('QBCore:Notify', src, reason, 'primary', 5000)
|
|
--Player.Functions.AddMoney('bank', amount, reason)
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, false)
|
|
end
|
|
elseif framework == 'esx' then
|
|
local xPlayer = ESX.GetPlayerFromId(src)
|
|
if (xPlayer.getAccount("cash") >= tonumber(amount)) then
|
|
xPlayer.removeAccountMoney('cash', tonumber(amount))
|
|
xPlayer.showNotification(reason)
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, false)
|
|
end
|
|
--xPlayer.addAccountMoney('bank', amount)
|
|
elseif framework == 'nd' then
|
|
local Player = NDCore.Functions.GetPlayer(src)
|
|
if (Player.amount >= amount) then
|
|
NDCore.Functions.DeductMoney(amount, src, 'cash', reason)
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, false)
|
|
end
|
|
elseif framework == 'bigdaddy' then
|
|
local account = exports['BigDaddy-Money']:GetAccounts(src, playerId, -1)
|
|
local data = json.decode(account)
|
|
if (data ~= null and tonumber(data.cash) >= tonumber(amount)) then
|
|
local newbalance = tonumber(data.cash) - tonumber(amount)
|
|
exports['BigDaddy-Money']:UpdateTotals(src, data.bank, newbalance, data.dirty, -1)
|
|
TriggerClientEvent("BigDaddy-Money:Notify", src, 'Paid ' .. currencySymbol .. string.format("%.2f", amount) .. ' ' .. reason)
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-Jobs-BusDriver:IsPaid', src, false)
|
|
end
|
|
elseif framework == 'custom' then
|
|
--INSERT CUSTOM CODE HERE FOR CASH MANAGEMENT
|
|
else
|
|
print('FRAMEWORK IS NOT SET PROPERLY FOR RESOURCE! Check server.lua in ' .. GetCurrentResourceName() .. ' for money events. The current value is set to ' .. framework .. ', and this is not a valid selection.' )
|
|
end
|
|
end)
|
|
|
|
RegisterNetEvent('BigDaddy-Jobs-BusDriver:GetPaid', function(amount, toPlayerId)
|
|
local src = source
|
|
|
|
if framework == 'nat' then
|
|
local account = exports.money:getaccount(src)
|
|
if (tonumber(account.bank) >= tonumber(amount)) then
|
|
local newbalance = tonumber(account.bank) - tonumber(amount)
|
|
exports.money:updateaccount(src, {cash = account.amount, bank = newbalance})
|
|
exports.money:bankNotify(src, 'Bus Driver Pay' .. ' ' .. currencySymbol .. amount )
|
|
end
|
|
elseif framework == 'qb' then
|
|
local Player = QBCore.Functions.GetPlayer(src)
|
|
if (Player.Functions.GetMoney(bank) >= tonumber(amount)) then
|
|
Player.Functions.RemoveMoney('bank', tonumber(amount), 'Bus Driver Pay')
|
|
if (useSociety) then
|
|
exports['qb-management']:AddMoney(toSocietyaccount, tonumber(amount))
|
|
end
|
|
TriggerClientEvent('QBCore:Notify', src, reason, 'primary', 5000)
|
|
end
|
|
elseif framework == 'esx' then
|
|
local xPlayer = ESX.GetPlayerFromId(src)
|
|
if (xPlayer.getAccount("bank") >= tonumber(amount)) then
|
|
xPlayer.removeAccountMoney('bank', tonumber(amount))
|
|
xPlayer.showNotification('Bus Driver Pay')
|
|
end
|
|
elseif framework == 'nd' then
|
|
local Player = NDCore.Functions.GetPlayer(src)
|
|
if (Player.bank >= amount) then
|
|
NDCore.Functions.DeductMoney(amount, src, 'bank', 'Bus Driver Pay')
|
|
end
|
|
elseif framework == 'bigdaddy' then
|
|
if toPlayerId > -1 then
|
|
local toaccount = exports['BigDaddy-Money']:GetAccounts(toPlayerId, toPlayerId, -1)
|
|
local todata = json.decode(toaccount)
|
|
local newtobalance = tonumber(todata.bank) + tonumber(amount)
|
|
exports['BigDaddy-Money']:UpdateTotals(toPlayerId, newtobalance, todata.cash, todata.dirty, -1)
|
|
TriggerClientEvent("BigDaddy-Money:Notify", toPlayerId, 'Received ' .. currencySymbol .. string.format("%.2f", amount) .. ' ' .. 'Bus Driver Pay')
|
|
end
|
|
elseif framework == 'custom' then
|
|
--INSERT CUSTOM CODE HERE FOR CASH MANAGEMENT
|
|
else
|
|
print('FRAMEWORK IS NOT SET PROPERLY FOR RESOURCE! Check server.lua in ' .. GetCurrentResourceName() .. ' for money events. The current value is set to ' .. framework .. ', and this is not a valid selection.' )
|
|
end
|
|
end)
|