chore(coding-style): correct indentation

This commit is contained in:
Romain Lanz
2017-09-14 16:36:56 +02:00
parent e1164eed01
commit adf225574c
10 changed files with 424 additions and 423 deletions
+9
View File
@@ -0,0 +1,9 @@
root = true
[*]
indent_size = 2
indent_style = space
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
+37 -37
View File
@@ -3,49 +3,49 @@ resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
description 'ESX Phone'
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',
'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',
'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'
}
+142 -141
View File
@@ -1,22 +1,17 @@
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
}
ESX = nil
local GUI = {}
GUI.Time = 0
GUI.PhoneIsShowed = false
GUI.MessagesIsShowed = false
GUI.AddContactIsShowed = false
local PhoneData = {phoneNumber = 0, contacts = {}}
local PhoneData = { phoneNumber = 0, contacts = {} }
local RegisteredMessageCallbacks = {}
local ContactJustAdded = false
local CurrentAction = nil
@@ -25,22 +20,28 @@ local CurrentActionData = {}
local CurrentDispatchRequestId = -1
local PhoneNumberSources = {}
ESX = nil
GUI.Time = 0
GUI.PhoneIsShowed = false
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
while ESX == nil do
TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
Citizen.Wait(0)
end
ESX.UI.Menu.RegisterType('phone', OpenPhone, ClosePhone)
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,
@@ -50,94 +51,94 @@ function OpenPhone()
GUI.PhoneIsShowed = true
ESX.SetTimeout(250, function()
SetNuiFocus(true, true)
SetNuiFocus(true, true)
end)
if not IsPedInAnyVehicle(playerPed, false) then
TaskStartScenarioInPlace(playerPed, "WORLD_HUMAN_STAND_MOBILE", 0, 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
showPhone = false
})
SetNuiFocus(false)
GUI.PhoneIsShowed = false
GUI.PhoneIsShowed = false
ClearPedTasks(playerPed)
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
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
})
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: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 phoneNumber = tonumber(data.phoneNumber)
local contactName = tostring(data.contactName)
if phoneNumber then
TriggerServerEvent('esx_phone:addPlayerContact', phoneNumber, contactName)
end
if phoneNumber then
TriggerServerEvent('esx_phone:addPlayerContact', phoneNumber, contactName)
end
end)
@@ -145,107 +146,107 @@ 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
if dispatchRequestId then
CurrentAction = 'dispatch'
CurrentActionMsg = job .. _U('press_take_call')
CurrentDispatchRequestId = dispatchRequestId
CurrentAction = 'dispatch'
CurrentActionMsg = job .. _U('press_take_call')
CurrentDispatchRequestId = dispatchRequestId
CurrentActionData = {
phoneNumber = phoneNumber,
message = message,
position = position,
actions = actions,
anonyme = anon,
job = job
}
CurrentActionData = {
phoneNumber = phoneNumber,
message = message,
position = position,
actions = actions,
anonyme = anon,
job = job
}
ESX.SetTimeout(15000, function()
CurrentAction = nil
end)
ESX.SetTimeout(15000, function()
CurrentAction = nil
end)
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(playerName .. _U('taken_call'))
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
})
TriggerServerEvent('esx_phone:send', phoneNumber, data.message, data.anonyme, {
x = coords.x,
y = coords.y,
z = coords.z
})
SendNUIMessage({
showMessageEditor = false
})
SendNUIMessage({
showMessageEditor = false
})
ESX.ShowNotification(_U('message_sent'))
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
Wait(0)
Wait(0)
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, 106, true) -- Vehicle Mouse Control Override
DisableControlAction(0, 24, true) -- Input Attack
DisableControlAction(0, 140, true) -- Melee Attack Alternate
@@ -265,8 +266,8 @@ Citizen.CreateThread(function()
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')
ESX.UI.Menu.CloseAll()
ESX.UI.Menu.Open('phone', GetCurrentResourceName(), 'main')
end
GUI.Time = GetGameTimer()
@@ -279,29 +280,29 @@ end)
-- Key controls
Citizen.CreateThread(function()
while true do
while true do
Citizen.Wait(0)
Citizen.Wait(0)
if CurrentAction ~= nil then
if CurrentAction ~= nil then
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
SetTextComponentFormat('STRING')
AddTextComponentString(CurrentActionMsg)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 300 then
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)
end
if CurrentAction == 'dispatch' then
TriggerServerEvent('esx_phone:stopDispatch', CurrentDispatchRequestId)
SetNewWaypoint(CurrentActionData.position.x, CurrentActionData.position.y)
end
CurrentAction = nil
GUI.Time = GetGameTimer()
CurrentAction = nil
GUI.Time = GetGameTimer()
end
end
end
end
end
end
end)
+1 -1
View File
@@ -6,5 +6,5 @@ CREATE TABLE user_contacts (
PRIMARY KEY (id)
);
ALTER TABLE `users`
ALTER TABLE `users`
ADD COLUMN `phone_number` INT NULL;
+9 -11
View File
@@ -1,13 +1,11 @@
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',
['number_not_assigned'] = 'Este número não foi atribuído...',
['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',
['number_not_assigned'] = 'Este número não foi atribuído...',
}
+9 -11
View File
@@ -1,13 +1,11 @@
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',
['number_not_assigned'] = 'diese Nummer ist nicht vergeben...',
['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',
['number_not_assigned'] = 'diese Nummer ist nicht vergeben...',
}
+9 -11
View File
@@ -1,13 +1,11 @@
Locales['en'] = {
['new_message'] = '~b~New 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'] = '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...',
['new_message'] = '~b~New 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'] = '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...',
}
+9 -10
View File
@@ -1,12 +1,11 @@
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',
['number_not_assigned'] = 'El número no se ha añadido todavía...',
['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',
['number_not_assigned'] = 'El número no se ha añadido todavía...',
}
+9 -11
View File
@@ -1,13 +1,11 @@
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é',
['number_not_assigned'] = 'ce numéro n\'est pas attribué...',
['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é',
['number_not_assigned'] = 'ce numéro n\'est pas attribué...',
}
+190 -190
View File
@@ -3,309 +3,309 @@ local DisptachRequestId = 0
local PhoneNumbers = {}
TriggerEvent('esx:getSharedObject', function(obj)
ESX = obj
ESX = obj
end)
function GenerateUniquePhoneNumber()
local foundNumber = false
local phoneNumber = nil
local foundNumber = false
local phoneNumber = nil
while not foundNumber do
while not foundNumber do
phoneNumber = math.random(10000, 99999)
phoneNumber = math.random(10000, 99999)
local result = MySQL.Sync.fetchAll(
'SELECT COUNT(*) as count FROM users WHERE phone_number = @phoneNumber',
{
['@phoneNumber'] = phoneNumber
}
)
local result = MySQL.Sync.fetchAll(
'SELECT COUNT(*) as count FROM users WHERE phone_number = @phoneNumber',
{
['@phoneNumber'] = phoneNumber
}
)
local count = tonumber(result[1].count)
local count = tonumber(result[1].count)
if count == 0 then
foundNumber = true
end
if count == 0 then
foundNumber = true
end
end
end
return phoneNumber
return phoneNumber
end
function GetDistpatchRequestId()
local requestId = DisptachRequestId
local requestId = DisptachRequestId
if DisptachRequestId < 65535 then
DisptachRequestId = DisptachRequestId + 1
else
DisptachRequestId = 0
end
if DisptachRequestId < 65535 then
DisptachRequestId = DisptachRequestId + 1
else
DisptachRequestId = 0
end
return requestId
return requestId
end
AddEventHandler('esx_phone:getDistpatchRequestId', function(cb)
cb(GetDistpatchRequestId())
cb(GetDistpatchRequestId())
end)
AddEventHandler('onResourceStart', function(ressource)
if ressource == 'esx_phone' then
TriggerEvent('esx_phone:ready')
end
if ressource == 'esx_phone' then
TriggerEvent('esx_phone:ready')
end
end)
AddEventHandler('esx:playerLoaded', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
local xPlayer = ESX.GetPlayerFromId(source)
for num,v in pairs(PhoneNumbers) do
if tonumber(num) == num then -- If phonenumber is a player phone number
for src,_ in pairs(v.sources) do
TriggerClientEvent('esx_phone:setPhoneNumberSource', source, num, tonumber(src))
end
end
end
for num,v in pairs(PhoneNumbers) do
if tonumber(num) == num then -- If phonenumber is a player phone number
for src,_ in pairs(v.sources) do
TriggerClientEvent('esx_phone:setPhoneNumberSource', source, num, tonumber(src))
end
end
end
MySQL.Async.fetchAll(
'SELECT * FROM users WHERE identifier = @identifier',
{
['@identifier'] = xPlayer.identifier
},
function(result)
MySQL.Async.fetchAll(
'SELECT * FROM users WHERE identifier = @identifier',
{
['@identifier'] = xPlayer.identifier
},
function(result)
local phoneNumber = result[1].phone_number
local phoneNumber = result[1].phone_number
if phoneNumber == nil then
if phoneNumber == nil then
phoneNumber = GenerateUniquePhoneNumber()
phoneNumber = GenerateUniquePhoneNumber()
MySQL.Async.execute(
'UPDATE users SET phone_number = @phone_number WHERE identifier = @identifier',
{
['@identifier'] = xPlayer.identifier,
['@phone_number'] = phoneNumber
}
)
end
MySQL.Async.execute(
'UPDATE users SET phone_number = @phone_number WHERE identifier = @identifier',
{
['@identifier'] = xPlayer.identifier,
['@phone_number'] = phoneNumber
}
)
end
TriggerClientEvent('esx_phone:setPhoneNumberSource', -1, phoneNumber, source)
TriggerClientEvent('esx_phone:setPhoneNumberSource', -1, phoneNumber, source)
PhoneNumbers[phoneNumber] = {
type = 'player',
hashDispatch = false,
sharePos = false,
hideNumber = false,
hidePosIfAnon = false,
sources = {[source] = true}
}
PhoneNumbers[phoneNumber] = {
type = 'player',
hashDispatch = false,
sharePos = false,
hideNumber = false,
hidePosIfAnon = false,
sources = {[source] = true}
}
xPlayer.set('phoneNumber', phoneNumber)
xPlayer.set('phoneNumber', phoneNumber)
if PhoneNumbers[xPlayer.job.name] ~= nil then
TriggerEvent('esx_phone:addSource', xPlayer.job.name, source)
end
if PhoneNumbers[xPlayer.job.name] ~= nil then
TriggerEvent('esx_phone:addSource', xPlayer.job.name, source)
end
local contacts = {}
local contacts = {}
MySQL.Async.fetchAll(
'SELECT * FROM user_contacts WHERE identifier = @identifier ORDER BY name ASC',
{
['@identifier'] = xPlayer.identifier
},
function(result2)
MySQL.Async.fetchAll(
'SELECT * FROM user_contacts WHERE identifier = @identifier ORDER BY name ASC',
{
['@identifier'] = xPlayer.identifier
},
function(result2)
for i=1, #result2, 1 do
for i=1, #result2, 1 do
table.insert(contacts, {
name = result2[i].name,
number = result2[i].number,
})
end
table.insert(contacts, {
name = result2[i].name,
number = result2[i].number,
})
end
xPlayer.set('contacts', contacts)
xPlayer.set('contacts', contacts)
TriggerClientEvent('esx_phone:loaded', source, phoneNumber, contacts)
TriggerClientEvent('esx_phone:loaded', source, phoneNumber, contacts)
end
)
end
)
end
)
end
)
end)
AddEventHandler('esx:playerDropped', function(source)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerClientEvent('esx_phone:setPhoneNumberSource', -1, xPlayer.get('phoneNumber'), -1)
PhoneNumbers[xPlayer.get('phoneNumber')] = nil
local xPlayer = ESX.GetPlayerFromId(source)
if PhoneNumbers[xPlayer.job.name] ~= nil then
TriggerEvent('esx_phone:removeSource', xPlayer.job.name, source)
end
TriggerClientEvent('esx_phone:setPhoneNumberSource', -1, xPlayer.get('phoneNumber'), -1)
PhoneNumbers[xPlayer.get('phoneNumber')] = nil
if PhoneNumbers[xPlayer.job.name] ~= nil then
TriggerEvent('esx_phone:removeSource', xPlayer.job.name, source)
end
end)
AddEventHandler('esx:setJob', function(source, job, lastJob)
if PhoneNumbers[lastJob.name] ~= nil then
TriggerEvent('esx_phone:removeSource', lastJob.name, source)
end
if PhoneNumbers[job.name] ~= nil then
TriggerEvent('esx_phone:addSource', job.name, source)
end
if PhoneNumbers[lastJob.name] ~= nil then
TriggerEvent('esx_phone:removeSource', lastJob.name, source)
end
if PhoneNumbers[job.name] ~= nil then
TriggerEvent('esx_phone:addSource', job.name, source)
end
end)
RegisterServerEvent('esx_phone:reload')
AddEventHandler('esx_phone:reload', function(phoneNumber)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local contacts = xPlayer.get('contacts')
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local contacts = xPlayer.get('contacts')
TriggerClientEvent('esx_phone:loaded', _source, phoneNumber, contacts)
TriggerClientEvent('esx_phone:loaded', _source, phoneNumber, contacts)
end)
RegisterServerEvent('esx_phone:send')
AddEventHandler('esx_phone:send', function(phoneNumber, message, anon, position)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
print('MESSAGE => ' .. xPlayer.name .. '@' .. phoneNumber .. ' : ' .. message)
print('MESSAGE => ' .. xPlayer.name .. '@' .. phoneNumber .. ' : ' .. message)
if PhoneNumbers[phoneNumber] ~= nil then
if PhoneNumbers[phoneNumber] ~= nil then
for k,v in pairs(PhoneNumbers[phoneNumber].sources) do
for k,v in pairs(PhoneNumbers[phoneNumber].sources) do
local numType = PhoneNumbers[phoneNumber].type
local numHasDispatch = PhoneNumbers[phoneNumber].hasDispatch
local numHide = PhoneNumbers[phoneNumber].hideNumber
local numHidePosIfAnon = PhoneNumbers[phoneNumber].hidePosIfAnon
local numPosition = (PhoneNumbers[phoneNumber].sharePos and position or false)
local numSource = tonumber(k)
local numType = PhoneNumbers[phoneNumber].type
local numHasDispatch = PhoneNumbers[phoneNumber].hasDispatch
local numHide = PhoneNumbers[phoneNumber].hideNumber
local numHidePosIfAnon = PhoneNumbers[phoneNumber].hidePosIfAnon
local numPosition = (PhoneNumbers[phoneNumber].sharePos and position or false)
local numSource = tonumber(k)
if numHidePosIfAnon and anon then
numPosition = false
end
if numHidePosIfAnon and anon then
numPosition = false
end
if numHasDispatch then
TriggerClientEvent('esx_phone:onMessage', numSource, xPlayer.get('phoneNumber'), message, numPosition, (numHide and true or anon), numType, GetDistpatchRequestId())
else
TriggerClientEvent('esx_phone:onMessage', numSource, xPlayer.get('phoneNumber'), message, numPosition, (numHide and true or anon), numType, false)
end
if numHasDispatch then
TriggerClientEvent('esx_phone:onMessage', numSource, xPlayer.get('phoneNumber'), message, numPosition, (numHide and true or anon), numType, GetDistpatchRequestId())
else
TriggerClientEvent('esx_phone:onMessage', numSource, xPlayer.get('phoneNumber'), message, numPosition, (numHide and true or anon), numType, false)
end
end
end
end
end
end)
AddEventHandler('esx_phone:registerNumber', function(number, type, sharePos, hasDispatch, hideNumber, hidePosIfAnon)
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 = {}
}
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 = {}
}
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
local foundPlayer = nil
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)
MySQL.Async.fetchAll(
'SELECT phone_number FROM users WHERE phone_number = @number',
{
['@number'] = phoneNumber
},
function(result)
if result[1] ~= nil then
foundNumber = true
end
if result[1] ~= nil then
foundNumber = true
end
if foundNumber then
if foundNumber then
if phoneNumber == xPlayer.get('phoneNumber') then
TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self'))
else
if phoneNumber == xPlayer.get('phoneNumber') then
TriggerClientEvent('esx:showNotification', _source, _U('cannot_add_self'))
else
local hasAlreadyAdded = false
local contacts = xPlayer.get('contacts')
local hasAlreadyAdded = false
local contacts = xPlayer.get('contacts')
for i=1, #contacts, 1 do
if contacts[i].number == phoneNumber then
hasAlreadyAdded = true
end
end
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
if hasAlreadyAdded then
TriggerClientEvent('esx:showNotification', _source, _U('number_in_contacts'))
else
table.insert(contacts, {
name = contactName,
number = phoneNumber,
})
table.insert(contacts, {
name = contactName,
number = phoneNumber,
})
xPlayer.set('contacts', contacts)
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)
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:showNotification', _source, _U('contact_added'))
TriggerClientEvent('esx_phone:addContact', _source, contactName, phoneNumber)
end
)
TriggerClientEvent('esx_phone:addContact', _source, contactName, phoneNumber)
end
)
end
end
end
end
else
TriggerClientEvent('esx:showNotification', source, _U('number_not_assigned'))
end
else
TriggerClientEvent('esx:showNotification', source, _U('number_not_assigned'))
end
end
)
end
)
end)
RegisterServerEvent('esx_phone:stopDispatch')
AddEventHandler('esx_phone:stopDispatch', function(dispatchRequestId)
TriggerClientEvent('esx_phone:stopDispatch', -1, dispatchRequestId, GetPlayerName(source))
TriggerClientEvent('esx_phone:stopDispatch', -1, dispatchRequestId, GetPlayerName(source))
end)