Performance improvments, enforce 2 space indent, vector3 coords

This commit is contained in:
ElPumpo
2019-07-16 11:07:28 +02:00
parent 6e9964a8e2
commit dd436587ae
12 changed files with 158 additions and 210 deletions
+1 -1
View File
@@ -1,6 +1,6 @@
resource_manifest_version '44febabe-d386-4d18-afbe-5e627f4af937'
description 'ESX ClotheShop'
description 'ESX Clothes Shop'
version '1.1.0'
+61 -101
View File
@@ -1,22 +1,7 @@
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
}
ESX = nil
local HasAlreadyEnteredMarker = false
local LastZone = nil
local CurrentAction = nil
local CurrentActionMsg = ''
local CurrentActionData = {}
local HasPaid = false
local hasAlreadyEnteredMarker, hasPaid, currentActionData = false, false, {}
local lastZone, currentAction, currentActionMsg
ESX = nil
Citizen.CreateThread(function()
while ESX == nil do
@@ -26,20 +11,18 @@ Citizen.CreateThread(function()
end)
function OpenShopMenu()
HasPaid = false
hasPaid = false
TriggerEvent('esx_skin:openRestrictedMenu', function(data, menu)
menu.close()
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm',
{
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'shop_confirm', {
title = _U('valid_this_purchase'),
align = 'top-left',
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}
}, function(data, menu)
}}, function(data, menu)
menu.close()
if data.current.value == 'yes' then
@@ -49,19 +32,17 @@ function OpenShopMenu()
TriggerServerEvent('esx_skin:save', skin)
end)
HasPaid = true
hasPaid = true
ESX.TriggerServerCallback('esx_clotheshop:checkPropertyDataStore', function(foundStore)
if foundStore then
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'save_dressing',
{
ESX.UI.Menu.Open('default', GetCurrentResourceName(), 'save_dressing', {
title = _U('save_in_dressing'),
align = 'top-left',
elements = {
{label = _U('no'), value = 'no'},
{label = _U('yes'), value = 'yes'}
}
}, function(data2, menu2)
}}, function(data2, menu2)
menu2.close()
if data2.current.value == 'yes' then
@@ -72,9 +53,8 @@ function OpenShopMenu()
TriggerEvent('skinchanger:getSkin', function(skin)
TriggerServerEvent('esx_clotheshop:saveOutfit', data3.value, skin)
ESX.ShowNotification(_U('saved_outfit'))
end)
ESX.ShowNotification(_U('saved_outfit'))
end, function(data3, menu3)
menu3.close()
end)
@@ -97,56 +77,47 @@ function OpenShopMenu()
end)
end
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_menu')
CurrentActionData = {}
currentAction = 'shop_menu'
currentActionMsg = _U('press_menu')
currentActionData = {}
end, function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_menu')
CurrentActionData = {}
currentAction = 'shop_menu'
currentActionMsg = _U('press_menu')
currentActionData = {}
end)
end, function(data, menu)
menu.close()
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_menu')
CurrentActionData = {}
currentAction = 'shop_menu'
currentActionMsg = _U('press_menu')
currentActionData = {}
end, {
'tshirt_1',
'tshirt_2',
'torso_1',
'torso_2',
'decals_1',
'decals_2',
'tshirt_1', 'tshirt_2',
'torso_1', 'torso_2',
'decals_1', 'decals_2',
'arms',
'pants_1',
'pants_2',
'shoes_1',
'shoes_2',
'chain_1',
'chain_2',
'helmet_1',
'helmet_2',
'glasses_1',
'glasses_2'
'pants_1', 'pants_2',
'shoes_1', 'shoes_2',
'chain_1', 'chain_2',
'helmet_1', 'helmet_2',
'glasses_1', 'glasses_2'
})
end
AddEventHandler('esx_clotheshop:hasEnteredMarker', function(zone)
CurrentAction = 'shop_menu'
CurrentActionMsg = _U('press_menu')
CurrentActionData = {}
currentAction = 'shop_menu'
currentActionMsg = _U('press_menu')
currentActionData = {}
end)
AddEventHandler('esx_clotheshop:hasExitedMarker', function(zone)
ESX.UI.Menu.CloseAll()
CurrentAction = nil
currentAction = nil
if not HasPaid then
if not hasPaid then
TriggerEvent('esx_skin:getLastSkin', function(skin)
TriggerEvent('skinchanger:loadSkin', skin)
end)
@@ -155,61 +126,50 @@ end)
-- Create Blips
Citizen.CreateThread(function()
for i=1, #Config.Shops, 1 do
local blip = AddBlipForCoord(Config.Shops[i].x, Config.Shops[i].y, Config.Shops[i].z)
for k,v in ipairs(Config.Shops) do
local blip = AddBlipForCoord(v)
SetBlipSprite (blip, 73)
SetBlipDisplay(blip, 4)
SetBlipScale (blip, 1.0)
SetBlipColour (blip, 47)
SetBlipAsShortRange(blip, true)
BeginTextCommandSetBlipName("STRING")
AddTextComponentString(_U('clothes'))
BeginTextCommandSetBlipName('STRING')
AddTextComponentSubstringPlayerName(_U('clothes'))
EndTextCommandSetBlipName(blip)
end
end)
-- Display markers
-- Enter / Exit marker events & draw markers
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
Citizen.Wait(0)
local playerCoords, isInMarker, currentZone, letSleep = GetEntityCoords(PlayerPedId()), false, nil, true
local coords = GetEntityCoords(PlayerPedId())
for k,v in pairs(Config.Shops) do
local distance = #(playerCoords - v)
for k,v in pairs(Config.Zones) do
if(v.Type ~= -1 and GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < Config.DrawDistance) then
DrawMarker(v.Type, v.Pos.x, v.Pos.y, v.Pos.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, v.Size.x, v.Size.y, v.Size.z, v.Color.r, v.Color.g, v.Color.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
if distance < Config.DrawDistance then
letSleep = false
DrawMarker(Config.MarkerType, v, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z, Config.MarkerColor.r, Config.MarkerColor.g, Config.MarkerColor.b, 100, false, true, 2, false, nil, nil, false)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(100)
local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentZone = nil
for k,v in pairs(Config.Zones) do
if(GetDistanceBetweenCoords(coords, v.Pos.x, v.Pos.y, v.Pos.z, true) < v.Size.x) then
isInMarker = true
currentZone = k
if distance < Config.MarkerSize.x then
isInMarker, currentZone = true, k
end
end
end
if (isInMarker and not HasAlreadyEnteredMarker) or (isInMarker and LastZone ~= currentZone) then
HasAlreadyEnteredMarker = true
LastZone = currentZone
if (isInMarker and not hasAlreadyEnteredMarker) or (isInMarker and lastZone ~= currentZone) then
hasAlreadyEnteredMarker, lastZone = true, currentZone
TriggerEvent('esx_clotheshop:hasEnteredMarker', currentZone)
end
if not isInMarker and HasAlreadyEnteredMarker then
HasAlreadyEnteredMarker = false
TriggerEvent('esx_clotheshop:hasExitedMarker', LastZone)
if not isInMarker and hasAlreadyEnteredMarker then
hasAlreadyEnteredMarker = false
TriggerEvent('esx_clotheshop:hasExitedMarker', lastZone)
end
if letSleep then
Citizen.Wait(500)
end
end
end)
@@ -219,15 +179,15 @@ Citizen.CreateThread(function()
while true do
Citizen.Wait(0)
if CurrentAction ~= nil then
ESX.ShowHelpNotification(CurrentActionMsg)
if currentAction then
ESX.ShowHelpNotification(currentActionMsg)
if IsControlJustReleased(0, Keys['E']) then
if CurrentAction == 'shop_menu' then
if IsControlJustReleased(0, 38) then
if currentAction == 'shop_menu' then
OpenShopMenu()
end
CurrentAction = nil
currentAction = nil
end
else
Citizen.Wait(500)
+15 -26
View File
@@ -8,30 +8,19 @@ Config.MarkerSize = {x = 1.5, y = 1.5, z = 1.0}
Config.MarkerColor = {r = 102, g = 102, b = 204}
Config.MarkerType = 1
Config.Zones = {}
Config.Shops = {
{x=72.254, y=-1399.102, z=28.376},
{x=-703.776, y=-152.258, z=36.415},
{x=-167.863, y=-298.969, z=38.733},
{x=428.694, y=-800.106, z=28.491},
{x=-829.413, y=-1073.710, z=10.328},
{x=-1447.797, y=-242.461, z=48.820},
{x=11.632, y=6514.224, z=30.877},
{x=123.646, y=-219.440, z=53.557},
{x=1696.291, y=4829.312, z=41.063},
{x=618.093, y=2759.629, z=41.088},
{x=1190.550, y=2713.441, z=37.222},
{x=-1193.429, y=-772.262, z=16.324},
{x=-3172.496, y=1048.133, z=19.863},
{x=-1108.441, y=2708.923, z=18.107}
}
for i=1, #Config.Shops, 1 do
Config.Zones['Shop_' .. i] = {
Pos = Config.Shops[i],
Size = Config.MarkerSize,
Color = Config.MarkerColor,
Type = Config.MarkerType
}
end
vector3(72.3, -1399.1, 28.4),
vector3(-703.8, -152.3, 36.4),
vector3(-167.9, -299.0, 38.7),
vector3(428.7, -800.1, 28.5),
vector3(-829.4, -1073.7, 10.3),
vector3(-1447.8, -242.5, 48.8),
vector3(11.6, 6514.2, 30.9),
vector3(123.6, -219.4, 53.6),
vector3(1696.3, 4829.3, 41.1),
vector3(618.1, 2759.6, 41.1),
vector3(1190.6, 2713.4, 37.2),
vector3(-1193.4, -772.3, 16.3),
vector3(-3172.5, 1048.1, 19.9),
vector3(-1108.4, 2708.9, 18.1)
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['br'] = {
['valid_this_purchase'] = 'validar esta compra?',
['yes'] = 'sim',
['no'] = 'não',
['not_enough_money'] = 'você não tem dinheiro suficiente',
['press_menu'] = 'pressione ~INPUT_CONTEXT~ para acessar o menu',
['clothes'] = 'roupas',
['you_paid'] = 'você pagou ~g~$%s~s~',
['save_in_dressing'] = 'você quer salvar essa roupa?',
['name_outfit'] = 'nome da roupa?',
['saved_outfit'] = 'roupa salva',
['valid_this_purchase'] = 'validar esta compra?',
['yes'] = 'sim',
['no'] = 'não',
['not_enough_money'] = 'você não tem dinheiro suficiente',
['press_menu'] = 'pressione ~INPUT_CONTEXT~ para acessar o menu',
['clothes'] = 'roupas',
['you_paid'] = 'você pagou ~g~$%s~s~',
['save_in_dressing'] = 'você quer salvar essa roupa?',
['name_outfit'] = 'nome da roupa?',
['saved_outfit'] = 'roupa salva',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['de'] = {
['valid_this_purchase'] = 'einkauf bestätigen?',
['yes'] = 'ja',
['no'] = 'nein',
['not_enough_money'] = 'du hast nicht genug Geld',
['press_menu'] = 'drücke ~INPUT_CONTEXT~ um das Menü zu öffnen',
['clothes'] = 'kleidung',
['you_paid'] = 'du bezahlst ~g~$%s~s~',
['save_in_dressing'] = 'do you want to save the outfit in your property?',
['name_outfit'] = 'name des outfits?',
['saved_outfit'] = 'the outfit has been saved!',
['valid_this_purchase'] = 'einkauf bestätigen?',
['yes'] = 'ja',
['no'] = 'nein',
['not_enough_money'] = 'du hast nicht genug Geld',
['press_menu'] = 'drücke ~INPUT_CONTEXT~ um das Menü zu öffnen',
['clothes'] = 'kleidung',
['you_paid'] = 'du bezahlst ~g~$%s~s~',
['save_in_dressing'] = 'do you want to save the outfit in your property?',
['name_outfit'] = 'name des outfits?',
['saved_outfit'] = 'the outfit has been saved!',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['en'] = {
['valid_this_purchase'] = 'validate this purchase?',
['yes'] = 'yes',
['no'] = 'no',
['not_enough_money'] = 'you do not have enough money',
['press_menu'] = 'press ~INPUT_CONTEXT~ to access the menu',
['clothes'] = 'clothes',
['you_paid'] = 'you paid ~g~$%s~s~',
['save_in_dressing'] = 'do you want to save the outfit in your property?',
['name_outfit'] = 'name your outfit',
['saved_outfit'] = 'the outfit has been saved!',
['valid_this_purchase'] = 'validate this purchase?',
['yes'] = 'yes',
['no'] = 'no',
['not_enough_money'] = 'you do not have enough money',
['press_menu'] = 'press ~INPUT_CONTEXT~ to access the ~y~Clothing Shop~s~.',
['clothes'] = 'clothing Shop',
['you_paid'] = 'you paid ~g~$%s~s~',
['save_in_dressing'] = 'do you want to save the outfit in your property?',
['name_outfit'] = 'name your outfit',
['saved_outfit'] = 'the outfit has been saved!',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['es'] = {
['valid_this_purchase'] = '¿Validar esta compra?',
['yes'] = 'Si',
['no'] = 'No',
['not_enough_money'] = 'No tienes suficiente dinero',
['press_menu'] = 'Presiona ~INPUT_CONTEXT~ para acceder al menú',
['clothes'] = 'Ropa',
['you_paid'] = 'Has pagado ~g~€%s~s~',
['save_in_dressing'] = '¿Quieres darle un nombre a tu vestuario?',
['name_outfit'] = 'nombre del traje?',
['saved_outfit'] = 'the outfit has been saved!',
['valid_this_purchase'] = '¿Validar esta compra?',
['yes'] = 'Si',
['no'] = 'No',
['not_enough_money'] = 'No tienes suficiente dinero',
['press_menu'] = 'Presiona ~INPUT_CONTEXT~ para acceder al menú',
['clothes'] = 'Ropa',
['you_paid'] = 'Has pagado ~g~€%s~s~',
['save_in_dressing'] = '¿Quieres darle un nombre a tu vestuario?',
['name_outfit'] = 'nombre del traje?',
['saved_outfit'] = 'the outfit has been saved!',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['fi'] = {
['valid_this_purchase'] = 'varmista tämä ostos?',
['yes'] = 'kyllä',
['no'] = 'ei',
['not_enough_money'] = 'sinulla ei ole tarpeeksi rahaa',
['press_menu'] = 'paina ~INPUT_CONTEXT~ avataksesi menu',
['clothes'] = 'vaatekauppa',
['you_paid'] = 'sinä maksoit ~g~$%s~s~',
['save_in_dressing'] = 'haluatko antaa nimen asulle ?',
['name_outfit'] = 'asun nimi?',
['saved_outfit'] = 'the outfit has been saved!',
['valid_this_purchase'] = 'varmista tämä ostos?',
['yes'] = 'kyllä',
['no'] = 'ei',
['not_enough_money'] = 'sinulla ei ole tarpeeksi rahaa',
['press_menu'] = 'paina ~INPUT_CONTEXT~ avataksesi menu',
['clothes'] = 'vaatekauppa',
['you_paid'] = 'sinä maksoit ~g~$%s~s~',
['save_in_dressing'] = 'haluatko antaa nimen asulle ?',
['name_outfit'] = 'asun nimi?',
['saved_outfit'] = 'the outfit has been saved!',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['fr'] = {
['valid_this_purchase'] = 'valider cet achat ?',
['yes'] = 'oui',
['no'] = 'non',
['not_enough_money'] = 'vous n\'avez pas assez d\'argent',
['press_menu'] = 'appuyez sur ~INPUT_CONTEXT~ pour accéder au menu',
['clothes'] = 'vêtements',
['you_paid'] = 'vous avez payé ~g~$%s~s~',
['save_in_dressing'] = 'voulez-vous donner un nom à votre tenue?',
['name_outfit'] = 'nom de la tenue?',
['saved_outfit'] = 'the outfit has been saved!',
['valid_this_purchase'] = 'valider cet achat ?',
['yes'] = 'oui',
['no'] = 'non',
['not_enough_money'] = 'vous n\'avez pas assez d\'argent',
['press_menu'] = 'appuyez sur ~INPUT_CONTEXT~ pour accéder au menu',
['clothes'] = 'vêtements',
['you_paid'] = 'vous avez payé ~g~$%s~s~',
['save_in_dressing'] = 'voulez-vous donner un nom à votre tenue?',
['name_outfit'] = 'nom de la tenue?',
['saved_outfit'] = 'the outfit has been saved!',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['pl'] = {
['valid_this_purchase'] = 'potwierdzić ten zakup?',
['yes'] = 'tak',
['no'] = 'nie',
['not_enough_money'] = 'nie masz wystarczająco pieniędzy',
['press_menu'] = 'naciśnij ~INPUT_CONTEXT~ aby uzyskać dostęp do menu.',
['clothes'] = 'ubranie',
['you_paid'] = 'płacisz ~g~%s $~s~',
['save_in_dressing'] = 'czy chcesz zapisać te ubranie w swojej posiadłości?',
['name_outfit'] = 'nazwij swój strój',
['saved_outfit'] = 'strój został zapisany!',
['valid_this_purchase'] = 'potwierdzić ten zakup?',
['yes'] = 'tak',
['no'] = 'nie',
['not_enough_money'] = 'nie masz wystarczająco pieniędzy',
['press_menu'] = 'naciśnij ~INPUT_CONTEXT~ aby uzyskać dostęp do menu.',
['clothes'] = 'ubranie',
['you_paid'] = 'płacisz ~g~%s $~s~',
['save_in_dressing'] = 'czy chcesz zapisać te ubranie w swojej posiadłości?',
['name_outfit'] = 'nazwij swój strój',
['saved_outfit'] = 'strój został zapisany!',
}
+10 -10
View File
@@ -1,12 +1,12 @@
Locales['sv'] = {
['valid_this_purchase'] = 'vill du köpa dessa kläder?',
['yes'] = 'ja',
['no'] = 'nej',
['not_enough_money'] = 'du har ~r~inte råd~s~ för att köpa detta',
['press_menu'] = 'tryck ~INPUT_CONTEXT~ för att komma åt menyn',
['clothes'] = 'kläder',
['you_paid'] = 'du har betalat ~g~$%s~s~',
['save_in_dressing'] = 'vill du spara outfiten i din fastighet?',
['name_outfit'] = 'vad ska din outfit heta?',
['saved_outfit'] = 'outfit har sparats!',
['valid_this_purchase'] = 'vill du köpa dessa kläder?',
['yes'] = 'ja',
['no'] = 'nej',
['not_enough_money'] = 'du har ~r~inte råd~s~ för att köpa detta',
['press_menu'] = 'tryck ~INPUT_CONTEXT~ för att öppna ~y~klädesaffären~s~.',
['clothes'] = 'klädesaffär',
['you_paid'] = 'du har betalat ~g~$%s~s~',
['save_in_dressing'] = 'vill du spara outfiten i din fastighet?',
['name_outfit'] = 'vad ska din outfit heta?',
['saved_outfit'] = 'outfit har sparats!',
}
+1 -2
View File
@@ -4,8 +4,7 @@ TriggerEvent('esx:getSharedObject', function(obj) ESX = obj end)
RegisterServerEvent('esx_clotheshop:saveOutfit')
AddEventHandler('esx_clotheshop:saveOutfit', function(label, skin)
local _source = source
local xPlayer = ESX.GetPlayerFromId(_source)
local xPlayer = ESX.GetPlayerFromId(source)
TriggerEvent('esx_datastore:getDataStore', 'property', xPlayer.identifier, function(store)
local dressing = store.get('dressing')