88 lines
4.0 KiB
Lua
88 lines
4.0 KiB
Lua
|
|
framework = 'bigdaddy' --VALUES CAN BE 'nat', 'qb', 'esx', 'nd', 'bigdaddy' or 'custom'
|
|
|
|
reason = 'Vending Machine' --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-VendingMachines: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-VendingMachines:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, false)
|
|
end
|
|
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)
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, false)
|
|
end
|
|
elseif framework == 'esx' then
|
|
local xPlayer = ESX.GetPlayerFromId(src)
|
|
local account = xPlayer.getAccount('cash')
|
|
if (account.money >= tonumber(amount)) then
|
|
xPlayer.removeAccountMoney('cash', tonumber(amount))
|
|
xPlayer.showNotification(reason)
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, false)
|
|
end
|
|
elseif framework == 'nd' then
|
|
local Player = NDCore:getPlayer(src)
|
|
if (Player.cash >= amount) then
|
|
Player.DeductMoney('cash', amount, reason)
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, false)
|
|
end
|
|
elseif framework == 'bigdaddy' then
|
|
local account = exports['BigDaddy-Money']:GetAccounts(src, playerId, -1)
|
|
local data = json.decode(account)
|
|
if (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) .. ' in cash ' .. reason)
|
|
TriggerClientEvent('BigDaddy-VendingMachines:IsPaid', src, true)
|
|
else
|
|
TriggerClientEvent('BigDaddy-VendingMachines: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)
|
|
|
|
|