diff --git a/README.md b/README.md index 9a42a9c6..14151baa 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,71 @@ -# fxserver-esx_phone -FXServer esx_phone +# esx_phone -[INFO] +### Note +- All scripts that implement the usage of esx phone must be started **after** this script, or else they wont register and no messages will be received. -Original script by FiveDev => https://github.com/FiveDev-FR/esx_phone-by-FiveDev +## Download & Installation -[INSTALLATION] - -1) CD in your resources/[esx] folder -2) Clone the repository +### Using [fvm](https://github.com/qlaffont/fvm-installer) ``` -git clone https://github.com/FXServer-ESX/fxserver-esx_phone esx_phone +fvm install --save --folder=esx esx-org/esx_phone ``` -3) Import esx_phone.sql in your database -4) Add this in your server.cfg : + +### Using Git +``` +cd resources +git clone https://github.com/ESX-Org/esx_phone [esx]/esx_phone +``` + +### Manually +- Download https://github.com/ESX-Org/esx_phone/archive/master.zip +- Put it in the `[esx]` directory + +- Import `esx_phone.sql` in your database +- Add this in your `server.cfg`: ``` start esx_phone ``` + +### Add custom contacts + +Client side + +```lua +RegisterNetEvent('esx_phone:loaded') +AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts) + + local specialContact = { + name = 'societyName', + number = 'societyNumber', + base64Icon = 'insert base 64 icon (PNG recommended)' + } + + TriggerEvent('esx_phone:addSpecialContact', specialContact.name, specialContact.number, specialContact.base64Icon) + +end) +``` + +Server side + +```lua +TriggerServerEvent('esx_phone:registerNumber', number, type, sharePos, hasDispatch, hideNumber, hidePosIfAnon) + +example + +TriggerEvent('esx_phone:registerNumber', 'ambulance', _U('alert_ambulance'), true, true) + +last two booleans are optional +``` + +# Legal +### License +esx_phone - phone script for fivem + +Copyright (C) 2015-2018 Jérémie N'gadi + +This program Is free software: you can redistribute it And/Or modify it under the terms Of the GNU General Public License As published by the Free Software Foundation, either version 3 Of the License, Or (at your option) any later version. + +This program Is distributed In the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty Of MERCHANTABILITY Or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License For more details. + +You should have received a copy Of the GNU General Public License along with this program. If Not, see http://www.gnu.org/licenses/. diff --git a/__resource.lua b/__resource.lua index 33f1d883..8069fbc4 100644 --- a/__resource.lua +++ b/__resource.lua @@ -2,52 +2,54 @@ resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' description 'ESX Phone' -version '1.0.0' +version '1.1.0' server_scripts { - '@mysql-async/lib/MySQL.lua', - 'config.lua', - '@es_extended/locale.lua', - 'locales/de.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fr.lua', - 'locales/es.lua', - 'server/main.lua' + '@mysql-async/lib/MySQL.lua', + 'config.lua', + '@es_extended/locale.lua', + 'locales/de.lua', + 'locales/br.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'locales/es.lua', + 'locales/sv.lua', + 'server/main.lua' } client_scripts { - '@es_extended/locale.lua', - 'config.lua', - 'locales/de.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fr.lua', - 'locales/es.lua', - 'client/main.lua' + '@es_extended/locale.lua', + 'config.lua', + 'locales/de.lua', + 'locales/br.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'locales/es.lua', + 'locales/sv.lua', + 'client/main.lua' } ui_page 'html/ui.html' files { - 'html/ui.html', - 'html/bankgothic.ttf', - 'html/pdown.ttf', - 'html/css/app.css', - 'html/scripts/mustache.min.js', - 'html/scripts/app.js', - 'html/img/cursor.png', - 'html/img/keys/enter.png', - 'html/img/keys/return.png', - 'html/img/phone.png', - 'html/img/icons/signal.png', - 'html/img/icons/rep.png', - 'html/img/icons/msg.png', - 'html/img/icons/add.png', - 'html/img/icons/back.png', - 'html/img/icons/new-msg.png', - 'html/img/icons/reply.png', - 'html/img/icons/write.png', - 'html/img/icons/edit.png', - 'html/img/icons/location.png' + 'html/ui.html', + 'html/bankgothic.ttf', + 'html/pdown.ttf', + 'html/css/app.css', + 'html/scripts/mustache.min.js', + 'html/scripts/app.js', + 'html/img/cursor.png', + 'html/img/keys/enter.png', + 'html/img/keys/return.png', + 'html/img/phone.png', + 'html/img/icons/signal.png', + 'html/img/icons/rep.png', + 'html/img/icons/msg.png', + 'html/img/icons/add.png', + 'html/img/icons/back.png', + 'html/img/icons/new-msg.png', + 'html/img/icons/reply.png', + 'html/img/icons/write.png', + 'html/img/icons/edit.png', + 'html/img/icons/location.png' } diff --git a/client/main.lua b/client/main.lua index f3ca2bf1..1b658e73 100644 --- a/client/main.lua +++ b/client/main.lua @@ -1,13 +1,13 @@ 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, - ["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, - ["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 + ["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, + ["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 } local GUI = {} @@ -27,307 +27,273 @@ GUI.MessagesIsShowed = false GUI.AddContactIsShowed = false Citizen.CreateThread(function() - - while ESX == nil do - TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) - Citizen.Wait(0) - end - - ESX.UI.Menu.RegisterType('phone', OpenPhone, ClosePhone) - + while ESX == nil do + TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end) + Citizen.Wait(0) + end + + ESX.UI.Menu.RegisterType('phone', OpenPhone, ClosePhone) end) function OpenPhone() + local playerPed = GetPlayerPed(-1) - local playerPed = GetPlayerPed(-1) + TriggerServerEvent('esx_phone:reload', PhoneData.phoneNumber) - TriggerServerEvent('esx_phone:reload', PhoneData.phoneNumber) + SendNUIMessage({ + showPhone = true, + phoneData = PhoneData + }) - SendNUIMessage({ - showPhone = true, - phoneData = PhoneData - }) + GUI.PhoneIsShowed = true - GUI.PhoneIsShowed = true - - ESX.SetTimeout(250, function() - SetNuiFocus(true, true) - end) - - if not IsPedInAnyVehicle(playerPed, false) then - TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_STAND_MOBILE", 0, true); - end + ESX.SetTimeout(250, function() + SetNuiFocus(true, true) + end) + if not IsPedInAnyVehicle(playerPed, false) then + TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_STAND_MOBILE", 0, true); + end end function ClosePhone() + local playerPed = GetPlayerPed(-1) - local playerPed = GetPlayerPed(-1) - - SendNUIMessage({ - showPhone = false - }) - - SetNuiFocus(false) - - GUI.PhoneIsShowed = false - - ClearPedTasks(playerPed) + SendNUIMessage({ + showPhone = false + }) + SetNuiFocus(false) + GUI.PhoneIsShowed = false + ClearPedTasks(playerPed) end RegisterNetEvent('esx_phone:loaded') AddEventHandler('esx_phone:loaded', function(phoneNumber, contacts) + PhoneData.phoneNumber = phoneNumber + PhoneData.contacts = {} - PhoneData.phoneNumber = phoneNumber - PhoneData.contacts = {} - - for i=1, #contacts, 1 do - contacts[i].online = (PhoneNumberSources[contacts[i].number] == nil and false or NetworkIsPlayerActive(GetPlayerFromServerId(PhoneNumberSources[contacts[i].number]))), - table.insert(PhoneData.contacts, contacts[i]) - end - - SendNUIMessage({ - reloadPhone = true, - phoneData = PhoneData - }) + for i=1, #contacts, 1 do + contacts[i].online = (PhoneNumberSources[contacts[i].number] == nil and false or NetworkIsPlayerActive(GetPlayerFromServerId(PhoneNumberSources[contacts[i].number]))), + table.insert(PhoneData.contacts, contacts[i]) + end + SendNUIMessage({ + reloadPhone = true, + phoneData = PhoneData + }) end) RegisterNetEvent('esx_phone:addContact') AddEventHandler('esx_phone:addContact', function(name, phoneNumber) - - table.insert(PhoneData.contacts, { - name = name, - number = phoneNumber, - online = (PhoneNumberSources[contacts[i].number] == nil and false or NetworkIsPlayerActive(GetPlayerFromServerId(PhoneNumberSources[contacts[i].number]))), - }) - -- CALL HERE RELOADCONTACT - SendNUIMessage({ - contactAdded = true, - phoneData = PhoneData - }) + table.insert(PhoneData.contacts, { + name = name, + number = phoneNumber, + online = (PhoneNumberSources[contacts[i].number] == nil and false or NetworkIsPlayerActive(GetPlayerFromServerId(PhoneNumberSources[contacts[i].number]))), + }) + -- CALL HERE RELOADCONTACT + SendNUIMessage({ + contactAdded = true, + phoneData = PhoneData + }) end) RegisterNetEvent('esx_phone:removeContact') AddEventHandler('esx_phone:removeContact', function(name, phoneNumber) - - for key, value in pairs(PhoneData.contacts) do - if value.name == name and value.number == phoneNumber then - table.remove(PhoneData.contacts,key) - end - end - -- CALL HERE RELOADCONTACT - SendNUIMessage({ - contactRemoved = true, - phoneData = PhoneData - }) + for key, value in pairs(PhoneData.contacts) do + if value.name == name and value.number == phoneNumber then + table.remove(PhoneData.contacts,key) + break + end + end + -- CALL HERE RELOADCONTACT + SendNUIMessage({ + contactRemoved = true, + phoneData = PhoneData + }) end) RegisterNetEvent('esx_phone:addSpecialContact') AddEventHandler('esx_phone:addSpecialContact', function(name, phoneNumber, base64Icon) - - SendNUIMessage({ - addSpecialContact = true, - name = name, - number = phoneNumber, - base64Icon = base64Icon - }) - + SendNUIMessage({ + addSpecialContact = true, + name = name, + number = phoneNumber, + base64Icon = base64Icon + }) end) RegisterNetEvent('esx_phone:removeSpecialContact') AddEventHandler('esx_phone:removeSpecialContact', function(phoneNumber) - - SendNUIMessage({ - removeSpecialContact = true, - number = phoneNumber - }) - + SendNUIMessage({ + removeSpecialContact = true, + number = 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 - + local phoneNumber = tonumber(data.phoneNumber) + local contactName = tostring(data.contactName) + + if phoneNumber then + TriggerServerEvent('esx_phone:addPlayerContact', phoneNumber, contactName) + else + ESX.ShowNotification(_U('invalid_number')) + end end) RegisterNUICallback('remove_contact', function(data, cb) + local phoneNumber = tonumber(data.phoneNumber) + local contactName = tostring(data.contactName) - local phoneNumber = tonumber(data.phoneNumber) - local contactName = tostring(data.contactName) - - if phoneNumber then - TriggerServerEvent('esx_phone:removePlayerContact', phoneNumber, contactName) - end - + if phoneNumber then + TriggerServerEvent('esx_phone:removePlayerContact', phoneNumber, contactName) + end end) RegisterNetEvent('esx_phone:onMessage') AddEventHandler('esx_phone:onMessage', function(phoneNumber, message, position, anon, job, dispatchRequestId) + if job == 'player' then + ESX.ShowNotification(_U('new_message', message)) + else + ESX.ShowNotification('~b~' .. job .. ': ~s~' .. message) + end - if job == 'player' then - ESX.ShowNotification(_U('new_message', message)) - else - ESX.ShowNotification('~b~' .. job .. ': ~s~' .. message) - end + SendNUIMessage({ + newMessage = true, + phoneNumber = phoneNumber, + message = message, + position = position, + anonyme = anon, + job = job + }) - SendNUIMessage({ - newMessage = true, - phoneNumber = phoneNumber, - message = message, - position = position, - anonyme = anon, - job = job - }) - - if dispatchRequestId then - - CurrentAction = 'dispatch' - CurrentActionMsg = job .. _U('press_take_call') - CurrentDispatchRequestId = dispatchRequestId - - CurrentActionData = { - phoneNumber = phoneNumber, - message = message, - position = position, - actions = actions, - anonyme = anon, - job = job - } - - ESX.SetTimeout(15000, function() - CurrentAction = nil - end) - - end + if dispatchRequestId then + CurrentAction = 'dispatch' + CurrentActionMsg = _U('press_take_call', job) + CurrentDispatchRequestId = dispatchRequestId + CurrentActionData = { + phoneNumber = phoneNumber, + message = message, + position = position, + actions = actions, + anonyme = anon, + job = job + } + + ESX.SetTimeout(15000, function() + CurrentAction = nil + end) + end end) RegisterNetEvent('esx_phone:stopDispatch') AddEventHandler('esx_phone:stopDispatch', function(dispatchRequestId, playerName) - - if CurrentDispatchRequestId == dispatchRequestId and CurrentAction == 'dispatch' then - CurrentAction = nil - ESX.ShowNotification(playerName .. _U('taken_call')) - end - + if CurrentDispatchRequestId == dispatchRequestId and CurrentAction == 'dispatch' then + CurrentAction = nil + ESX.ShowNotification(_U('taken_call', playerName)) + end end) RegisterNetEvent('esx_phone:setPhoneNumberSource') AddEventHandler('esx_phone:setPhoneNumberSource', function(phoneNumber, source) - - if source == -1 then - PhoneNumberSources[phoneNumber] = nil - else - PhoneNumberSources[phoneNumber] = source - end + if source == -1 then + PhoneNumberSources[phoneNumber] = nil + else + PhoneNumberSources[phoneNumber] = source + end end) RegisterNUICallback('setGPS', function(data) - SetNewWaypoint(data.x, data.y) - ESX.ShowNotification(_U('gps_position')) + SetNewWaypoint(data.x, data.y) + ESX.ShowNotification(_U('gps_position')) end) RegisterNUICallback('send', function(data) + local phoneNumber = data.number + local playerPed = GetPlayerPed(-1) + local coords = GetEntityCoords(playerPed) - local phoneNumber = data.number - local playerPed = GetPlayerPed(-1) - local coords = GetEntityCoords(playerPed) + if tonumber(phoneNumber) ~= nil then + phoneNumber = tonumber(phoneNumber) + end - if tonumber(phoneNumber) ~= nil then - phoneNumber = tonumber(phoneNumber) - end - - TriggerServerEvent('esx_phone:send', phoneNumber, data.message, data.anonyme, { - x = coords.x, - y = coords.y, - z = coords.z - }) - - SendNUIMessage({ - showMessageEditor = false - }) - - ESX.ShowNotification(_U('message_sent')) + TriggerServerEvent('esx_phone:send', phoneNumber, data.message, data.anonyme, { + x = coords.x, + y = coords.y, + z = coords.z + }) + + SendNUIMessage({ + showMessageEditor = false + }) + ESX.ShowNotification(_U('message_sent')) end) RegisterNUICallback('escape', function() - ESX.UI.Menu.Close('phone', GetCurrentResourceName(), 'main') + ESX.UI.Menu.Close('phone', GetCurrentResourceName(), 'main') end) Citizen.CreateThread(function() - while true do + while true do + Citizen.Wait(10) - Citizen.Wait(10) + if GUI.PhoneIsShowed then -- codes here: https://pastebin.com/guYd0ht4 + DisableControlAction(0, 1, true) -- LookLeftRight + DisableControlAction(0, 2, true) -- LookUpDown + DisableControlAction(0, 25, true) -- Input Aim + DisableControlAction(0, 106, true) -- Vehicle Mouse Control Override - if GUI.PhoneIsShowed then -- codes here: https://pastebin.com/guYd0ht4 - DisableControlAction(0, 1, true) -- LookLeftRight - DisableControlAction(0, 2, true) -- LookUpDown - DisableControlAction(0, 25, true) -- Input Aim - DisableControlAction(0, 106, true) -- Vehicle Mouse Control Override + DisableControlAction(0, 24, true) -- Input Attack + DisableControlAction(0, 140, true) -- Melee Attack Alternate + DisableControlAction(0, 141, true) -- Melee Attack Alternate + 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, 24, true) -- Input Attack - DisableControlAction(0, 140, true) -- Melee Attack Alternate - DisableControlAction(0, 141, true) -- Melee Attack Alternate - 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, 12, true) -- Weapon Wheel Up Down - DisableControlAction(0, 14, true) -- Weapon Wheel Next - DisableControlAction(0, 15, true) -- Weapon Wheel Prev - DisableControlAction(0, 16, true) -- Select Next Weapon - DisableControlAction(0, 17, true) -- Select Prev Weapon - else - - if IsControlPressed(0, Keys['F1']) and GetLastInputMethod(2) 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') - end - - GUI.Time = GetGameTimer() - - end - - end - end + DisableControlAction(0, 12, true) -- Weapon Wheel Up Down + DisableControlAction(0, 14, true) -- Weapon Wheel Next + DisableControlAction(0, 15, true) -- Weapon Wheel Prev + DisableControlAction(0, 16, true) -- Select Next Weapon + DisableControlAction(0, 17, true) -- Select Prev Weapon + else + -- open phone + -- todo: is player busy (handcuffed, etc) + if IsControlPressed(0, Keys['F1']) and GetLastInputMethod(2) 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') + end + GUI.Time = GetGameTimer() + end + end + end end) -- Key controls Citizen.CreateThread(function() - while true do + while true do + Citizen.Wait(10) + + if CurrentAction ~= nil then - Citizen.Wait(10) + SetTextComponentFormat('STRING') + AddTextComponentString(CurrentActionMsg) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) - if CurrentAction ~= nil then + if IsControlPressed(0, Keys['E']) and GetLastInputMethod(2) and (GetGameTimer() - GUI.Time) > 300 then - SetTextComponentFormat('STRING') - AddTextComponentString(CurrentActionMsg) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) + if CurrentAction == 'dispatch' then + TriggerServerEvent('esx_phone:stopDispatch', CurrentDispatchRequestId) + SetNewWaypoint(CurrentActionData.position.x, CurrentActionData.position.y) + end + CurrentAction = nil + GUI.Time = GetGameTimer() + end - if IsControlPressed(0, Keys['E']) and GetLastInputMethod(2) and (GetGameTimer() - GUI.Time) > 300 then - - if CurrentAction == 'dispatch' then - TriggerServerEvent('esx_phone:stopDispatch', CurrentDispatchRequestId) - SetNewWaypoint(CurrentActionData.position.x, CurrentActionData.position.y) - end - - CurrentAction = nil - GUI.Time = GetGameTimer() - - end - - end - - end + end + end end) diff --git a/esx_phone.sql b/esx_phone.sql index e9069869..0a47211e 100644 --- a/esx_phone.sql +++ b/esx_phone.sql @@ -1,10 +1,14 @@ -CREATE TABLE user_contacts ( - id int(11) NOT NULL AUTO_INCREMENT, - identifier varchar(255) NOT NULL, - name varchar(255) NOT NULL, - number int(11) NOT NULL, - PRIMARY KEY (id) +USE `essentialmode`; + +CREATE TABLE `user_contacts` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `identifier` varchar(255) NOT NULL, + `name` varchar(255) NOT NULL, + `number` int(11) NOT NULL, + + PRIMARY KEY (`id`) ); ALTER TABLE `users` -ADD COLUMN `phone_number` INT NULL; + ADD COLUMN `phone_number` INT NULL +; diff --git a/locales/br.lua b/locales/br.lua index 9214fe24..3275b1fc 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,12 +1,13 @@ Locales['br'] = { - ['new_message'] = '~b~Nova mensagem :~s~ %s', - ['press_take_call'] = ' - Pressione ~INPUT_CONTEXT~ para aceitar a chamada', - ['taken_call'] = ' recebeu uma chamada', - ['gps_position'] = 'Destino inserido no GPS', - ['message_sent'] = 'mensagem enviada', - ['cannot_add_self'] = 'Você não pode se adicionar', - ['number_in_contacts'] = 'Este número já está na sua lista de contatos', - ['contact_added'] = 'contato adicionado', - ['contact_removed'] = 'the contact has been removed!', - ['number_not_assigned'] = 'Este número não foi atribuído...', + ['new_message'] = '~b~Nova mensagem :~s~ %s', + ['press_take_call'] = '%s - Pressione ~INPUT_CONTEXT~ para aceitar a chamada', + ['taken_call'] = '~y~%s~s~ recebeu uma chamada', + ['gps_position'] = 'destino inserido no GPS', + ['message_sent'] = 'mensagem enviada', + ['cannot_add_self'] = 'você não pode se adicionar', + ['number_in_contacts'] = 'este número já está na sua lista de contatos', + ['contact_added'] = 'contato adicionado', + ['contact_removed'] = 'the contact has been removed!', + ['number_not_assigned'] = 'este número não foi atribuído...', + ['invalid_number'] = 'that\'s not an valid number!', } diff --git a/locales/de.lua b/locales/de.lua index 425463f3..bea36169 100644 --- a/locales/de.lua +++ b/locales/de.lua @@ -1,12 +1,13 @@ Locales['de'] = { - ['new_message'] = '~b~Neue Nachricht', - ['press_take_call'] = ' - Drücke ~INPUT_CONTEXT~ um den Anruf anzunehmen', - ['taken_call'] = ' hat den Anruf angenommen', - ['gps_position'] = 'ziel in GPS eingegeben', - ['message_sent'] = 'nachricht gesendet', - ['cannot_add_self'] = 'du kannst dich nicht selbst hinzufügen', - ['number_in_contacts'] = 'diese Nummer ist bereits in deinen Kontakten', - ['contact_added'] = 'kontakt hinzugefügt', - ['contact_removed'] = 'the contact has been removed!', - ['number_not_assigned'] = 'diese Nummer ist nicht vergeben...', + ['new_message'] = '~b~Neue Nachricht', + ['press_take_call'] = '%s - Drücke ~INPUT_CONTEXT~ um den Anruf anzunehmen', + ['taken_call'] = '~y~%s~s~ hat den Anruf angenommen', + ['gps_position'] = 'ziel in GPS eingegeben', + ['message_sent'] = 'nachricht gesendet', + ['cannot_add_self'] = 'du kannst dich nicht selbst hinzufügen', + ['number_in_contacts'] = 'diese Nummer ist bereits in deinen Kontakten', + ['contact_added'] = 'kontakt hinzugefügt', + ['contact_removed'] = 'the contact has been removed!', + ['number_not_assigned'] = 'diese Nummer ist nicht vergeben...', + ['invalid_number'] = 'that\'s not an valid number!', } diff --git a/locales/en.lua b/locales/en.lua index 2d6c31ea..9fea81d3 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,12 +1,13 @@ Locales['en'] = { - ['new_message'] = '~b~Recived message:~s~ %s', - ['press_take_call'] = ' - Press ~INPUT_CONTEXT~ to take the call', - ['taken_call'] = ' has taken the call', - ['gps_position'] = 'destination entered into the GPS', - ['message_sent'] = 'the message has been sent', - ['cannot_add_self'] = 'you can not add yourself', - ['number_in_contacts'] = 'this number is already in your contact list', - ['contact_added'] = 'the contact has been added!', - ['contact_removed'] = 'the contact has been removed!', - ['number_not_assigned'] = 'this number is not assigned to anyone!', -} + ['new_message'] = '~b~You have recived a message:~s~ %s', + ['press_take_call'] = '%s - Press ~INPUT_CONTEXT~ to take the call', + ['taken_call'] = '~y~%s~s~ has taken the call', + ['gps_position'] = 'the destination has been added to your GPS', + ['message_sent'] = 'the message has been sent', + ['cannot_add_self'] = 'you can not add yourself!', + ['number_in_contacts'] = 'this number is already in your contact list', + ['contact_added'] = 'the contact has been added!', + ['contact_removed'] = 'the contact has been removed!', + ['number_not_assigned'] = 'the number has not been assigned!', + ['invalid_number'] = 'that\'s not an valid number!', +} \ No newline at end of file diff --git a/locales/es.lua b/locales/es.lua index ad06dff6..97ca7ad7 100644 --- a/locales/es.lua +++ b/locales/es.lua @@ -1,12 +1,13 @@ Locales['es'] = { - ['new_message'] = '~b~Nuevo menaje :~s~ %s', - ['press_take_call'] = ' - Presionar ~INPUT_CONTEXT~ para coger la llamada', - ['taken_call'] = ' Has contestado la llamada', - ['gps_position'] = 'Posición GPS', - ['message_sent'] = 'Mensaje enviado', - ['cannot_add_self'] = 'No has podido agregar', - ['number_in_contacts'] = 'Este número ya está en tu lista de contactos', - ['contact_added'] = 'Contacto añadido', - ['contact_removed'] = 'the contact has been removed!', - ['number_not_assigned'] = 'el número no se ha añadido todavía...', + ['new_message'] = '~b~Nuevo menaje :~s~ %s', + ['press_take_call'] = '%s - Presionar ~INPUT_CONTEXT~ para coger la llamada', + ['taken_call'] = '~y~%s~s~ has contestado la llamada', + ['gps_position'] = 'posición GPS', + ['message_sent'] = 'mensaje enviado', + ['cannot_add_self'] = 'no has podido agregar', + ['number_in_contacts'] = 'este número ya está en tu lista de contactos', + ['contact_added'] = 'contacto añadido', + ['contact_removed'] = 'the contact has been removed!', + ['number_not_assigned'] = 'el número no se ha añadido todavía...', + ['invalid_number'] = 'that\'s not an valid number!', } diff --git a/locales/fr.lua b/locales/fr.lua index ef6d2166..aa2f88d2 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -1,12 +1,13 @@ Locales['fr'] = { - ['new_message'] = '~b~Nouveau message :~s~ %s', - ['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é', - ['contact_removed'] = 'contact supprimé', - ['number_not_assigned'] = 'ce numéro n\'est pas attribué...', + ['new_message'] = '~b~Nouveau message :~s~ %s', + ['press_take_call'] = '%s - Appuyez sur ~INPUT_CONTEXT~ pour prendre l\'appel', + ['taken_call'] = '~y~%s~s~ 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é', + ['contact_removed'] = 'contact supprimé', + ['number_not_assigned'] = 'ce numéro n\'est pas attribué...', + ['invalid_number'] = 'that\'s not an valid number!', } diff --git a/locales/sv.lua b/locales/sv.lua new file mode 100644 index 00000000..51e39990 --- /dev/null +++ b/locales/sv.lua @@ -0,0 +1,13 @@ +Locales['sv'] = { + ['new_message'] = '~b~Nytt meddelande:~s~ %s', + ['press_take_call'] = '%s - tryck ~INPUT_CONTEXT~ för att svara', + ['taken_call'] = '~y~%s~s~ har tagit emot ditt meddelande', + ['gps_position'] = 'destinationen är markerad på din GPS!', + ['message_sent'] = 'meddelandet har skickats!', + ['cannot_add_self'] = 'du kan inte lägga till dig själv!', + ['number_in_contacts'] = 'det här nummret finns redan bland dina kontakter!', + ['contact_added'] = 'kontakten har lags till!', + ['contact_removed'] = 'kontakten har tagits bort!', + ['number_not_assigned'] = 'det här nummret finns inte!', + ['invalid_number'] = 'det är inte ett giltigt nummer!', +} \ No newline at end of file diff --git a/server/main.lua b/server/main.lua index 548823b9..0c1a3663 100644 --- a/server/main.lua +++ b/server/main.lua @@ -204,108 +204,99 @@ AddEventHandler('esx_phone:send', function(phoneNumber, message, anon, position) end) AddEventHandler('esx_phone:registerNumber', function(number, type, sharePos, hasDispatch, hideNumber, hidePosIfAnon) + local hideNumber = hideNumber or false + local hidePosIfAnon = hidePosIfAnon or false - local hideNumber = hideNumber or false - local hidePosIfAnon = hidePosIfAnon or false - - PhoneNumbers[number] = { - type = type, - sharePos = sharePos, - hasDispatch = (hasDispatch or false), - hideNumber = hideNumber, - hidePosIfAnon = hidePosIfAnon, - sources = {} - } - + PhoneNumbers[number] = { + type = type, + sharePos = sharePos, + hasDispatch = (hasDispatch or false), + hideNumber = hideNumber, + hidePosIfAnon = hidePosIfAnon, + sources = {} + } end) AddEventHandler('esx_phone:addSource', function(number, source) - PhoneNumbers[number].sources[tostring(source)] = true + PhoneNumbers[number].sources[tostring(source)] = true end) AddEventHandler('esx_phone:removeSource', function(number, source) - PhoneNumbers[number].sources[tostring(source)] = nil + PhoneNumbers[number].sources[tostring(source)] = nil end) RegisterServerEvent('esx_phone:addPlayerContact') AddEventHandler('esx_phone:addPlayerContact', function(phoneNumber, contactName) + local _source = source + local xPlayer = ESX.GetPlayerFromId(_source) + local foundNumber = false + phoneNumber = tonumber(phoneNumber) + + -- is the player trying to enter something else into the database? + if phoneNumber == nil then + print('esx_phone: ' .. xPlayer.identifier .. ' attempted to crash the database!') + return + end - local _source = source - local xPlayer = ESX.GetPlayerFromId(_source) - local foundNumber = false - local foundPlayer = nil + MySQL.Async.fetchAll( + 'SELECT phone_number FROM users WHERE phone_number = @number', + { + ['@number'] = phoneNumber + }, function(result) + if result[1] ~= nil then + foundNumber = true + end + end) - MySQL.Async.fetchAll( - 'SELECT phone_number FROM users WHERE phone_number = @number', - { - ['@number'] = phoneNumber - }, - function(result) + if foundNumber then + if phoneNumber == xPlayer.get('phoneNumber') then + TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self')) + else + local hasAlreadyAdded = false + local contacts = xPlayer.get('contacts') - if result[1] ~= nil then - foundNumber = true - end + for i=1, #contacts, 1 do + if contacts[i].number == phoneNumber then + hasAlreadyAdded = true + break + end + end - if foundNumber then + if hasAlreadyAdded then + TriggerClientEvent('esx:showNotification', _source, _U('number_in_contacts')) + else - if phoneNumber == xPlayer.get('phoneNumber') then - TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self')) - else + table.insert(contacts, { + name = contactName, + number = phoneNumber, + }) - local hasAlreadyAdded = false - local contacts = xPlayer.get('contacts') + xPlayer.set('contacts', contacts) - for i=1, #contacts, 1 do - if contacts[i].number == phoneNumber then - hasAlreadyAdded = true - end - end - - if hasAlreadyAdded then - TriggerClientEvent('esx:showNotification', _source, _U('number_in_contacts')) - else - - table.insert(contacts, { - name = contactName, - number = phoneNumber, - }) - - xPlayer.set('contacts', contacts) - - MySQL.Async.execute( - 'INSERT INTO user_contacts (identifier, name, number) VALUES (@identifier, @name, @number)', - { - ['@identifier'] = xPlayer.identifier, - ['@name'] = contactName, - ['@number'] = phoneNumber - }, - function(rowsChanged) - - TriggerClientEvent('esx:showNotification', _source, _U('contact_added')) - - TriggerClientEvent('esx_phone:addContact', _source, contactName, phoneNumber) - end - ) - - end - end - - else - TriggerClientEvent('esx:showNotification', source, _U('number_not_assigned')) - end - - end - ) + MySQL.Async.execute( + 'INSERT INTO user_contacts (identifier, name, number) VALUES (@identifier, @name, @number)', + { + ['@identifier'] = xPlayer.identifier, + ['@name'] = contactName, + ['@number'] = phoneNumber + }, function(rowsChanged) + TriggerClientEvent('esx:showNotification', _source, _U('contact_added')) + TriggerClientEvent('esx_phone:addContact', _source, contactName, phoneNumber) + end) + + end + end + else + TriggerClientEvent('esx:showNotification', source, _U('number_not_assigned')) + end end) RegisterServerEvent('esx_phone:removePlayerContact') AddEventHandler('esx_phone:removePlayerContact', function(phoneNumber, contactName) - local _source = source local xPlayer = ESX.GetPlayerFromId(_source) local foundNumber = false - local foundPlayer = nil MySQL.Async.fetchAll( 'SELECT phone_number FROM users WHERE phone_number = @number',