diff --git a/__resource.lua b/__resource.lua index c7e09045..b01f9752 100644 --- a/__resource.lua +++ b/__resource.lua @@ -4,10 +4,18 @@ description 'ESX Phone' server_scripts { '@mysql-async/lib/MySQL.lua', + '@es_extended/locale.lua', + 'locales/en.lua', + 'locales/fr.lua', 'server/main.lua' } -client_script 'client/main.lua' +client_scripts { + '@es_extended/locale.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'client/main.lua' +} ui_page 'html/ui.html' @@ -32,4 +40,4 @@ files { 'html/img/icons/write.png', 'html/img/icons/edit.png', 'html/img/icons/location.png' -} \ No newline at end of file +} diff --git a/client/main.lua b/client/main.lua index be5ca732..652a7a17 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,10 +1,10 @@ local Keys = { - ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, - ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, + ["ESC"] = 322, ["F1"] = 288, ["F2"] = 289, ["F3"] = 170, ["F5"] = 166, ["F6"] = 167, ["F7"] = 168, ["F8"] = 169, ["F9"] = 56, ["F10"] = 57, + ["~"] = 243, ["1"] = 157, ["2"] = 158, ["3"] = 160, ["4"] = 164, ["5"] = 165, ["6"] = 159, ["7"] = 161, ["8"] = 162, ["9"] = 163, ["-"] = 84, ["="] = 83, ["BACKSPACE"] = 177, ["TAB"] = 37, ["Q"] = 44, ["W"] = 32, ["E"] = 38, ["R"] = 45, ["T"] = 245, ["Y"] = 246, ["U"] = 303, ["P"] = 199, ["["] = 39, ["]"] = 40, ["ENTER"] = 18, ["CAPS"] = 137, ["A"] = 34, ["S"] = 8, ["D"] = 9, ["F"] = 23, ["G"] = 47, ["H"] = 74, ["K"] = 311, ["L"] = 182, ["LEFTSHIFT"] = 21, ["Z"] = 20, ["X"] = 73, ["C"] = 26, ["V"] = 0, ["B"] = 29, ["N"] = 249, ["M"] = 244, [","] = 82, ["."] = 81, - ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, + ["LEFTCTRL"] = 36, ["LEFTALT"] = 19, ["SPACE"] = 22, ["RIGHTCTRL"] = 70, ["HOME"] = 213, ["PAGEUP"] = 10, ["PAGEDOWN"] = 11, ["DELETE"] = 178, ["LEFT"] = 174, ["RIGHT"] = 175, ["TOP"] = 27, ["DOWN"] = 173, ["NENTER"] = 201, ["N4"] = 108, ["N5"] = 60, ["N6"] = 107, ["N+"] = 96, ["N-"] = 97, ["N7"] = 117, ["N8"] = 61, ["N9"] = 118 @@ -25,7 +25,7 @@ local CurrentActionData = {} local CurrentDispatchRequestId = -1 Citizen.CreateThread(function() - + while ESX == nil do TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) Citizen.Wait(0) @@ -38,12 +38,12 @@ end) function OpenPhone() TriggerServerEvent('esx_phone:reload', PhoneData.phoneNumber) - + SendNUIMessage({ showPhone = true, phoneData = PhoneData }) - + GUI.PhoneIsShowed = true ESX.SetTimeout(200, function() @@ -59,21 +59,21 @@ function ClosePhone() }) SetNuiFocus(false) - + GUI.PhoneIsShowed = false end RegisterNetEvent('esx_phone:loaded') AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts) - + PhoneData.phoneNumber = phoneNumber PhoneData.contacts = {} - + for i=1, #contacts, 1 do table.insert(PhoneData.contacts, contacts[i]) end - + SendNUIMessage({ reloadPhone = true, phoneData = PhoneData @@ -83,7 +83,7 @@ end) RegisterNetEvent('esx_phone:addContact') AddEventHandler('esx_phone:addContact', function(name, phoneNumber, isOnline) - + table.insert(PhoneData.contacts, { name = name, number = phoneNumber, @@ -98,7 +98,7 @@ end) RegisterNetEvent('esx_phone:addSpecialContact') AddEventHandler('esx_phone:addSpecialContact', function(name, phoneNumber, base64Icon) - + SendNUIMessage({ addSpecialContact = true, name = name, @@ -110,7 +110,7 @@ end) RegisterNetEvent('esx_phone:removeSpecialContact') AddEventHandler('esx_phone:removeSpecialContact', function(phoneNumber) - + SendNUIMessage({ removeSpecialContact = true, number = phoneNumber @@ -119,10 +119,10 @@ AddEventHandler('esx_phone:removeSpecialContact', function(phoneNumber) end) RegisterNUICallback('add_contact', function(data, cb) - + local phoneNumber = tonumber(data.phoneNumber) local contactName = tostring(data.contactName) - + if phoneNumber then TriggerServerEvent('esx_phone:addPlayerContact', phoneNumber, contactName) end @@ -132,9 +132,9 @@ end) RegisterNetEvent('esx_phone:onMessage') AddEventHandler('esx_phone:onMessage', function(phoneNumber, message, position, anon, job, dispatchRequestId) - - ESX.ShowNotification('~b~Nouveau message') - + + ESX.ShowNotification(_U('new_message')) + SendNUIMessage({ newMessage = true, phoneNumber = phoneNumber, @@ -147,9 +147,9 @@ AddEventHandler('esx_phone:onMessage', function(phoneNumber, message, position, if dispatchRequestId then CurrentAction = 'dispatch' - CurrentActionMsg = job .. ' - Appuez sur ~INPUT_CONTEXT~ pour prendre l\'appel' + CurrentActionMsg = job .. _U('press_take_call') CurrentDispatchRequestId = dispatchRequestId - + CurrentActionData = { phoneNumber = phoneNumber, message = message, @@ -172,31 +172,31 @@ AddEventHandler('esx_phone:stopDispatch', function(dispatchRequestId, playerName if CurrentDispatchRequestId == dispatchRequestId and CurrentAction == 'dispatch' then CurrentAction = nil - ESX.ShowNotification(playerName .. ' a pris l\'appel') + ESX.ShowNotification(playerName .. _U('taken_call')) end end) RegisterNUICallback('setGPS', function(data) SetNewWaypoint(data.x, data.y) - ESX.ShowNotification('Position entrée dans le GPS') + ESX.ShowNotification(_U('gps_position')) end) -RegisterNUICallback('send', function(data) - +RegisterNUICallback('send', function(data) + local phoneNumber = data.number if tonumber(phoneNumber) ~= nil then phoneNumber = tonumber(phoneNumber) end - TriggerServerEvent('esx_phone:send', phoneNumber, data.message, data.anonyme) - + TriggerServerEvent('esx_phone:send', phoneNumber, data.message, data.anonyme) + SendNUIMessage({ showMessageEditor = false }) - ESX.ShowNotification('Message envoyé') + ESX.ShowNotification(_U('message_sent')) end) @@ -206,9 +206,9 @@ end) Citizen.CreateThread(function() while true do - + Wait(0) - + if GUI.PhoneIsShowed then -- codes here: https://pastebin.com/guYd0ht4 DisableControlAction(0, 1, true) -- LookLeftRight DisableControlAction(0, 2, true) -- LookUpDown @@ -221,7 +221,7 @@ Citizen.CreateThread(function() DisableControlAction(0, 142, true) -- Melee Attack Alternate DisableControlAction(0, 257, true) -- Input Attack 2 DisableControlAction(0, 263, true) -- Input Melee Attack - DisableControlAction(0, 264, true) -- Input Melee Attack 2 + DisableControlAction(0, 264, true) -- Input Melee Attack 2 DisableControlAction(0, 12, true) -- Weapon Wheel Up Down DisableControlAction(0, 14, true) -- Weapon Wheel Next @@ -231,7 +231,7 @@ Citizen.CreateThread(function() else if IsControlPressed(0, Keys['F1']) and (GetGameTimer() - GUI.Time) > 150 then - + if not ESX.UI.Menu.IsOpen('phone', GetCurrentResourceName(), 'main') then ESX.UI.Menu.CloseAll() ESX.UI.Menu.Open('phone', GetCurrentResourceName(), 'main') @@ -258,7 +258,7 @@ Citizen.CreateThread(function() DisplayHelpTextFromStringLabel(0, 0, 1, -1) if IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 300 then - + if CurrentAction == 'dispatch' then TriggerServerEvent('esx_phone:stopDispatch', CurrentDispatchRequestId) SetNewWaypoint(CurrentActionData.position.x, CurrentActionData.position.y) @@ -266,10 +266,10 @@ Citizen.CreateThread(function() CurrentAction = nil GUI.Time = GetGameTimer() - + end end end -end) \ No newline at end of file +end) diff --git a/config.lua b/config.lua new file mode 100644 index 00000000..56a8b5e9 --- /dev/null +++ b/config.lua @@ -0,0 +1,2 @@ +Config = {} +Config.Locale = 'fr' diff --git a/locales/en.lua b/locales/en.lua new file mode 100644 index 00000000..7d7393f8 --- /dev/null +++ b/locales/en.lua @@ -0,0 +1,13 @@ +Locales['en'] = { + + ['new_message'] = '~b~New message', + ['press_take_call'] = ' - Press to take the call', + ['taken_call'] = ' has taken the call', + ['gps_position'] = 'destination entered into the GPS', + ['message_sent'] = 'message sent', + ['cannot_add_self'] = 'you can not add yourself', + ['number_in_contacts'] = 'this number is alraedy in your contact list', + ['contact_added'] = 'contact added', + ['number_not_assigned'] = 'this number is not assigned...', + +} diff --git a/locales/fr.lua b/locales/fr.lua new file mode 100644 index 00000000..4927ec7c --- /dev/null +++ b/locales/fr.lua @@ -0,0 +1,13 @@ +Locales['fr'] = { + + ['new_message'] = '~b~Nouveau message', + ['press_take_call'] = ' - Appuyez sur ~INPUT_CONTEXT~ pour prendre l\'appel', + ['taken_call'] = ' a pris l\'appel', + ['gps_position'] = 'position entrée dans le GPS', + ['message_sent'] = 'message envoyé', + ['cannot_add_self'] = 'vous ne pouvez pas vous ajouter vous-même', + ['number_in_contacts'] = 'ce numéro est déja dans votre liste de contacts', + ['contact_added'] = 'contact ajouté', + ['number_not_assigned'] = 'ce numéro n\'est pas attribué...', + +} diff --git a/server/main.lua b/server/main.lua index ccc53a15..b1555710 100644 --- a/server/main.lua +++ b/server/main.lua @@ -8,14 +8,14 @@ local RegisteredCallbacks = {} local DisptachRequestId = 0 function GenerateUniquePhoneNumber() - + local foundNumber = false local phoneNumber = nil - + while not foundNumber do - + phoneNumber = math.random(10000, 99999) - + local result = MySQL.Sync.fetchAll( 'SELECT COUNT(*) as count FROM users WHERE phone_number = @phoneNumber', { @@ -24,7 +24,7 @@ function GenerateUniquePhoneNumber() ) local count = tonumber(result[1].count) - + if count == 0 then foundNumber = true end @@ -72,9 +72,9 @@ AddEventHandler('esx:playerLoaded', function(source) local phoneNumber = result[1].phone_number if phoneNumber == nil then - + phoneNumber = GenerateUniquePhoneNumber() - + MySQL.Async.execute( 'UPDATE users SET phone_number = @phone_number WHERE identifier = @identifier', { @@ -83,9 +83,9 @@ AddEventHandler('esx:playerLoaded', function(source) } ) end - + xPlayer.set('phoneNumber', phoneNumber) - + local contacts = {} MySQL.Async.fetchAll( @@ -96,13 +96,13 @@ AddEventHandler('esx:playerLoaded', function(source) function(result2) for i=1, #result2, 1 do - + table.insert(contacts, { name = result2[i].name, number = result2[i].number, online = false }) - + local xPlayers = ESX.GetPlayers() for k, v in pairs(xPlayers) do @@ -112,9 +112,9 @@ AddEventHandler('esx:playerLoaded', function(source) end end - + xPlayer.set('contacts', contacts) - + TriggerClientEvent('esx_phone:loaded', source, phoneNumber, contacts) end @@ -141,13 +141,13 @@ AddEventHandler('esx_phone:reload', function(phoneNumber) function(result2) for i=1, #result2, 1 do - + table.insert(contacts, { name = result2[i].name, number = result2[i].number, online = false }) - + local xPlayers = ESX.GetPlayers() for k, v in pairs(xPlayers) do @@ -157,7 +157,7 @@ AddEventHandler('esx_phone:reload', function(phoneNumber) end end - + xPlayer.set('contacts', contacts) TriggerClientEvent('esx_phone:loaded', _source, phoneNumber, contacts) @@ -192,7 +192,7 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) local foundPlayer = nil MySQL.Async.fetchAll( - 'SELECT phone_number FROM users WHERE phone_number = @number', + 'SELECT phone_number FROM users WHERE phone_number = @number', { ['@number'] = phoneNumber }, @@ -203,14 +203,14 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) end if foundNumber then - + if phoneNumber == xPlayer.get('phoneNumber') then - TriggerClientEvent('esx:showNotification', _source, 'Vous ne pouvez pas vous ajouter vous-même') + TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self')) else local hasAlreadyAdded = false local contacts = xPlayer.get('contacts') - + for i=1, #contacts, 1 do if contacts[i].number == phoneNumber then hasAlreadyAdded = true @@ -218,9 +218,9 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) end if hasAlreadyAdded then - TriggerClientEvent('esx:showNotification', _source, 'Ce numéro est déja dans votre liste de contacts') + TriggerClientEvent('esx:showNotification', _source, _U('number_in_contacts')) else - + table.insert(contacts, { name = contactName, number = phoneNumber, @@ -237,27 +237,27 @@ AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) }, function(rowsChanged) - TriggerClientEvent('esx:showNotification', _source, 'Contact ajouté') - + TriggerClientEvent('esx:showNotification', _source, _U('contact_added')) + local xPlayers = ESX.GetPlayers() local isOnline = false - + for k,v in pairs(xPlayers) do if v.get('phoneNumber') == phoneNumber then isOnline = true break end end - + TriggerClientEvent('esx_phone:addContact', _source, contactName, phoneNumber, isOnline) end ) - + end end else - TriggerClientEvent('esx:showNotification', source, 'Ce numéro n\'est pas attribué...') + TriggerClientEvent('esx:showNotification', source, _U('number_not_assigned')) end end @@ -267,17 +267,17 @@ end) AddEventHandler('esx_phone:ready', function() TriggerEvent('esx_phone:registerCallback', function(source, phoneNumber, message, anon) - + local xPlayer = ESX.GetPlayerFromId(source) local xPlayers = ESX.GetPlayers() print('MESSAGE => ' .. xPlayer.name .. '@' .. phoneNumber .. ' : ' .. message) for k, v in pairs(xPlayers) do - if v.get('phoneNumber') == phoneNumber then - TriggerClientEvent('esx_phone:onMessage', v.source, xPlayer.get('phoneNumber'), message, xPlayer.get('coords'), anon, job, false) - end - end + if v.get('phoneNumber') == phoneNumber then + TriggerClientEvent('esx_phone:onMessage', v.source, xPlayer.get('phoneNumber'), message, xPlayer.get('coords'), anon, job, false) + end + end end) end) @@ -285,4 +285,4 @@ end) RegisterServerEvent('esx_phone:stopDispatch') AddEventHandler('esx_phone:stopDispatch', function(dispatchRequestId) TriggerClientEvent('esx_phone:stopDispatch', -1, dispatchRequestId, GetPlayerName(source)) -end) \ No newline at end of file +end)