From 39bd6a80f080dd474aeac3fbfcc0bef9b4f40eee Mon Sep 17 00:00:00 2001 From: Romain Lanz Date: Thu, 14 Sep 2017 16:52:50 +0200 Subject: [PATCH] chore(coding-style): correct indentation --- .editorconfig | 9 ++ __resource.lua | 28 +++--- client/main.lua | 238 ++++++++++++++++++++++++------------------------ locales/br.lua | 10 +- locales/en.lua | 14 ++- locales/fr.lua | 14 ++- server/main.lua | 148 +++++++++++++++--------------- 7 files changed, 230 insertions(+), 231 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 00000000..41c2aaf2 --- /dev/null +++ b/.editorconfig @@ -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 \ No newline at end of file diff --git a/__resource.lua b/__resource.lua index 8321f96c..adf1086e 100644 --- a/__resource.lua +++ b/__resource.lua @@ -3,24 +3,20 @@ resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937' description 'Instance' server_scripts { - - '@es_extended/locale.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fr.lua', - 'config.lua', - 'server/main.lua' - + '@es_extended/locale.lua', + 'locales/br.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'config.lua', + 'server/main.lua' } client_scripts { - - '@es_extended/locale.lua', - 'locales/br.lua', - 'locales/en.lua', - 'locales/fr.lua', - 'config.lua', - 'client/main.lua' - + '@es_extended/locale.lua', + 'locales/br.lua', + 'locales/en.lua', + 'locales/fr.lua', + 'config.lua', + 'client/main.lua' } diff --git a/client/main.lua b/client/main.lua index 9120d0ab..de9a5a3a 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 = {} @@ -18,146 +18,146 @@ local InstancedPlayers = {} local RegisteredInstanceTypes = {} function ShowNotification(msg) - SetNotificationTextEntry('STRING') - AddTextComponentString(msg) - DrawNotification(0, 1) + SetNotificationTextEntry('STRING') + AddTextComponentString(msg) + DrawNotification(0, 1) end function GetInstance() - return Instance + return Instance end function CreateInstance(type, data) - TriggerServerEvent('instance:create', type, data) + TriggerServerEvent('instance:create', type, data) end function CloseInstance() - Instance = {} - TriggerServerEvent('instance:close') + Instance = {} + TriggerServerEvent('instance:close') end function EnterInstance(instance) - - TriggerServerEvent('instance:enter', instance.host) - if RegisteredInstanceTypes[instance.type].enter ~= nil then - RegisteredInstanceTypes[instance.type].enter(instance) - end + TriggerServerEvent('instance:enter', instance.host) + + if RegisteredInstanceTypes[instance.type].enter ~= nil then + RegisteredInstanceTypes[instance.type].enter(instance) + end end function LeaveInstance() - if Instance.host ~= nil then + if Instance.host ~= nil then - if #Instance.players > 1 then - TriggerEvent('esx:showNotification', _U('left_instance')) - end + if #Instance.players > 1 then + TriggerEvent('esx:showNotification', _U('left_instance')) + end - if RegisteredInstanceTypes[Instance.type].exit ~= nil then - RegisteredInstanceTypes[Instance.type].exit(Instance) - end + if RegisteredInstanceTypes[Instance.type].exit ~= nil then + RegisteredInstanceTypes[Instance.type].exit(Instance) + end - TriggerServerEvent('instance:leave', Instance.host) - end + TriggerServerEvent('instance:leave', Instance.host) + end end function InviteToInstance(type, player, data) - TriggerServerEvent('instance:invite', Instance.host, type, player, data) + TriggerServerEvent('instance:invite', Instance.host, type, player, data) end function RegisterInstanceType(type, enter, exit) - RegisteredInstanceTypes[type] = { - enter = enter, - exit = exit - } + RegisteredInstanceTypes[type] = { + enter = enter, + exit = exit + } end AddEventHandler('instance:get', function(cb) - cb(GetInstance()) + cb(GetInstance()) end) AddEventHandler('instance:create', function(type, data) - CreateInstance(type, data) + CreateInstance(type, data) end) AddEventHandler('instance:close', function() - CloseInstance() + CloseInstance() end) AddEventHandler('instance:enter', function(instance) - EnterInstance(instance) + EnterInstance(instance) end) AddEventHandler('instance:leave', function() - LeaveInstance() + LeaveInstance() end) AddEventHandler('instance:invite', function(type, player, data) - InviteToInstance(type, player, data) + InviteToInstance(type, player, data) end) AddEventHandler('instance:registerType', function(name, enter, exit) - RegisterInstanceType(name, enter, exit) + RegisterInstanceType(name, enter, exit) end) RegisterNetEvent('instance:onInstancedPlayersData') AddEventHandler('instance:onInstancedPlayersData', function(instancedPlayers) - InstancedPlayers = instancedPlayers + InstancedPlayers = instancedPlayers end) RegisterNetEvent('instance:onCreate') AddEventHandler('instance:onCreate', function(instance) - Instance = {} + Instance = {} end) RegisterNetEvent('instance:onEnter') AddEventHandler('instance:onEnter', function(instance) - Instance = instance + Instance = instance end) RegisterNetEvent('instance:onLeave') AddEventHandler('instance:onClose', function(instance) - Instance = {} + Instance = {} end) RegisterNetEvent('instance:onClose') AddEventHandler('instance:onClose', function(instance) - Instance = {} + Instance = {} end) RegisterNetEvent('instance:onPlayerEntered') AddEventHandler('instance:onPlayerEntered', function(instance, player) - Instance = instance - ShowNotification(GetPlayerName(GetPlayerFromServerId(player)) .. _('entered_into')) + Instance = instance + ShowNotification(GetPlayerName(GetPlayerFromServerId(player)) .. _('entered_into')) end) RegisterNetEvent('instance:onPlayerLeft') AddEventHandler('instance:onPlayerLeft', function(instance, player) - Instance = instance - ShowNotification(GetPlayerName(GetPlayerFromServerId(player)) .. _('left_out')) + Instance = instance + ShowNotification(GetPlayerName(GetPlayerFromServerId(player)) .. _('left_out')) end) RegisterNetEvent('instance:onInvite') AddEventHandler('instance:onInvite', function(instance, type, data) - InstanceInvite = { - type = type, - host = instance, - data = data - } + InstanceInvite = { + type = type, + host = instance, + data = data + } - Citizen.CreateThread(function() + Citizen.CreateThread(function() - Citizen.Wait(10000) + Citizen.Wait(10000) - if InstanceInvite ~= nil then - ShowNotification(_U('invite_expired')) - InstanceInvite = nil - end + if InstanceInvite ~= nil then + ShowNotification(_U('invite_expired')) + InstanceInvite = nil + end - end) + end) end) @@ -165,111 +165,111 @@ RegisterInstanceType('default') -- Input invites Citizen.CreateThread(function() - while true do + while true do - Wait(0) + Wait(0) - if InstanceInvite ~= nil then - SetTextComponentFormat('STRING') - AddTextComponentString(_U('press_to_enter')) - DisplayHelpTextFromStringLabel(0, 0, 1, -1) - end + if InstanceInvite ~= nil then + SetTextComponentFormat('STRING') + AddTextComponentString(_U('press_to_enter')) + DisplayHelpTextFromStringLabel(0, 0, 1, -1) + end - end + end end) -- Controls Citizen.CreateThread(function() - while true do + while true do - Wait(0) + Wait(0) - if InstanceInvite ~= nil and IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 150 then + if InstanceInvite ~= nil and IsControlPressed(0, Keys['E']) and (GetGameTimer() - GUI.Time) > 150 then - local playerPed = GetPlayerPed(-1) + local playerPed = GetPlayerPed(-1) - EnterInstance(InstanceInvite) + EnterInstance(InstanceInvite) - ShowNotification(_U('entered_instance')) + ShowNotification(_U('entered_instance')) - InstanceInvite = nil - GUI.Time = GetGameTimer() + InstanceInvite = nil + GUI.Time = GetGameTimer() - end + end - end + end end) -- Instance players Citizen.CreateThread(function() - while true do + while true do - Wait(0) + Wait(0) - if Instance.host ~= nil then + if Instance.host ~= nil then - local playerPed = GetPlayerPed(-1) + local playerPed = GetPlayerPed(-1) - for i=0, 32, 1 do + for i=0, 32, 1 do - local found = false + local found = false - for j=1, #Instance.players, 1 do + for j=1, #Instance.players, 1 do - instancePlayer = GetPlayerFromServerId(Instance.players[j]) + instancePlayer = GetPlayerFromServerId(Instance.players[j]) - if i == instancePlayer then - found = true - end + if i == instancePlayer then + found = true + end - end + end - if not found then + if not found then - local otherPlayerPed = GetPlayerPed(i) + local otherPlayerPed = GetPlayerPed(i) - SetEntityLocallyInvisible(otherPlayerPed) - SetEntityNoCollisionEntity(playerPed, otherPlayerPed, true) - end + SetEntityLocallyInvisible(otherPlayerPed) + SetEntityNoCollisionEntity(playerPed, otherPlayerPed, true) + end - end + end - else + else - local playerPed = GetPlayerPed(-1) + local playerPed = GetPlayerPed(-1) - for i=0, 32, 1 do + for i=0, 32, 1 do - local found = false + local found = false - for j=1, #InstancedPlayers, 1 do + for j=1, #InstancedPlayers, 1 do - instancePlayer = GetPlayerFromServerId(InstancedPlayers[j]) + instancePlayer = GetPlayerFromServerId(InstancedPlayers[j]) - if i == instancePlayer then - found = true - end + if i == instancePlayer then + found = true + end - end + end - if found then + if found then - local otherPlayerPed = GetPlayerPed(i) + local otherPlayerPed = GetPlayerPed(i) - SetEntityLocallyInvisible(otherPlayerPed) - SetEntityNoCollisionEntity(playerPed, otherPlayerPed, true) - end + SetEntityLocallyInvisible(otherPlayerPed) + SetEntityNoCollisionEntity(playerPed, otherPlayerPed, true) + end - end + end - end + end - end + end end) Citizen.CreateThread(function() - TriggerEvent('instance:loaded') -end) \ No newline at end of file + TriggerEvent('instance:loaded') +end) diff --git a/locales/br.lua b/locales/br.lua index 47c85b40..180c39f1 100644 --- a/locales/br.lua +++ b/locales/br.lua @@ -1,8 +1,6 @@ Locales['br'] = { - - ['left_instance'] = 'Você deixou a instância', - ['invite_expired'] = 'Convite expirado', - ['press_to_enter'] = 'Pressione ~INPUT_CONTEXT~ para entrar na instância', - ['entered_instance'] = 'Você entrou na instância', - + ['left_instance'] = 'Você deixou a instância', + ['invite_expired'] = 'Convite expirado', + ['press_to_enter'] = 'Pressione ~INPUT_CONTEXT~ para entrar na instância', + ['entered_instance'] = 'Você entrou na instância', } diff --git a/locales/en.lua b/locales/en.lua index 41f01dcb..522e7c03 100644 --- a/locales/en.lua +++ b/locales/en.lua @@ -1,10 +1,8 @@ Locales['en'] = { - - ['left_instance'] = 'you have left the instance', - ['invite_expired'] = 'invite expired', - ['press_to_enter'] = 'press ~INPUT_CONTEXT~ to enter the instance', - ['entered_instance'] = 'you entered the instance', - ['entered_into'] = ' entered the instance', - ['left_out'] = ' left the instance', - + ['left_instance'] = 'you have left the instance', + ['invite_expired'] = 'invite expired', + ['press_to_enter'] = 'press ~INPUT_CONTEXT~ to enter the instance', + ['entered_instance'] = 'you entered the instance', + ['entered_into'] = ' entered the instance', + ['left_out'] = ' left the instance', } diff --git a/locales/fr.lua b/locales/fr.lua index 02a2f407..766bad80 100644 --- a/locales/fr.lua +++ b/locales/fr.lua @@ -1,10 +1,8 @@ Locales['fr'] = { - - ['left_instance'] = 'vous avez quitté l\'instance', - ['invite_expired'] = 'invitation expirée', - ['press_to_enter'] = 'appuyez sur ~INPUT_CONTEXT~ pour entrer dans l\'instance', - ['entered_instance'] = 'vous êtes entré dans l\'instance', - ['entered_into'] = ' est entré dans l\'instance', - ['left_out'] = ' est sorti dans l\'instance', - + ['left_instance'] = 'vous avez quitté l\'instance', + ['invite_expired'] = 'invitation expirée', + ['press_to_enter'] = 'appuyez sur ~INPUT_CONTEXT~ pour entrer dans l\'instance', + ['entered_instance'] = 'vous êtes entré dans l\'instance', + ['entered_into'] = ' est entré dans l\'instance', + ['left_out'] = ' est sorti dans l\'instance', } diff --git a/server/main.lua b/server/main.lua index c461a425..9c5e3c72 100644 --- a/server/main.lua +++ b/server/main.lua @@ -2,142 +2,142 @@ local Instances = {} function GetInstancedPlayers() - local players = {} + local players = {} - for k,v in pairs(Instances) do - for i=1, #v.players, 1 do - table.insert(players, v.players[i]) - end - end + for k,v in pairs(Instances) do + for i=1, #v.players, 1 do + table.insert(players, v.players[i]) + end + end - return players + return players end function CreateInstance(type, player, data) - Instances[player] = { - type = type, - host = player, - players = {}, - data = data - } + Instances[player] = { + type = type, + host = player, + players = {}, + data = data + } - TriggerEvent('instance:onCreate', Instances[player]) - TriggerClientEvent('instance:onCreate', player, Instances[player]) - TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) + TriggerEvent('instance:onCreate', Instances[player]) + TriggerClientEvent('instance:onCreate', player, Instances[player]) + TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) end function CloseInstance(instance) - if Instances[instance] ~= nil then + if Instances[instance] ~= nil then - for i=1, #Instances[instance].players, 1 do - TriggerClientEvent('instance:onClose', Instances[instance].players[i]) - end + for i=1, #Instances[instance].players, 1 do + TriggerClientEvent('instance:onClose', Instances[instance].players[i]) + end - Instances[instance] = nil + Instances[instance] = nil - TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) - TriggerEvent('instance:onClose', instance) - end + TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) + TriggerEvent('instance:onClose', instance) + end end function AddPlayerToInstance(instance, player) - - local found = false - for i=1, #Instances[instance].players, 1 do - if Instances[instance].players[i] == player then - found = true - break - end - end + local found = false - if not found then - table.insert(Instances[instance].players, player) - end + for i=1, #Instances[instance].players, 1 do + if Instances[instance].players[i] == player then + found = true + break + end + end - TriggerClientEvent('instance:onEnter', player, Instances[instance]) + if not found then + table.insert(Instances[instance].players, player) + end - for i=1, #Instances[instance].players, 1 do - if Instances[instance].players[i] ~= player then - TriggerClientEvent('instance:onPlayerEntered', Instances[instance].players[i], Instances[instance], player) - end + TriggerClientEvent('instance:onEnter', player, Instances[instance]) - end + for i=1, #Instances[instance].players, 1 do + if Instances[instance].players[i] ~= player then + TriggerClientEvent('instance:onPlayerEntered', Instances[instance].players[i], Instances[instance], player) + end - TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) + end + + TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) end function RemovePlayerFromInstance(instance, player) - if Instances[instance] ~= nil then + if Instances[instance] ~= nil then - TriggerClientEvent('instance:onLeave', player, Instances[instance]) + TriggerClientEvent('instance:onLeave', player, Instances[instance]) - if Instances[instance].host == player then - - for i=1, #Instances[instance].players, 1 do - if Instances[instance].players[i] ~= player then - TriggerClientEvent('instance:onPlayerLeft', Instances[instance].players[i], Instances[instance], player) - end - end + if Instances[instance].host == player then - CloseInstance(instance) - - else + for i=1, #Instances[instance].players, 1 do + if Instances[instance].players[i] ~= player then + TriggerClientEvent('instance:onPlayerLeft', Instances[instance].players[i], Instances[instance], player) + end + end - for i=1, #Instances[instance].players, 1 do - if Instances[instance].players[i] == player then - Instances[instance].players[i] = nil - end - end + CloseInstance(instance) - for i=1, #Instances[instance].players, 1 do - if Instances[instance].players[i] ~= player then - TriggerClientEvent('instance:onPlayerLeft', Instances[instance].players[i], Instances[instance], player) - end - - end + else - TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) + for i=1, #Instances[instance].players, 1 do + if Instances[instance].players[i] == player then + Instances[instance].players[i] = nil + end + end - end + for i=1, #Instances[instance].players, 1 do + if Instances[instance].players[i] ~= player then + TriggerClientEvent('instance:onPlayerLeft', Instances[instance].players[i], Instances[instance], player) + end - end + end + + TriggerClientEvent('instance:onInstancedPlayersData', -1, GetInstancedPlayers()) + + end + + end end function InvitePlayerToInstance(instance, type, player, data) - TriggerClientEvent('instance:onInvite', player, instance, type, data) + TriggerClientEvent('instance:onInvite', player, instance, type, data) end RegisterServerEvent('instance:create') AddEventHandler('instance:create', function(type, data) - CreateInstance(type, source, data) + CreateInstance(type, source, data) end) RegisterServerEvent('instance:close') AddEventHandler('instance:close', function() - CloseInstance(source) + CloseInstance(source) end) RegisterServerEvent('instance:enter') AddEventHandler('instance:enter', function(instance) - AddPlayerToInstance(instance, source) + AddPlayerToInstance(instance, source) end) RegisterServerEvent('instance:leave') AddEventHandler('instance:leave', function(instance) - RemovePlayerFromInstance(instance, source) + RemovePlayerFromInstance(instance, source) end) RegisterServerEvent('instance:invite') AddEventHandler('instance:invite', function(instance, type, player, data) - InvitePlayerToInstance(instance, type, player, data) + InvitePlayerToInstance(instance, type, player, data) end)