Files
Elite-Gaming-FiveM/resources/BigDaddy-Trains/server.lua
T
2025-08-14 13:35:16 -07:00

207 lines
9.8 KiB
Lua

framework = 'bigdaddy' --VALUES CAN BE 'nat', 'qb', 'esx', 'nd', 'bigdaddy' or 'custom'
reason = 'Train Ticket Purchase' --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-Trains: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.bank) - tonumber(amount)
exports.money:updateaccount(src, {cash = account.amount, bank = newbalance})
exports.money:bankNotify(src, reason .. ' ' .. 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), reason)
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(reason)
end
elseif framework == 'nd' then
local Player = NDCore.Functions.GetPlayer(src)
if (Player.bank >= amount) then
NDCore.Functions.DeductMoney(amount, src, 'bank', reason)
end
elseif framework == 'bigdaddy' then
local account = exports['BigDaddy-Money']:GetAccounts(src, playerId, -1)
local data = json.decode(account)
if (tonumber(data.bank) >= tonumber(amount)) then
local newbalance = tonumber(data.bank) - tonumber(amount)
exports['BigDaddy-Money']:UpdateTotals(src, newbalance, data.cash, data.dirty, -1)
TriggerClientEvent("BigDaddy-Money:Notify", src, 'Paid ' .. currencySymbol .. string.format("%.2f", amount) .. ' ' .. reason)
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-Trains:PayTo', function(amount, playerId, 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, reason .. ' ' .. 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), reason)
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(reason)
end
elseif framework == 'nd' then
local Player = NDCore.Functions.GetPlayer(src)
if (Player.bank >= amount) then
NDCore.Functions.DeductMoney(amount, src, 'bank', reason)
end
elseif framework == 'bigdaddy' then
local account = exports['BigDaddy-Money']:GetAccounts(src, playerId, -1)
local data = json.decode(account)
if (tonumber(data.bank) >= tonumber(amount)) then
local newbalance = tonumber(data.bank) - tonumber(amount)
exports['BigDaddy-Money']:UpdateTotals(src, newbalance, data.cash, data.dirty, -1)
TriggerClientEvent("BigDaddy-Money:Notify", src, 'Paid ' .. currencySymbol .. string.format("%.2f", amount) .. ' ' .. reason)
end
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) .. ' ' .. reason)
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-Trains: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, reason .. ' ' .. 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), reason)
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(reason)
end
elseif framework == 'nd' then
local Player = NDCore.Functions.GetPlayer(src)
if (Player.bank >= amount) then
NDCore.Functions.DeductMoney(amount, src, 'bank', reason)
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) .. ' ' .. reason)
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)
RegisterServerEvent('BigDaddy-Trains:GetAccounts')
AddEventHandler('BigDaddy-Trains:GetAccounts', function()
local src = source
if framework == 'nat' then
local account = exports.money:getaccount(src)
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, tonumber(account.bank));
elseif framework == 'qb' then
local Player = QBCore.Functions.GetPlayer(src)
if Player ~= nil then
local money = Player.Functions.GetMoney(bank)
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, money);
else
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, 0);
end
elseif framework == 'esx' then
local xPlayer = ESX.GetPlayerFromId(src)
if xPlayer ~= nil then
local money = xPlayer.getAccount('bank').money
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, money);
else
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, 0);
end
elseif framework == 'nd' then
local Player = NDCore.Functions.GetPlayer(src)
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, Player.bank);
elseif framework == 'bigdaddy' then
local account = exports['BigDaddy-Money']:GetAccounts(src, playerId, -1)
local data = json.decode(account)
TriggerClientEvent("BigDaddy-Trains:SetAccounts", src, data.bank);
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)