From 922d0c5fecd7c1d335bfe4de10674022b3a5030a Mon Sep 17 00:00:00 2001 From: ElPumpo Date: Sun, 8 Jul 2018 15:18:47 +0200 Subject: [PATCH] Implemented paying with bank balance, cleanup --- client/main.lua | 4 +- locales/br.lua | 12 +++--- locales/de.lua | 6 ++- locales/en.lua | 4 +- locales/es.lua | 12 +++--- locales/fi.lua | 2 +- locales/fr.lua | 4 +- locales/sv.lua | 10 ++--- server/main.lua | 108 ++++++++++++++++++++++++++++++++---------------- 9 files changed, 104 insertions(+), 58 deletions(-) diff --git a/client/main.lua b/client/main.lua index 84af3132..e613cf01 100644 --- a/client/main.lua +++ b/client/main.lua @@ -36,7 +36,7 @@ function ShowBillsMenu() 'default', GetCurrentResourceName(), 'billing', { title = _U('invoices'), - align = 'bottom-right', + align = 'bottom-right', elements = elements }, function(data, menu) @@ -63,7 +63,7 @@ end Citizen.CreateThread(function() while true do Citizen.Wait(10) - if IsControlJustReleased(0, Keys["F7"]) and not isDead and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') then + if IsControlJustReleased(0, Keys['F7']) and not isDead and not ESX.UI.Menu.IsOpen('default', GetCurrentResourceName(), 'billing') then ShowBillsMenu() end end diff --git a/locales/br.lua b/locales/br.lua index 6cac8e82..7921cda0 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,7 +1,9 @@ Locales['br'] = { - ['invoices'] = 'Faturas', - ['received_invoice'] = 'Você ~r~recebeu~s~ uma fatura', - ['paid_invoice'] = 'Você ~g~pagou~s~ uma fatura de ~r~$%s~s~', - ['received_payment'] = 'Você ~g~recebeu~s~ um pagamento de ~r~$%s~s~', - ['player_not_logged'] = 'O jogador não está logado', + ['invoices'] = 'faturas', + ['received_invoice'] = 'você ~r~recebeu~s~ uma fatura', + ['paid_invoice'] = 'você ~g~pagou~s~ uma fatura de ~r~$%s~s~', + ['received_payment'] = 'você ~g~recebeu~s~ um pagamento de ~r~$%s~s~', + ['player_not_online'] = 'o jogador não está logado', + ['no_money'] = 'you do not have enough money to pay this bill', + ['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!', } diff --git a/locales/de.lua b/locales/de.lua index 1c55d48b..f7bf1a0d 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -1,7 +1,9 @@ Locales['de'] = { - ['invoices'] = 'Rechnungen', + ['invoices'] = 'rechnungen', ['received_invoice'] = 'you hast eine Rechnung ~r~erhlaten~s~', ['paid_invoice'] = 'du ~g~bezahlst~s~ eine Rechnung von ~r~$%s~s~', ['received_payment'] = 'du ~g~erhältst~s~ eine Zahlung von ~r~$%s~s~', - ['player_not_logged'] = 'der Spieler ist nicht online', + ['player_not_online'] = 'der Spieler ist nicht online', + ['no_money'] = 'you do not have enough money to pay this bill', + ['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!', } diff --git a/locales/en.lua b/locales/en.lua index 220fd265..a2137db9 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -3,7 +3,7 @@ Locales['en'] = { ['received_invoice'] = 'you have just ~r~received~s~ an invoice', ['paid_invoice'] = 'you ~g~paid~s~ an invoice of ~r~$%s~s~', ['received_payment'] = 'you ~g~received~s~ a payment of ~r~$%s~s~', - ['player_not_logged'] = 'the player is not logged in', + ['player_not_online'] = 'the player is not logged in', ['no_money'] = 'you do not have enough money to pay this bill', - ['target_no_money'] = 'the player ~r~does not~w~ have enough money to pay the bill!', + ['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!', } diff --git a/locales/es.lua b/locales/es.lua index 9a21351e..17a232c9 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -1,7 +1,9 @@ Locales['es'] = { - ['invoices'] = 'Facturas', - ['received_invoice'] = 'Has ~r~recibido~s~ una multa', - ['paid_invoice'] = 'Has ~g~pagado~s~ una multa de ~r~€%s~s~', - ['received_payment'] = 'Has ~g~recibido~s~ un pago de ~g~€%s~s~', - ['player_not_logged'] = 'El jugador no está conectado', + ['invoices'] = 'facturas', + ['received_invoice'] = 'has ~r~recibido~s~ una multa', + ['paid_invoice'] = 'has ~g~pagado~s~ una multa de ~r~€%s~s~', + ['received_payment'] = 'has ~g~recibido~s~ un pago de ~g~€%s~s~', + ['player_not_online'] = 'el jugador no está conectado', + ['no_money'] = 'you do not have enough money to pay this bill', + ['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!', } diff --git a/locales/fi.lua b/locales/fi.lua index 150161fa..f4b7820d 100644 --- a/locales/fi.lua +++ b/locales/fi.lua @@ -3,7 +3,7 @@ Locales['fi'] = { ['received_invoice'] = 'sinä ~r~sait~s~ laskun', ['paid_invoice'] = 'sinä ~g~maksoit~s~ laskun suuruudelta ~r~$%s~s~', ['received_payment'] = 'sinä ~g~sait~s~ maksun suuruudelta ~r~$%s~s~', - ['player_not_logged'] = 'pelaaja ei ole sisäänkirjautuneena', + ['player_not_online'] = 'pelaaja ei ole sisäänkirjautuneena', ['no_money'] = 'sinulla ei ole tarpeeksi rahaa maksaaksesi tätä laskua.', ['target_no_money'] = 'pelaajalla ~r~ei ole~w~ tarpeeksi rahaa maksaakseentätä laskua', } diff --git a/locales/fr.lua b/locales/fr.lua index a9113d73..be53d3b2 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -3,5 +3,7 @@ Locales['fr'] = { ['received_invoice'] = 'vous avez ~r~reçu~s~ une facture', ['paid_invoice'] = 'vous avez ~g~payé~s~ une facture de ~r~$%s~s~', ['received_payment'] = 'vous avez ~g~reçu~s~ un paiement de ~g~$%s~s~', - ['player_not_logged'] = 'le joueur n\'est pas connecté', + ['player_not_online'] = 'le joueur n\'est pas connecté', + ['no_money'] = 'you do not have enough money to pay this bill', + ['target_no_money'] = 'the player ~r~does not~s~ have enough money to pay the bill!', } diff --git a/locales/sv.lua b/locales/sv.lua index d661d797..69cad9bc 100644 --- a/locales/sv.lua +++ b/locales/sv.lua @@ -1,9 +1,9 @@ Locales['sv'] = { ['invoices'] = 'räkningar', ['received_invoice'] = 'du har ~y~mottagit~s~ en räkning', - ['paid_invoice'] = 'du ~y~betalade~w~ precis en räkning på ~g~$%s~s~', - ['received_payment'] = 'du har ~y~mottagit~w~ en räkning på ~g~$%s~s~', - ['player_not_logged'] = 'spelaren är inte online', - ['no_money'] = 'du har ~r~inte råd~w~ för att kunna betala räkningen', - ['target_no_money'] = 'Spelaren har ~r~inte råd~w~ för att betala räkningen', + ['paid_invoice'] = 'du ~y~betalade~s~ precis en räkning på ~g~$%s~s~', + ['received_payment'] = 'du har ~y~mottagit~s~ en räkning på ~g~$%s~s~', + ['player_not_online'] = 'personen är inte online', + ['no_money'] = 'du har ~r~inte råd~s~ för att kunna betala räkningen', + ['target_no_money'] = 'personen har ~r~inte råd~s~ för att betala räkningen', } diff --git a/server/main.lua b/server/main.lua index 8fedbf5e..36b7d776 100644 --- a/server/main.lua +++ b/server/main.lua @@ -94,13 +94,12 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id) 'SELECT * FROM billing WHERE id = @id', { ['@id'] = id - }, - function(result) + }, function(result) - local sender = result[1].sender - local targetType = result[1].target_type - local target = result[1].target - local amount = result[1].amount + local sender = result[1].sender + local targetType = result[1].target_type + local target = result[1].target + local amount = result[1].amount local xTarget = ESX.GetPlayerFromIdentifier(sender) @@ -108,55 +107,94 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id) if xTarget ~= nil then - if xPlayer.get('money') >= amount then + if xPlayer.getMoney() >= amount then - MySQL.Async.execute( - 'DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, - function(rowsChanged) + MySQL.Async.execute('DELETE from billing WHERE id = @id', + { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeMoney(amount) + xTarget.addMoney(amount) - xPlayer.removeMoney(amount) - xTarget.addMoney(amount) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) + cb() + end) - cb() + elseif xPlayer.getBank() >= amount then - end - ) + MySQL.Async.execute('DELETE from billing WHERE id = @id', + { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeAccountMoney('bank', amount) + xTarget.addAccountMoney('bank', amount) + + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) + + cb() + end) else - TriggerClientEvent('esx:showNotification', source, _U('player_not_logged')) + TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money')) + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + cb() end + else + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('player_not_online')) + cb() end else + TriggerEvent('esx_addonaccount:getSharedAccount', target, function(account) - if xPlayer.get('money') >= amount then - MySQL.Async.execute( - 'DELETE from billing WHERE id = @id', - { - ['@id'] = id - }, - function(rowsChanged) - xPlayer.removeMoney(amount) - account.addMoney(amount) - TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) - if xTarget ~= nil then - TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) - end + + if xPlayer.getMoney() >= amount then + + MySQL.Async.execute('DELETE from billing WHERE id = @id', + { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeMoney(amount) + account.addMoney(amount) + + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) + if xTarget ~= nil then + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) + end + cb() end) + + elseif xPlayer.getBank() >= amount then + + MySQL.Async.execute('DELETE from billing WHERE id = @id', + { + ['@id'] = id + }, function(rowsChanged) + xPlayer.removeAccountMoney('bank', amount) + account.addMoney(amount) + + TriggerClientEvent('esx:showNotification', xPlayer.source, _U('paid_invoice', amount)) + if xTarget ~= nil then + TriggerClientEvent('esx:showNotification', xTarget.source, _U('received_payment', amount)) + end + + cb() + end) + else TriggerClientEvent('esx:showNotification', xPlayer.source, _U('no_money')) + if xTarget ~= nil then TriggerClientEvent('esx:showNotification', xTarget.source, _U('target_no_money')) end + + cb() end end) @@ -165,4 +203,4 @@ ESX.RegisterServerCallback('esx_billing:payBill', function(source, cb, id) end ) -end) +end) \ No newline at end of file