From bbe9f9f132fc51891e83d6968ae03b660f124612 Mon Sep 17 00:00:00 2001 From: Neddings Date: Thu, 15 Aug 2019 02:53:57 -0700 Subject: [PATCH 1/3] Rewritten with localisation --- __resource.lua | 20 +++- client/main.lua | 169 ++++++++++++++++++++++++++++ client/client.lua => config.lua | 191 +------------------------------- locales/en.lua | 14 +++ locales/fr.lua | 14 +++ server.lua => server/main.lua | 25 ++--- 6 files changed, 230 insertions(+), 203 deletions(-) create mode 100644 client/main.lua rename client/client.lua => config.lua (50%) create mode 100644 locales/en.lua create mode 100644 locales/fr.lua rename server.lua => server/main.lua (74%) diff --git a/__resource.lua b/__resource.lua index 4969a6e..a9bc892 100644 --- a/__resource.lua +++ b/__resource.lua @@ -1,8 +1,24 @@ -client_script('client/client.lua') +resource_manifest_version '05cfa83c-a124-4cfa-a768-c24a5811d8f9' + +description 'The New Way of Banking' + +version '1.0.0' + +client_scripts { + '@es_extended/locale.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'config.lua', + 'client/main.lua' +} server_scripts { + '@es_extended/locale.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'config.lua', '@mysql-async/lib/MySQL.lua', - 'server.lua' + 'server/main.lua' } -- Uncomment the desired version diff --git a/client/main.lua b/client/main.lua new file mode 100644 index 0000000..6062b16 --- /dev/null +++ b/client/main.lua @@ -0,0 +1,169 @@ +--================================================================================================ +--== VARIABLES - DO NOT EDIT == +--================================================================================================ +ESX = nil +inMenu = true +local showblips = true +local atbank = false +local bankMenu = true + +--================================================================================================ +--== THREADING - DO NOT EDIT == +--================================================================================================ + +--=============================================== +--== Base ESX Threading == +--=============================================== +Citizen.CreateThread(function() + while ESX == nil do + TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + Citizen.Wait(0) + end +end) + +--=============================================== +--== Core Threading == +--=============================================== +if bankMenu then + Citizen.CreateThread(function() + while true do + Wait(0) + if nearBank() or nearATM() then + DisplayHelpText(_U('helptext')) + if IsControlJustPressed(1, 38) then + inMenu = true + SetNuiFocus(true, true) + SendNUIMessage({type = 'openGeneral'}) + TriggerServerEvent('bank:balance') + local ped = GetPlayerPed(-1) + end + end + if IsControlJustPressed(1, 322) then + inMenu = false + SetNuiFocus(false, false) + SendNUIMessage({type = 'close'}) + end + end + end) +end + +--=============================================== +--== Map Blips == +--=============================================== +Citizen.CreateThread(function() + if showblips then + for k,v in ipairs(Config.Banks)do + local blip = AddBlipForCoord(v.x, v.y, v.z) + SetBlipSprite(blip, v.id) + SetBlipScale(blip, 0.7) + SetBlipAsShortRange(blip, true) + if v.principal ~= nil and v.principal then + SetBlipColour(blip, 77) + end + BeginTextCommandSetBlipName("STRING") + AddTextComponentString(tostring(v.name)) + EndTextCommandSetBlipName(blip) + end + end +end) + +--=============================================== +--== Deposit Event == +--=============================================== +RegisterNetEvent('currentbalance1') +AddEventHandler('currentbalance1', function(balance) + local id = PlayerId() + local playerName = GetPlayerName(id) + + SendNUIMessage({ + type = "balanceHUD", + balance = balance, + player = playerName + }) +end) +--=============================================== +--== Deposit Event == +--=============================================== +RegisterNUICallback('deposit', function(data) + TriggerServerEvent('bank:deposit', tonumber(data.amount)) + TriggerServerEvent('bank:balance') +end) + +--=============================================== +--== Withdraw Event == +--=============================================== +RegisterNUICallback('withdrawl', function(data) + TriggerServerEvent('bank:withdraw', tonumber(data.amountw)) + TriggerServerEvent('bank:balance') +end) + +--=============================================== +--== Balance Event == +--=============================================== +RegisterNUICallback('balance', function() + TriggerServerEvent('bank:balance') +end) + +RegisterNetEvent('balance:back') +AddEventHandler('balance:back', function(balance) + SendNUIMessage({type = 'balanceReturn', bal = balance}) +end) + +--=============================================== +--== Transfer Event == +--=============================================== +RegisterNUICallback('transfer', function(data) + TriggerServerEvent('bank:transfer', data.to, data.amountt) + TriggerServerEvent('bank:balance') +end) + +--=============================================== +--== Result Event == +--=============================================== +RegisterNetEvent('bank:result') +AddEventHandler('bank:result', function(type, message) + SendNUIMessage({type = 'result', m = message, t = type}) +end) + +--=============================================== +--== NUIFocusoff == +--=============================================== +RegisterNUICallback('NUIFocusOff', function() + inMenu = false + SetNuiFocus(false, false) + SendNUIMessage({type = 'closeAll'}) +end) + +--=============================================== +--== Capture Bank Distance == +--=============================================== +function nearBank() + local player = GetPlayerPed(-1) + local playerloc = GetEntityCoords(player, 0) + + for _, search in pairs(Config.Banks) do + local distance = GetDistanceBetweenCoords(search.x, search.y, search.z, playerloc['x'], playerloc['y'], playerloc['z'], true) + + if distance <= 3 then + return true + end + end +end + +function nearATM() + local player = GetPlayerPed(-1) + local playerloc = GetEntityCoords(player, 0) + + for _, search in pairs(Config.ATM) do + local distance = GetDistanceBetweenCoords(search.x, search.y, search.z, playerloc['x'], playerloc['y'], playerloc['z'], true) + if distance <= 3 then + return true + end + end +end + +function DisplayHelpText(str) + SetTextComponentFormat("STRING") + AddTextComponentString(str) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) +end \ No newline at end of file diff --git a/client/client.lua b/config.lua similarity index 50% rename from client/client.lua rename to config.lua index c6d7d40..8c7731a 100644 --- a/client/client.lua +++ b/config.lua @@ -1,12 +1,7 @@ ---================================================================================================ ---== VARIABLES - DO NOT EDIT == ---================================================================================================ -ESX = nil -inMenu = true -local showblips = true -local atbank = false -local bankMenu = true -local banks = { +Config = {} +Config.Locale = 'fr' + +Config.Banks = { {name="Bank", id=108, x=150.266, y=-1040.203, z=29.374}, {name="Bank", id=108, x=-1212.980, y=-330.841, z=37.787}, {name="Bank", id=108, x=-2962.582, y=482.627, z=15.703}, @@ -15,9 +10,9 @@ local banks = { {name="Bank", id=108, x=-351.534, y=-49.529, z=49.042}, {name="Pacific Bank", id=106, x=241.727, y=220.706, z=106.286, principal = true}, {name="Bank", id=108, x=1175.0643310547, y=2706.6435546875, z=38.094036102295} -} +} -local atms = { +Config.ATM = { {name="ATM", id=277, x=-386.733, y=6045.953, z=31.501}, {name="ATM", id=277, x=-284.037, y=6224.385, z=31.187}, {name="ATM", id=277, x=-284.037, y=6224.385, z=31.187}, @@ -91,7 +86,6 @@ local atms = { {name="ATM", id=277, x=-302.408, y=-829.945, z=32.417}, {name="ATM", id=277, x=5.134, y=-919.949, z=29.557}, {name="ATM", id=277, x=527.26, y=-160.76, z=57.09}, - {name="ATM", id=277, x=-867.19, y=-186.99, z=37.84}, {name="ATM", id=277, x=-821.62, y=-1081.88, z=11.13}, {name="ATM", id=277, x=-1315.32, y=-835.96, z=16.96}, @@ -110,176 +104,3 @@ local atms = { {name="ATM", id=277, x=-1286.24, y=-213.39, z=42.45}, {name="ATM", id=277, x=-1282.54, y=-210.45, z=42.45}, } ---================================================================================================ ---== THREADING - DO NOT EDIT == ---================================================================================================ - ---=============================================== ---== Base ESX Threading == ---=============================================== -Citizen.CreateThread(function() - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end -end) - - - - - ---=============================================== ---== Core Threading == ---=============================================== -if bankMenu then - Citizen.CreateThread(function() - while true do - Wait(0) - if nearBank() or nearATM() then - DisplayHelpText("Appuie sur ~INPUT_PICKUP~ pour accèder à tes comptes ~b~") - - if IsControlJustPressed(1, 38) then - inMenu = true - SetNuiFocus(true, true) - SendNUIMessage({type = 'openGeneral'}) - TriggerServerEvent('bank:balance') - local ped = GetPlayerPed(-1) - end - end - - if IsControlJustPressed(1, 322) then - inMenu = false - SetNuiFocus(false, false) - SendNUIMessage({type = 'close'}) - end - end - end) -end - - ---=============================================== ---== Map Blips == ---=============================================== -Citizen.CreateThread(function() - if showblips then - for k,v in ipairs(banks)do - local blip = AddBlipForCoord(v.x, v.y, v.z) - SetBlipSprite(blip, v.id) - SetBlipScale(blip, 0.7) - SetBlipAsShortRange(blip, true) - if v.principal ~= nil and v.principal then - SetBlipColour(blip, 77) - end - BeginTextCommandSetBlipName("STRING") - AddTextComponentString(tostring(v.name)) - EndTextCommandSetBlipName(blip) - end - end -end) - - - ---=============================================== ---== Deposit Event == ---=============================================== -RegisterNetEvent('currentbalance1') -AddEventHandler('currentbalance1', function(balance) - local id = PlayerId() - local playerName = GetPlayerName(id) - - SendNUIMessage({ - type = "balanceHUD", - balance = balance, - player = playerName - }) -end) ---=============================================== ---== Deposit Event == ---=============================================== -RegisterNUICallback('deposit', function(data) - TriggerServerEvent('bank:deposit', tonumber(data.amount)) - TriggerServerEvent('bank:balance') -end) - ---=============================================== ---== Withdraw Event == ---=============================================== -RegisterNUICallback('withdrawl', function(data) - TriggerServerEvent('bank:withdraw', tonumber(data.amountw)) - TriggerServerEvent('bank:balance') -end) - ---=============================================== ---== Balance Event == ---=============================================== -RegisterNUICallback('balance', function() - TriggerServerEvent('bank:balance') -end) - -RegisterNetEvent('balance:back') -AddEventHandler('balance:back', function(balance) - SendNUIMessage({type = 'balanceReturn', bal = balance}) -end) - - ---=============================================== ---== Transfer Event == ---=============================================== -RegisterNUICallback('transfer', function(data) - TriggerServerEvent('bank:transfer', data.to, data.amountt) - TriggerServerEvent('bank:balance') -end) - ---=============================================== ---== Result Event == ---=============================================== -RegisterNetEvent('bank:result') -AddEventHandler('bank:result', function(type, message) - SendNUIMessage({type = 'result', m = message, t = type}) -end) - ---=============================================== ---== NUIFocusoff == ---=============================================== -RegisterNUICallback('NUIFocusOff', function() - inMenu = false - SetNuiFocus(false, false) - SendNUIMessage({type = 'closeAll'}) -end) - - ---=============================================== ---== Capture Bank Distance == ---=============================================== -function nearBank() - local player = GetPlayerPed(-1) - local playerloc = GetEntityCoords(player, 0) - - for _, search in pairs(banks) do - local distance = GetDistanceBetweenCoords(search.x, search.y, search.z, playerloc['x'], playerloc['y'], playerloc['z'], true) - - if distance <= 3 then - return true - end - end -end - -function nearATM() - local player = GetPlayerPed(-1) - local playerloc = GetEntityCoords(player, 0) - - for _, search in pairs(atms) do - local distance = GetDistanceBetweenCoords(search.x, search.y, search.z, playerloc['x'], playerloc['y'], playerloc['z'], true) - - if distance <= 3 then - return true - end - end -end - - -function DisplayHelpText(str) - SetTextComponentFormat("STRING") - AddTextComponentString(str) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) -end \ No newline at end of file diff --git a/locales/en.lua b/locales/en.lua new file mode 100644 index 0000000..82fed0c --- /dev/null +++ b/locales/en.lua @@ -0,0 +1,14 @@ +Locales['en'] = { + -- General + ['helptext'] = "Press ~INPUT_PICKUP~ to access your ~b~ accounts", + ['amount_invalid'] = "Invalid amount.", + -- Deposit + ['deposit_success'] = "Deposit completed.", + -- Withdraw + ['withdraw_success'] = "Withdrawal completed.", + --Transfer + ['destination_unknown'] = "Recipient not found.", + ['destination_self'] = "You can't make a transfer to yourself.", + ['not_enough'] = "You don't have enough money in the bank.", + ['transfer_success'] = "Transfer completed.", +} \ No newline at end of file diff --git a/locales/fr.lua b/locales/fr.lua new file mode 100644 index 0000000..d713097 --- /dev/null +++ b/locales/fr.lua @@ -0,0 +1,14 @@ +Locales['fr'] = { + -- General + ['helptext'] = "Appuie sur ~INPUT_PICKUP~ pour accèder à tes comptes ~b~", + ['amount_invalid'] = "Montant invalide.", + -- Deposit + ['deposit_success'] = "Dépot effectué.", + -- Withdraw + ['withdraw_success'] = "Retrait effectué.", + --Transfer + ['destination_unknown'] = "Destinataire introuvable.", + ['destination_self'] = "Vous ne pouvez pas faire de transfert à vous même.", + ['not_enough'] = "Vous n'avez pas assez d'argent en banque.", + ['transfer_success'] = "Transfert effectué.", +} \ No newline at end of file diff --git a/server.lua b/server/main.lua similarity index 74% rename from server.lua rename to server/main.lua index fcdb751..4108999 100644 --- a/server.lua +++ b/server/main.lua @@ -11,15 +11,14 @@ AddEventHandler('bank:deposit', function(amount) local xPlayer = ESX.GetPlayerFromId(_source) if amount == nil or amount <= 0 or amount > xPlayer.getMoney() then - TriggerClientEvent('bank:result', _source, "error", "Montant invalide.") + TriggerClientEvent('bank:result', _source, "error", _U('amount_invalid')) else xPlayer.removeMoney(amount) xPlayer.addAccountMoney('bank', tonumber(amount)) - TriggerClientEvent('bank:result', _source, "success", "Dépot effectué.") + TriggerClientEvent('bank:result', _source, "success", _U('deposit_success')) end end) - RegisterServerEvent('bank:withdraw') AddEventHandler('bank:withdraw', function(amount) local _source = source @@ -28,11 +27,11 @@ AddEventHandler('bank:withdraw', function(amount) amount = tonumber(amount) base = xPlayer.getAccount('bank').money if amount == nil or amount <= 0 or amount > base then - TriggerClientEvent('bank:result', _source, "error", "Montant invalide.") + TriggerClientEvent('bank:result', _source, "error", _U('amount_invalid')) else xPlayer.removeAccountMoney('bank', amount) xPlayer.addMoney(amount) - TriggerClientEvent('bank:result', _source, "success", "Retrait effectué.") + TriggerClientEvent('bank:result', _source, "success", _U('withdraw_success')) end end) @@ -44,7 +43,6 @@ AddEventHandler('bank:balance', function() TriggerClientEvent('currentbalance1', _source, balance) end) - RegisterServerEvent('bank:transfer') AddEventHandler('bank:transfer', function(to, amountt) local _source = source @@ -53,26 +51,21 @@ AddEventHandler('bank:transfer', function(to, amountt) local balance = 0 if(zPlayer == nil or zPlayer == -1) then - TriggerClientEvent('bank:result', _source, "error", "Destinataire introuvable.") + TriggerClientEvent('bank:result', _source, "error", _U('destination_unknown')) else balance = xPlayer.getAccount('bank').money zbalance = zPlayer.getAccount('bank').money if tonumber(_source) == tonumber(to) then - TriggerClientEvent('bank:result', _source, "error", "Vous ne pouvez pas faire de transfert à vous même.") + TriggerClientEvent('bank:result', _source, "error", _U('destination_self')) else if balance <= 0 or balance < tonumber(amountt) or tonumber(amountt) <= 0 then - TriggerClientEvent('bank:result', _source, "error", "Vous n'avez pas assez d'argent en banque.") + TriggerClientEvent('bank:result', _source, "error", _U('not_enough')) else xPlayer.removeAccountMoney('bank', tonumber(amountt)) zPlayer.addAccountMoney('bank', tonumber(amountt)) - TriggerClientEvent('bank:result', _source, "success", "Transfert effectué.") + TriggerClientEvent('bank:result', _source, "success", _U('transfer_success')) end end end -end) - - - - - +end) \ No newline at end of file From bd8a17792d47e78c967997da20764289a2b6cd79 Mon Sep 17 00:00:00 2001 From: Neddings Date: Thu, 15 Aug 2019 03:20:46 -0700 Subject: [PATCH 2/3] Made a small typing mistake --- client/main.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/main.lua b/client/main.lua index 6062b16..9309189 100644 --- a/client/main.lua +++ b/client/main.lua @@ -52,7 +52,7 @@ end --=============================================== Citizen.CreateThread(function() if showblips then - for k,v in ipairs(Config.Banks)do + for k,v in pairs(Config.Banks)do local blip = AddBlipForCoord(v.x, v.y, v.z) SetBlipSprite(blip, v.id) SetBlipScale(blip, 0.7) From 5abf347cb96bb7e33ddda7058cf04a1ad01f5e88 Mon Sep 17 00:00:00 2001 From: Neddings Date: Thu, 15 Aug 2019 03:53:23 -0700 Subject: [PATCH 3/3] And adding the Dutch translation. Please note: the UI is not translated to Dutch yet --- __resource.lua | 10 ++++++---- locales/nl.lua | 14 ++++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 locales/nl.lua diff --git a/__resource.lua b/__resource.lua index a9bc892..5cdb918 100644 --- a/__resource.lua +++ b/__resource.lua @@ -6,8 +6,9 @@ version '1.0.0' client_scripts { '@es_extended/locale.lua', - 'locales/en.lua', + 'locales/en.lua', 'locales/fr.lua', + 'locales/nl.lua', 'config.lua', 'client/main.lua' } @@ -15,10 +16,11 @@ client_scripts { server_scripts { '@es_extended/locale.lua', 'locales/en.lua', - 'locales/fr.lua', + 'locales/fr.lua', + 'locales/nl.lua', 'config.lua', - '@mysql-async/lib/MySQL.lua', - 'server/main.lua' + '@mysql-async/lib/MySQL.lua', + 'server/main.lua' } -- Uncomment the desired version diff --git a/locales/nl.lua b/locales/nl.lua new file mode 100644 index 0000000..9f15ac0 --- /dev/null +++ b/locales/nl.lua @@ -0,0 +1,14 @@ +Locales['nl'] = { + -- General + ['helptext'] = "Druk op ~INPUT_PICKUP~ om toegang te krijgen tot uw ~b~ accounts.", + ['amount_invalid'] = "Ongeldig bedrag.", + -- Deposit + ['deposit_success'] = "Storting voltooid.", + -- Withdraw + ['withdraw_success'] = "Terugtrekking voltooid.", + --Transfer + ['destination_unknown'] = "Ontvanger niet gevonden.", + ['destination_self'] = "Je kunt niet naar jezelf overboeken.", + ['not_enough'] = "Je hebt niet genoeg geld op de bank.", + ['transfer_success'] = "Overschrijving voltooid.", +} \ No newline at end of file