Files
jim-payments/server/atmserver.lua

267 lines
12 KiB
Lua
Raw Permalink Normal View History

onResourceStart(function()
registerCommand("cashgive", {
locale("command" , "pay_user"), {}, false,
function(source)
TriggerClientEvent(getScript()..":client:ATM:give", source)
end
})
createCallback(getScript()..":GetInfo", function(source)
local Player = getPlayer(source)
local society, gsociety = 0, 0
society = getSocietyAccount(Player.job)
if Player.gang ~= "none" then
gsociety = getSocietyAccount(Player.gang)
end
-- Savings account is only QBCore for now
if isStarted(QBExport) and not isStarted(QBXExport) then
-- Grab Savings account info
local result = MySQL.Sync.fetchAll('SELECT * FROM bank_accounts WHERE citizenid = ? AND account_name = ?', { Player.citizenId, 'Savings_'..Player.citizenId, })
if result[1] then
accountID = result[1].citizenid
savingBalance = result[1].account_balance
else
MySQL.Async.insert('INSERT INTO bank_accounts (citizenid, account_name, account_balance) VALUES (?, ?, ?)', { Player.citizenId, 'Savings_'..Player.citizenId, 0}, function() completed = true end) repeat Wait(0) until completed == true
local result = MySQL.Sync.fetchAll('SELECT * FROM bank_accounts WHERE citizenid = ? AND account_name = ?', { Player.citizenId, 'Savings_'..Player.citizenId, })
accountID = result[1].citizenid
savingBalance = result[1].account_balance
end
end
local retTable = {
name = Player.firstname..' '..Player.lastname,
cash = Player.cash,
bank = Player.bank,
account = Player.account,
cid = Player.citizenId.." ["..source.."]",
savbal = savingBalance,
aid = accountID,
society = society,
gsociety = gsociety
}
2025-02-21 13:54:49 +00:00
return retTable
end)
end, true)
2025-02-22 13:23:43 +00:00
2025-02-21 13:54:49 +00:00
RegisterServerEvent(getScript()..":server:ATM:use", function(amount, billtype, baccount, account, society, gsociety)
2022-08-22 21:32:15 +01:00
local src = source
2025-02-21 13:54:49 +00:00
local Player = getPlayer(src)
2022-08-22 21:32:15 +01:00
local amount = tonumber(amount)
2025-02-21 13:54:49 +00:00
local bankScript, newAmount = "", 0
2022-08-22 21:32:15 +01:00
--Simple transfers from bank to wallet --
if account == "bank" or account == "atm" then
if billtype == "withdraw" then
2025-02-21 13:54:49 +00:00
if Player.bank < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"bank_low"), "error", src)
2025-02-21 13:54:49 +00:00
elseif Player.bank >= tonumber(amount) then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"draw")..cv(amount)..locale("success" ,"from_bank"), "success") -- Don't really need this as phone gets notified when money is withdrawn
2025-02-21 13:54:49 +00:00
chargePlayer(amount, "bank", src) Wait(1500)
fundPlayer(amount, "cash", src)
2022-08-22 21:32:15 +01:00
end
elseif billtype == "deposit" then
2025-02-21 13:54:49 +00:00
if Player.cash < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"no_cash"), "error", src)
2025-02-21 13:54:49 +00:00
elseif Player.cash >= amount then
chargePlayer(amount, "cash", src) Wait(1500)
fundPlayer(amount, "bank", src)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"deposited")..cv(amount)..locale("success" ,"into_bank"), "success", src)
2022-08-22 21:32:15 +01:00
end
end
-- Transfers from bank to savings account --
elseif account == "savings" then
2025-02-21 13:54:49 +00:00
local getSavingsAccount = MySQL.Sync.fetchAll('SELECT * FROM bank_accounts WHERE citizenid = ? AND account_name = ?', { Player.citizenId, 'Savings_'..Player.citizenId, })
2024-01-07 02:37:55 -05:00
if getSavingsAccount[1] ~= nil then savbal = tonumber(getSavingsAccount[1].account_balance) aid = getSavingsAccount[1].citizenid end
2022-08-22 21:32:15 +01:00
if billtype == "withdraw" then
if savbal >= amount then
savbal -= amount
2025-02-21 13:54:49 +00:00
fundPlayer(amount, "cash", src)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, "$"..cv(amount)..locale("success" ,"draw_save"), "success", src)
MySQL.Async.execute('UPDATE bank_accounts SET account_balance = ? WHERE citizenid = ?', { savbal, Player.citizenId }, function(success)
2022-08-22 21:32:15 +01:00
if success then return true else return false end
end)
elseif savbal < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"saving_low"), "error")
2022-08-22 21:32:15 +01:00
end
elseif billtype == "deposit" then
2025-02-21 13:54:49 +00:00
if amount < Player.bank then
savbal += amount
2025-02-21 13:54:49 +00:00
chargePlayer(amount, "bank", src)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, "$"..cv(amount)..locale("success", "depos_save"), "success", src)
2025-02-21 13:54:49 +00:00
MySQL.Async.execute('UPDATE bank_accounts SET account_balance = ? WHERE citizenid = ?', { savbal, Player.citizenId}, function(success)
2022-08-22 21:32:15 +01:00
if success then return true else return false end
end)
2025-02-22 13:23:43 +00:00
else triggerNotify(nil, locale("error" ,"bank_low"), "error", src)
2022-08-22 21:32:15 +01:00
end
end
--Simple transfers from society account to bank --
elseif account == "society" then
if billtype == "withdraw" then
2025-02-21 13:54:49 +00:00
if tonumber(society) < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"soc_low"), "error", src)
2022-08-22 21:32:15 +01:00
elseif tonumber(society) >= amount then
2025-02-21 13:54:49 +00:00
chargeSociety(Player.job, amount)
2025-02-21 13:54:49 +00:00
fundPlayer(amount, "bank", src)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success", "draw")..cv(amount)..locale("success", "fromthe")..Jobs[Player.job].label..locale("success" ,"account"), "success", src)
2022-08-22 21:32:15 +01:00
end
elseif billtype == "deposit" then
2025-02-22 13:23:43 +00:00
if Player.bank < amount then triggerNotify(nil, locale("error", "nomoney_bank"), "error", src)
2025-02-21 13:54:49 +00:00
elseif Player.bank >= amount then
fundSociety(Player.job, amount)
2025-02-21 13:54:49 +00:00
chargePlayer(amount, "bank", src) Wait(1500)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success", "deposited")..cv(amount)..locale("success", "into")..Jobs[Player.job].label..locale("success", "account"), "success", src)
2022-08-22 21:32:15 +01:00
end
end
-- Transfer from boss account to players --
2025-02-21 13:54:49 +00:00
--[[ disabled until i work out a system for other frameworks
2022-08-22 21:32:15 +01:00
elseif account == "societytransfer" then
local bannedCharacters = {'%','$',';'}
local newAmount = tostring(amount)
local newiban = tostring(baccount)
for _, v in pairs(bannedCharacters) do
newAmount = string.gsub(newAmount, '%' .. v, '')
newiban = string.gsub(newiban, '%' .. v, '')
end
baccount = newiban
amount = tonumber(newAmount)
2024-01-27 21:57:05 +00:00
local Player = Core.Functions.GetPlayer(src)
2022-08-22 21:32:15 +01:00
if (society - amount) >= 0 then
local query = '%"account":"' .. baccount .. '"%'
local result = MySQL.Sync.fetchAll('SELECT * FROM players WHERE charinfo LIKE ?', {query})
if result[1] then
2024-01-27 21:57:05 +00:00
local Reciever = Core.Functions.GetPlayerByCitizenId(result[1].citizenid)
2025-02-21 13:54:49 +00:00
if Config.Banking == "renewed" then
exports['Renewed-Banking']:removeAccountMoney(tostring(Player.PlayerData.job.name), amount)
elseif Config.Banking == "qb-management" then
exports["qb-management"]:RemoveMoney(tostring(Player.PlayerData.job.name), amount)
elseif Config.Banking == "qb-banking" then
exports["qb-banking"]:RemoveMoney(tostring(Player.PlayerData.job.name), amount)
elseif Config.Banking == "fd" then
exports.fd_banking:RemoveMoney(tostring(Player.PlayerData.job.name), amount)
end
2022-08-22 21:32:15 +01:00
if Reciever then
Reciever.Functions.AddMoney('bank', amount)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"sent"]..amount..locale("success" ,"to"]..Reciever.PlayerData.charinfo.firstname.." "..Reciever.PlayerData.charinfo.lastname, "success", src)
triggerNotify(nil, locale("success" ,"recieved"]..cv(amount)..locale("success" ,"from"]..tostring(Player.PlayerData.job.label)..locale("success" ,"account"], "success", Reciever.PlayerData.source)
2022-08-22 21:32:15 +01:00
else
local RecieverMoney = json.decode(result[1].money)
RecieverMoney.bank += amount
2022-08-22 21:32:15 +01:00
MySQL.Async.execute('UPDATE players SET money = ? WHERE citizenid = ?', {json.encode(RecieverMoney), result[1].citizenid})
end
2025-02-22 13:23:43 +00:00
elseif not result[1] then triggerNotify(nil, locale("error" ,"error_start"]..baccount..locale("error" ,"error_end"], "error", src)
2022-08-22 21:32:15 +01:00
end
2025-02-21 13:54:49 +00:00
end]]
2022-08-22 21:32:15 +01:00
--Simple transfers from gang society account to bank --
elseif account == "gang" then
if billtype == "withdraw" then
2025-02-21 13:54:49 +00:00
if tonumber(gsociety) < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"soc_low"), "error", src)
2022-08-22 21:32:15 +01:00
elseif tonumber(gsociety) >= amount then
chargeSociety(Player.gang, amount)
2022-08-22 21:32:15 +01:00
end
2025-02-21 13:54:49 +00:00
fundPlayer(amount, "bank", src)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"draw")..cv(amount)..locale("success" ,"fromthe")..Gangs[Player.gang].label..locale("success" ,"account"), "success", src)
2025-02-21 13:54:49 +00:00
2022-08-22 21:32:15 +01:00
elseif billtype == "deposit" then
2025-02-21 13:54:49 +00:00
if Player.bank < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"nomoney_bank"), "error", src)
2025-02-21 13:54:49 +00:00
elseif Player.bank >= amount then
fundSociety(Player.gang, amount)
chargePlayer(amount, "bank", Player.source) Wait(1500)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"deposited")..cv(amount)..locale("success" ,"into")..Gangs[Player.gang].label..locale("success" ,"account"), "success", src)
2022-08-22 21:32:15 +01:00
end
end
-- Transfer from gang account to players --
elseif account == "gangtransfer" then
local bannedCharacters = {'%','$',';'}
local newAmount = tostring(amount)
local newiban = tostring(baccount)
for _, v in pairs(bannedCharacters) do
newAmount = string.gsub(newAmount, '%' .. v, '')
newiban = string.gsub(newiban, '%' .. v, '')
end
baccount = newiban
amount = tonumber(newAmount)
2024-01-27 21:57:05 +00:00
local Player = Core.Functions.GetPlayer(src)
2022-08-22 21:32:15 +01:00
if (gsociety - amount) >= 0 then
local query = '%"account":"' .. baccount .. '"%'
local result = MySQL.Sync.fetchAll('SELECT * FROM players WHERE charinfo LIKE ?', {query})
if result[1] then
2024-01-27 21:57:05 +00:00
local Reciever = Core.Functions.GetPlayerByCitizenId(result[1].citizenid)
chargeSociety(Player.PlayerData.gang.nameg, amount)
2022-08-22 21:32:15 +01:00
if not Reciever then
Reciever.Functions.AddMoney('bank', amount)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"sent")..amount..locale("success" ,"to")..Reciever.PlayerData.charinfo.firstname.." "..Reciever.PlayerData.charinfo.lastname, "success", src)
triggerNotify(nil, Reciever.PlayerData.source, locale("success" ,"recieved")..cv(amount)..locale("success" ,"from")..tostring(Player.PlayerData.gang.label)..locale("success" ,"account"), "success", Reciever.PlayerData.source)
2022-08-22 21:32:15 +01:00
else
local RecieverMoney = json.decode(result[1].money)
RecieverMoney.bank += amount
2022-08-22 21:32:15 +01:00
MySQL.Async.execute('UPDATE players SET money = ? WHERE citizenid = ?', {json.encode(RecieverMoney), result[1].citizenid})
end
2025-02-22 13:23:43 +00:00
elseif not result[1] then triggerNotify(nil, locale("error" ,"error_start")..baccount..locale("error" ,"error_end"), "error", src)
2022-08-22 21:32:15 +01:00
end
end
elseif account == "transfer" then
local bannedCharacters = {'%','$',';'}
local newAmount = tostring(amount)
local newiban = tostring(baccount)
for _, v in pairs(bannedCharacters) do
newAmount = string.gsub(newAmount, '%' .. v, '')
newiban = string.gsub(newiban, '%' .. v, '')
end
baccount = newiban
amount = tonumber(newAmount)
2024-01-27 21:57:05 +00:00
local Player = Core.Functions.GetPlayer(src)
2022-08-22 21:32:15 +01:00
if (Player.PlayerData.money.bank - amount) >= 0 then
local query = '%"account":"' .. baccount .. '"%'
local result = MySQL.Sync.fetchAll('SELECT * FROM players WHERE charinfo LIKE ?', {query})
if result[1] then
2024-01-27 21:57:05 +00:00
local Reciever = Core.Functions.GetPlayerByCitizenId(result[1].citizenid)
2022-08-22 21:32:15 +01:00
Player.Functions.RemoveMoney('bank', amount)
if Reciever then
Reciever.Functions.AddMoney('bank', amount)
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("success" ,"sent")..cv(amount)..locale("success" ,"to")..Reciever.PlayerData.charinfo.firstname.." "..Reciever.PlayerData.charinfo.lastname, "success", src)
triggerNotify(nil, locale("success" ,"recieved")..cv(amount)..locale("success" ,"from")..Player.PlayerData.charinfo.firstname.." "..Player.PlayerData.charinfo.lastname, "success", Reciever.PlayerData.source)
2022-08-22 21:32:15 +01:00
else
local RecieverMoney = json.decode(result[1].money)
RecieverMoney.bank += amount
2022-08-22 21:32:15 +01:00
MySQL.Async.execute('UPDATE players SET money = ? WHERE citizenid = ?', {json.encode(RecieverMoney), result[1].citizenid})
end
2024-01-07 02:37:55 -05:00
elseif not result[1] then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"error_start")..baccount..locale("error" ,"error_end"), "error", src)
2022-08-22 21:32:15 +01:00
end
end
end
end)
2025-02-21 13:54:49 +00:00
RegisterServerEvent(getScript()..":server:ATM:give", function(citizen, price)
2025-02-22 13:23:43 +00:00
local Player = getPlayer(source)
local Reciever = getPlayer(tonumber(citizen))
2022-08-22 21:32:15 +01:00
local amount = tonumber(price)
2025-02-22 13:23:43 +00:00
local balance = Player.cash
2022-08-22 21:32:15 +01:00
if amount and amount > 0 then
if balance >= amount then
2025-02-22 13:23:43 +00:00
chargePlayer(amount, "cash", source)
triggerNotify(nil, locale("success" ,"you_gave")..Reciever.name.." $"..cv(amount), "success", source)
fundPlayer(amount, "cash", Reciever.source)
triggerNotify(nil, locale("success" ,"you_got")..cv(amount)..locale("success" ,"from")..Player.name, "success", tonumber(citizen))
2022-08-22 21:32:15 +01:00
elseif balance < amount then
2025-02-22 13:23:43 +00:00
triggerNotify(nil, locale("error" ,"not_enough"), "error", source)
2022-08-22 21:32:15 +01:00
end
2025-02-22 13:23:43 +00:00
else triggerNotify(nil, locale("error" ,"zero"), 'error', source) end
2022-09-02 20:04:22 +08:00
end)