1
0
Fork 0
forked from Simnation/Main

Update server.lua

This commit is contained in:
Nordi98 2025-06-29 07:25:16 +02:00
parent 51d9f2d06e
commit dc47213f4b

View file

@ -616,6 +616,68 @@ AddEventHandler("okokBanking:DepositMoneyToSociety", function(amount, society, s
end end
end) end)
RegisterServerEvent("okokBanking:DepositMoneyToSociety")
AddEventHandler("okokBanking:DepositMoneyToSociety", function(amount, society, societyName)
local _source = source
local xPlayer = QBCore.Functions.GetPlayer(_source)
local playerMoney = xPlayer.PlayerData.money.cash
local itemCash = xPlayer.Functions.GetItemByName("cash")
local playerMoneyCash = 0
if itemCash ~= nil then
playerMoneyCash = itemCash.amount
end
if amount <= playerMoney and not Config.UseCashAsItem or amount <= playerMoneyCash and Config.UseCashAsItem then
if Config.UseQBManagement then
exports['qb-management']:AddMoney(society, amount)
elseif Config.UseQBBanking then
-- Direct database update for qb-banking since export isn't available
MySQL.query('UPDATE bank_accounts SET account_balance = account_balance + @amount WHERE account_name = @society', {
['@amount'] = amount,
['@society'] = society,
}, function(changed)
print("Updated bank account for " .. society .. " with amount " .. amount)
end)
else
MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE society = @society AND society_name = @society_name', {
['@value'] = amount,
['@society'] = society,
['@society_name'] = societyName,
}, function(changed)
end)
end
if Config.UseCashAsItem then
xPlayer.Functions.RemoveItem('cash', amount)
else
xPlayer.Functions.RemoveMoney('cash', amount)
end
xPlayer = QBCore.Functions.GetPlayer(_source)
local itemCashUpdated = xPlayer.Functions.GetItemByName("cash")
local playerMoneyCashUpdated = 0
if itemCashUpdated ~= nil then
playerMoneyCashUpdated = itemCashUpdated.amount
end
TriggerEvent('okokBanking:AddDepositTransactionToSociety', amount, _source, society, societyName)
if Config.UseCashAsItem then
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerMoneyCashUpdated)
else
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash)
end
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('deposited_to').title, interp(_L('deposited_to').text, {s1 = amount, s2 = societyName}), _L('deposited_to').time, _L('deposited_to').type)
else
TriggerClientEvent('QBCore:Notify', _source, interp(_L('deposited_to').text, {s1 = amount, s2 = societyName}), _L('deposited_to').type)
end
TransferMoneyWebhook({sender_name = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname, receiver_name = societyName..' ('..society..')', value = amount})
else
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('no_money_pocket').title, _L('no_money_pocket').text, _L('no_money_pocket').time, _L('no_money_pocket').type)
else
TriggerClientEvent('QBCore:Notify', _source, _L('no_money_pocket').text, _L('no_money_pocket').type)
end
end
end)
RegisterServerEvent("okokBanking:WithdrawMoneyToSociety") RegisterServerEvent("okokBanking:WithdrawMoneyToSociety")
AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society, societyName, societyMoney) AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society, societyName, societyMoney)
@ -624,16 +686,7 @@ AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society,
local db local db
local hasChecked = false local hasChecked = false
if Config.UseQBManagement or Config.UseQBBanking then if Config.UseQBManagement then
if Config.UseQBBanking then
MySQL.Async.fetchAll('SELECT * FROM bank_accounts WHERE account_name = @account_name', {
['@account_name'] = society,
}, function(result)
db = result[1]
hasChecked = true
db.value = db.account_balance
end)
else
MySQL.Async.fetchAll('SELECT * FROM management_funds WHERE job_name = @job_name', { MySQL.Async.fetchAll('SELECT * FROM management_funds WHERE job_name = @job_name', {
['@job_name'] = society, ['@job_name'] = society,
}, function(result) }, function(result)
@ -641,7 +694,14 @@ AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society,
hasChecked = true hasChecked = true
db.value = db.amount db.value = db.amount
end) end)
end elseif Config.UseQBBanking then
MySQL.Async.fetchAll('SELECT * FROM bank_accounts WHERE account_name = @account_name', {
['@account_name'] = society,
}, function(result)
db = result[1]
hasChecked = true
db.value = db.account_balance
end)
else else
MySQL.query('SELECT * FROM okokbanking_societies WHERE society = @society', { MySQL.query('SELECT * FROM okokbanking_societies WHERE society = @society', {
['@society'] = society ['@society'] = society
@ -672,12 +732,131 @@ AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society,
TriggerClientEvent('QBCore:Notify', _source, _L('someone_withdrawing').text, _L('someone_withdrawing').type) TriggerClientEvent('QBCore:Notify', _source, _L('someone_withdrawing').text, _L('someone_withdrawing').type)
end end
else else
if Config.UseQBManagement or Config.UseQBBanking then if Config.UseQBManagement then
if Config.UseQBBanking then
exports['qb-banking']:RemoveMoney(society, amount)
else
exports['qb-management']:RemoveMoney(society, amount) exports['qb-management']:RemoveMoney(society, amount)
elseif Config.UseQBBanking then
-- Direct database update for qb-banking since export isn't available
MySQL.query('UPDATE bank_accounts SET account_balance = account_balance - @amount WHERE account_name = @society', {
['@amount'] = amount,
['@society'] = society,
}, function(changed)
print("Updated bank account for " .. society .. " with withdrawal of " .. amount)
end)
else
MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', {
['@value'] = amount,
['@society'] = society,
['@society_name'] = societyName,
}, function(changed)
end)
end end
if Config.UseCashAsItem then
xPlayer.Functions.AddItem('cash', amount)
else
xPlayer.Functions.AddMoney('cash', amount)
end
xPlayer = QBCore.Functions.GetPlayer(_source)
local itemCash = xPlayer.Functions.GetItemByName("cash")
local PlayerCashMoney = 0
if itemCash ~= nil then
PlayerCashMoney = itemCash.amount
end
TriggerEvent('okokBanking:AddWithdrawTransactionToSociety', amount, _source, society, societyName)
if Config.UseCashAsItem then
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, PlayerCashMoney)
else
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash)
end
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('you_have_withdrawn').title, interp(_L('you_have_withdrawn').text, {s1 = amount, s2 = societyName}), _L('you_have_withdrawn').time, _L('you_have_withdrawn').type)
else
TriggerClientEvent('QBCore:Notify', _source, interp(_L('you_have_withdrawn').text, {s1 = amount, s2 = societyName}), _L('you_have_withdrawn').type)
end
TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname, value = amount})
end
else
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('society_no_money').title, _L('society_no_money').text, _L('society_no_money').time, _L('society_no_money').type)
else
TriggerClientEvent('QBCore:Notify', _source, _L('society_no_money').text, _L('society_no_money').type)
end
end
if not Config.UseQBManagement then
MySQL.query('UPDATE okokbanking_societies SET is_withdrawing = 0 WHERE society = @society AND society_name = @society_name', {
['@value'] = amount,
['@society'] = society,
['@society_name'] = societyName,
}, function(changed)
end)
end
end)
RegisterServerEvent("okokBanking:WithdrawMoneyToSociety")
AddEventHandler("okokBanking:WithdrawMoneyToSociety", function(amount, society, societyName, societyMoney)
local _source = source
local xPlayer = QBCore.Functions.GetPlayer(_source)
local db
local hasChecked = false
if Config.UseQBManagement then
MySQL.Async.fetchAll('SELECT * FROM management_funds WHERE job_name = @job_name', {
['@job_name'] = society,
}, function(result)
db = result[1]
hasChecked = true
db.value = db.amount
end)
elseif Config.UseQBBanking then
MySQL.Async.fetchAll('SELECT * FROM bank_accounts WHERE account_name = @account_name', {
['@account_name'] = society,
}, function(result)
db = result[1]
hasChecked = true
db.value = db.account_balance
end)
else
MySQL.query('SELECT * FROM okokbanking_societies WHERE society = @society', {
['@society'] = society
}, function(result)
db = result[1]
hasChecked = true
end)
end
if not Config.UseQBManagement then
MySQL.query('UPDATE okokbanking_societies SET is_withdrawing = 1 WHERE society = @society AND society_name = @society_name', {
['@value'] = amount,
['@society'] = society,
['@society_name'] = societyName,
}, function(changed)
end)
end
while not hasChecked do
Citizen.Wait(100)
end
if amount <= db.value then
if db.is_withdrawing == 1 then
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('someone_withdrawing').title, _L('someone_withdrawing').text, _L('someone_withdrawing').time, _L('someone_withdrawing').type)
else
TriggerClientEvent('QBCore:Notify', _source, _L('someone_withdrawing').text, _L('someone_withdrawing').type)
end
else
if Config.UseQBManagement then
exports['qb-management']:RemoveMoney(society, amount)
elseif Config.UseQBBanking then
-- Direct database update for qb-banking since export isn't available
MySQL.query('UPDATE bank_accounts SET account_balance = account_balance - @amount WHERE account_name = @society', {
['@amount'] = amount,
['@society'] = society,
}, function(changed)
print("Updated bank account for " .. society .. " with withdrawal of " .. amount)
end)
else else
MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', { MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', {
['@value'] = amount, ['@value'] = amount,
@ -736,12 +915,16 @@ AddEventHandler("okokBanking:TransferMoneyToSociety", function(amount, ibanNumbe
local playerMoney = xPlayer.PlayerData.money.bank local playerMoney = xPlayer.PlayerData.money.bank
if amount <= playerMoney then if amount <= playerMoney then
if Config.UseQBManagement or Config.UseQBBanking then if Config.UseQBManagement then
if Config.UseQBBanking then exports['qb-management']:AddMoney(society, amount)
exports['qb-banking']:AddMoney(society, amount) elseif Config.UseQBBanking then
else -- Direct database update for qb-banking since export isn't available
exports['qb-management']:TransferMoney(society, amount, ibanNumber) MySQL.query('UPDATE bank_accounts SET account_balance = account_balance + @amount WHERE account_name = @society', {
end ['@amount'] = amount,
['@society'] = society,
}, function(changed)
print("Updated bank account for " .. society .. " with transfer of " .. amount)
end)
else else
MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE iban = @iban', { MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE iban = @iban', {
['@value'] = amount, ['@value'] = amount,
@ -782,6 +965,7 @@ AddEventHandler("okokBanking:TransferMoneyToSociety", function(amount, ibanNumbe
end end
end) end)
function getSocietyInfo(society, iban) function getSocietyInfo(society, iban)
local done = false local done = false
local societyInfo = nil local societyInfo = nil
@ -870,62 +1054,156 @@ function getSocietyInfo(society, iban)
return societyInfo return societyInfo
end end
RegisterServerEvent("okokBanking:TransferMoneyToSocietyFromSociety") RegisterServerEvent("okokBanking:TransferMoneyToSociety")
AddEventHandler("okokBanking:TransferMoneyToSocietyFromSociety", function(amount, ibanNumber, societyNameTarget, societyTarget, society, societyName, societyMoney) AddEventHandler("okokBanking:TransferMoneyToSociety", function(amount, ibanNumber, societyName, society)
local _source = source local _source = source
local xPlayer = QBCore.Functions.GetPlayer(_source) local xPlayer = QBCore.Functions.GetPlayer(_source)
local playerJob = xPlayer.PlayerData.job.name local playerMoney = xPlayer.PlayerData.money.bank
if society ~= playerJob then if amount <= playerMoney then
return if Config.UseQBManagement then
exports['qb-management']:AddMoney(society, amount)
elseif Config.UseQBBanking then
-- Direct database update for qb-banking since export isn't available
MySQL.query('UPDATE bank_accounts SET account_balance = account_balance + @amount WHERE account_name = @society', {
['@amount'] = amount,
['@society'] = society,
}, function(changed)
print("Updated bank account for " .. society .. " with transfer of " .. amount)
end)
else
MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE iban = @iban', {
['@value'] = amount,
['@iban'] = ibanNumber
}, function(changed)
end)
end end
xPlayer.Functions.RemoveMoney('bank', amount)
xPlayer = QBCore.Functions.GetPlayer(_source)
local itemCash = xPlayer.Functions.GetItemByName("cash")
local playerCashMoney = 0
if itemCash ~= nil then
playerCashMoney = itemCash.amount
end
TriggerEvent('okokBanking:AddTransferTransactionToSociety', amount, _source, society, societyName)
if Config.UseCashAsItem then
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney)
TriggerClientEvent('okokBanking:updateTransactions', _source, xPlayer.PlayerData.money.bank, playerCashMoney)
TriggerClientEvent('okokBanking:updateMoney', _source, xPlayer.PlayerData.money.bank, playerCashMoney)
else
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash)
TriggerClientEvent('okokBanking:updateTransactions', _source, xPlayer.PlayerData.money.bank, xPlayer.PlayerData.money.cash)
TriggerClientEvent('okokBanking:updateMoney', _source, xPlayer.PlayerData.money.bank, xPlayer.PlayerData.money.cash)
end
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = societyName}), _L('transferred_to').time, _L('transferred_to').type)
else
TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = societyName}), _L('transferred_to').type)
end
TransferMoneyWebhook({sender_name = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname, receiver_name = societyName..' ('..society..')', value = amount})
else
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('no_money_bank').title, _L('no_money_bank').text, _L('no_money_bank').time, _L('no_money_bank').type)
else
TriggerClientEvent('QBCore:Notify', _source, _L('no_money_bank').text, _L('no_money_bank').type)
end
end
end)
RegisterServerEvent("okokBanking:TransferMoneyToPlayerFromSociety")
AddEventHandler("okokBanking:TransferMoneyToPlayerFromSociety", function(amount, ibanNumber, targetIdentifier, acc, targetName, society, societyName, societyMoney, toMyself)
local _source = source
local xPlayer = QBCore.Functions.GetPlayer(_source)
local itemCash = xPlayer.Functions.GetItemByName("cash") local itemCash = xPlayer.Functions.GetItemByName("cash")
local playerCashMoney = 0 local playerCashMoney = 0
if itemCash ~= nil then if itemCash ~= nil then
playerCashMoney = itemCash.amount playerCashMoney = itemCash.amount
end end
local xTarget = QBCore.Functions.GetPlayerByCitizenId(targetIdentifier) local xTarget = QBCore.Functions.GetPlayerByCitizenId(targetIdentifier)
local itemCashTarget = xTarget and xTarget.Functions.GetItemByName("cash")
local playerCashMoneyTarget = 0
if itemCashTarget ~= nil then
playerCashMoneyTarget = itemCashTarget.amount
end
local xPlayers = QBCore.Functions.GetPlayers() local xPlayers = QBCore.Functions.GetPlayers()
local societyInfo = getSocietyInfo(society, ibanNumber) if amount <= societyMoney then
if Config.UseQBManagement then
if amount <= societyInfo.value then
if Config.UseQBManagement or Config.UseQBBanking then
if Config.UseQBBanking then
exports['qb-banking']:RemoveMoney(society, amount)
exports['qb-banking']:AddMoney(societyTarget, amount)
else
exports['qb-management']:AddMoney(societyTarget, amount)
exports['qb-management']:RemoveMoney(society, amount) exports['qb-management']:RemoveMoney(society, amount)
end elseif Config.UseQBBanking then
-- Direct database update for qb-banking since export isn't available
MySQL.query('UPDATE bank_accounts SET account_balance = account_balance - @amount WHERE account_name = @society', {
['@amount'] = amount,
['@society'] = society,
}, function(changed)
print("Updated bank account for " .. society .. " with withdrawal of " .. amount)
end)
else else
MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', { MySQL.query('UPDATE okokbanking_societies SET value = value - @value WHERE society = @society AND society_name = @society_name', {
['@value'] = amount, ['@value'] = amount,
['@society'] = society, ['@society'] = society,
['@society_name'] = societyName, ['@society_name'] = societyName,
}, function(changed) }, function(changed)
MySQL.query('UPDATE okokbanking_societies SET value = value + @value WHERE society = @society AND society_name = @society_name', {
['@value'] = amount,
['@society'] = societyTarget,
['@society_name'] = societyNameTarget,
}, function(changed)
end)
end) end)
end end
if xTarget ~= nil then
TriggerEvent('okokBanking:AddTransferTransactionFromSociety', amount, society, societyName, societyTarget, societyNameTarget) xTarget.Functions.AddMoney('bank', amount)
if not toMyself then
for i=1, #xPlayers, 1 do
local xForPlayer = QBCore.Functions.GetPlayer(xPlayers[i])
if xForPlayer.PlayerData.citizenid == targetIdentifier then
if Config.UseCashAsItem then
TriggerClientEvent('okokBanking:updateTransactions', xPlayers[i], xTarget.PlayerData.money.bank, playerCashMoneyTarget)
else
TriggerClientEvent('okokBanking:updateTransactions', xPlayers[i], xTarget.PlayerData.money.bank, xTarget.PlayerData.money.cash)
end
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', xPlayers[i], _L('received_from').title, interp(_L('received_from').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('received_from').time, _L('received_from').type)
else
TriggerClientEvent('QBCore:Notify', xPlayers[i], interp(_L('received_from').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('received_from').type)
end
end
end
end
TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', amount, society, societyName, targetIdentifier, targetName)
if Config.UseCashAsItem then if Config.UseCashAsItem then
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney) TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney)
else else
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash) TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash)
end end
if Config.okokNotify then if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = societyNameTarget}), _L('transferred_to').time, _L('transferred_to').type) TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('transferred_to').time, _L('transferred_to').type)
else else
TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = societyNameTarget}), _L('transferred_to').type) TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = xPlayer.PlayerData.charinfo.firstname..' '..xPlayer.PlayerData.charinfo.lastname}), _L('transferred_to').type)
end
TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = xTarget.PlayerData.charinfo.firstname..' '..xTarget.PlayerData.charinfo.lastname, value = amount})
elseif xTarget == nil then
local playerAccount = json.decode(acc)
playerAccount.bank = playerAccount.bank + amount
playerAccount = json.encode(playerAccount)
TriggerEvent('okokBanking:AddTransferTransactionFromSocietyToP', amount, society, societyName, targetIdentifier, targetName)
if Config.UseCashAsItem then
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, playerCashMoney)
else
TriggerClientEvent('okokBanking:updateTransactionsSociety', _source, xPlayer.PlayerData.money.cash)
end
if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('transferred_to').title, interp(_L('transferred_to').text, {s1 = amount, s2 = targetName }), _L('transferred_to').time, _L('transferred_to').type)
else
TriggerClientEvent('QBCore:Notify', _source, interp(_L('transferred_to').text, {s1 = amount, s2 = targetName }), _L('transferred_to').type)
end
TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = targetName..' (Offline User)', value = amount})
MySQL.query('UPDATE players SET money = @playerAccount WHERE citizenid = @target', {
['@playerAccount'] = playerAccount,
['@target'] = targetIdentifier
}, function(changed)
end)
end end
TransferMoneyWebhook({sender_name = societyName..' ('..society..')', receiver_name = societyNameTarget..' ('..societyTarget..')', value = amount})
else else
if Config.okokNotify then if Config.okokNotify then
TriggerClientEvent('okokNotify:Alert', _source, _L('society_no_money').title, _L('society_no_money').text, _L('society_no_money').time, _L('society_no_money').type) TriggerClientEvent('okokNotify:Alert', _source, _L('society_no_money').title, _L('society_no_money').text, _L('society_no_money').time, _L('society_no_money').type)
@ -935,6 +1213,9 @@ AddEventHandler("okokBanking:TransferMoneyToSocietyFromSociety", function(amount
end end
end) end)
RegisterServerEvent("okokBanking:TransferMoneyToPlayerFromSociety") RegisterServerEvent("okokBanking:TransferMoneyToPlayerFromSociety")
AddEventHandler("okokBanking:TransferMoneyToPlayerFromSociety", function(amount, ibanNumber, targetIdentifier, acc, targetName, society, societyName, societyMoney, toMyself) AddEventHandler("okokBanking:TransferMoneyToPlayerFromSociety", function(amount, ibanNumber, targetIdentifier, acc, targetName, society, societyName, societyMoney, toMyself)
local _source = source local _source = source