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
+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)