Improve performance by merging functions

This commit is contained in:
ElPumpo
2019-01-15 23:07:13 +01:00
parent bfc3929136
commit bdb808583a
+51 -65
View File
@@ -69,7 +69,7 @@ function CreateBlips()
for i=1, #Config.Properties, 1 do for i=1, #Config.Properties, 1 do
local property = Config.Properties[i] local property = Config.Properties[i]
if property.entering ~= nil then if property.entering then
Blips[property.name] = AddBlipForCoord(property.entering.x, property.entering.y, property.entering.z) Blips[property.name] = AddBlipForCoord(property.entering.x, property.entering.y, property.entering.z)
SetBlipSprite (Blips[property.name], 369) SetBlipSprite (Blips[property.name], 369)
@@ -225,7 +225,7 @@ function SetPropertyOwned(name, owned)
local _property = GetProperty(k) local _property = GetProperty(k)
local _gateway = GetGateway(_property) local _gateway = GetGateway(_property)
if _gateway ~= nil then if _gateway then
if _gateway.name == enteringName then if _gateway.name == enteringName then
found = true found = true
break break
@@ -749,7 +749,7 @@ AddEventHandler('playerSpawned', function()
end end
ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName) ESX.TriggerServerCallback('esx_property:getLastProperty', function(propertyName)
if propertyName ~= nil then if propertyName then
if propertyName ~= '' then if propertyName ~= '' then
local property = GetProperty(propertyName) local property = GetProperty(propertyName)
@@ -850,76 +850,64 @@ AddEventHandler('esx_property:hasExitedMarker', function(name, part)
CurrentAction = nil CurrentAction = nil
end) end)
-- Display markers -- Enter / Exit marker events & Draw markers
Citizen.CreateThread(function() Citizen.CreateThread(function()
while true do while true do
Citizen.Wait(0)
Citizen.Wait(1)
local coords = GetEntityCoords(PlayerPedId()) local coords = GetEntityCoords(PlayerPedId())
local isInMarker, letSleep = false, true
for i=1, #Config.Properties, 1 do local currentProperty, currentPart
local property = Config.Properties[i]
local isHost = false
if(property.entering ~= nil and not property.disabled and GetDistanceBetweenCoords(coords, property.entering.x, property.entering.y, property.entering.z, true) < Config.DrawDistance) then
DrawMarker(Config.MarkerType, property.entering.x, property.entering.y, property.entering.z, 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, false, false, false)
end
if(property.exit ~= nil and not property.disabled and GetDistanceBetweenCoords(coords, property.exit.x, property.exit.y, property.exit.z, true) < Config.DrawDistance) then
DrawMarker(Config.MarkerType, property.exit.x, property.exit.y, property.exit.z, 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, false, false, false)
end
if(property.roomMenu ~= nil and HasChest and not property.disabled and GetDistanceBetweenCoords(coords, property.roomMenu.x, property.roomMenu.y, property.roomMenu.z, true) < Config.DrawDistance) then
DrawMarker(Config.MarkerType, property.roomMenu.x, property.roomMenu.y, property.roomMenu.z, 0.0, 0.0, 0.0, 0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z, Config.RoomMenuMarkerColor.r, Config.RoomMenuMarkerColor.g, Config.RoomMenuMarkerColor.b, 100, false, true, 2, false, false, false, false)
end
end
end
end)
-- Enter / Exit marker events
Citizen.CreateThread(function()
while true do
Citizen.Wait(1)
local coords = GetEntityCoords(PlayerPedId())
local isInMarker = false
local currentProperty = nil
local currentPart = nil
for i=1, #Config.Properties, 1 do for i=1, #Config.Properties, 1 do
local property = Config.Properties[i] local property = Config.Properties[i]
if(property.entering ~= nil and not property.disabled and GetDistanceBetweenCoords(coords, property.entering.x, property.entering.y, property.entering.z, true) < Config.MarkerSize.x) then -- Entering
isInMarker = true if property.entering and not property.disabled then
currentProperty = property.name local distance = GetDistanceBetweenCoords(coords, property.entering.x, property.entering.y, property.entering.z, true)
currentPart = 'entering'
if distance < Config.DrawDistance then
DrawMarker(Config.MarkerType, property.entering.x, property.entering.y, property.entering.z, 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)
letSleep = false
end
if distance < Config.MarkerSize.x then
isInMarker = true
currentProperty = property.name
currentPart = 'entering'
end
end end
if(property.exit ~= nil and not property.disabled and GetDistanceBetweenCoords(coords, property.exit.x, property.exit.y, property.exit.z, true) < Config.MarkerSize.x) then -- Exit
isInMarker = true if property.exit and not property.disabled then
currentProperty = property.name local distance = GetDistanceBetweenCoords(coords, property.exit.x, property.exit.y, property.exit.z, true)
currentPart = 'exit'
if distance < Config.DrawDistance then
DrawMarker(Config.MarkerType, property.exit.x, property.exit.y, property.exit.z, 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)
letSleep = false
end
if distance < Config.MarkerSize.x then
isInMarker = true
currentProperty = property.name
currentPart = 'exit'
end
end end
if(property.inside ~= nil and not property.disabled and GetDistanceBetweenCoords(coords, property.inside.x, property.inside.y, property.inside.z, true) < Config.MarkerSize.x) then -- Room menu
isInMarker = true if property.roomMenu and HasChest and not property.disabled then
currentProperty = property.name local distance = GetDistanceBetweenCoords(coords, property.roomMenu.x, property.roomMenu.y, property.roomMenu.z, true)
currentPart = 'inside'
end
if(property.outside ~= nil and not property.disabled and GetDistanceBetweenCoords(coords, property.outside.x, property.outside.y, property.outside.z, true) < Config.MarkerSize.x) then if distance < Config.DrawDistance then
isInMarker = true DrawMarker(Config.MarkerType, property.roomMenu.x, property.roomMenu.y, property.roomMenu.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Config.MarkerSize.x, Config.MarkerSize.y, Config.MarkerSize.z, Config.RoomMenuMarkerColor.r, Config.RoomMenuMarkerColor.g, Config.RoomMenuMarkerColor.b, 100, false, true, 2, false, nil, nil, false)
currentProperty = property.name letSleep = false
currentPart = 'outside' end
end
if(property.roomMenu ~= nil and HasChest and not property.disabled and GetDistanceBetweenCoords(coords, property.roomMenu.x, property.roomMenu.y, property.roomMenu.z, true) < Config.MarkerSize.x) then if distance < Config.MarkerSize.x then
isInMarker = true isInMarker = true
currentProperty = property.name currentProperty = property.name
currentPart = 'roomMenu' currentPart = 'roomMenu'
end
end end
end end
@@ -936,7 +924,7 @@ Citizen.CreateThread(function()
TriggerEvent('esx_property:hasExitedMarker', LastProperty, LastPart) TriggerEvent('esx_property:hasExitedMarker', LastProperty, LastPart)
end end
if not isInMarker and not HasAlreadyEnteredMarker then if letSleep then
Citizen.Wait(500) Citizen.Wait(500)
end end
end end
@@ -945,11 +933,9 @@ end)
-- Key controls -- Key controls
Citizen.CreateThread(function() Citizen.CreateThread(function()
while true do while true do
Citizen.Wait(0) Citizen.Wait(0)
if CurrentAction ~= nil then if CurrentAction then
ESX.ShowHelpNotification(CurrentActionMsg) ESX.ShowHelpNotification(CurrentActionMsg)
if IsControlJustReleased(0, Keys['E']) then if IsControlJustReleased(0, Keys['E']) then
@@ -969,9 +955,9 @@ Citizen.CreateThread(function()
end end
CurrentAction = nil CurrentAction = nil
end
else -- no current action, sleep mode end
else
Citizen.Wait(500) Citizen.Wait(500)
end end
end end