Not saying you’re incorrect but, what is the usage difference between using Citizen.Wait and Wait performance wise?
Edit:
Seems like there are far better suggestions you could make like using faster alternative of GetDistanceBetweenCoords
-- language faster equivalent:
local firstVec = vector3(0.0, 0.0, 0.0)
local secondVec = vector3(5.0, 5.0, 5.0)
local dist = #(firstVec - secondVec) -- Use Z
local dist = #(firstVec.xy - secondVec.xy) -- Do not use Z
This wild senseless loop probably causing the 0.01 usage:
Citizen.CreateThread(function()
while true do
Citizen.Wait(500)
if ESX ~= nil then
PlayerData = ESX.GetPlayerData()
PlayerJob = PlayerData.job.name
PlayerGrade = PlayerData.job.grade
end
end
end)
Or the fact that it’s triggering depreciated trigger to get ESX object that is no longer used in latest ESX versions(Better change for both below)
PlayerData = nil
PlayerJob = nil
PlayerGrade = nil
ESX = exports["es_extended"]:getSharedObject()
RegisterNetEvent('esx:playerLoaded')
AddEventHandler('esx:playerLoaded', function(xPlayer)
PlayerData = xPlayer
PlayerJob = xPlayer.job.name
PlayerGrade = xPlayer.job.grade
end)
RegisterNetEvent('esx:setJob')
AddEventHandler('esx:setJob', function(job)
PlayerJob = job.name
PlayerGrade = job.grade
end)
I mean you’re pointing out Citizen.Wait over Wait and there’s this loop checking coords every frame for no reason:
CreateThread(function()
while true do
Citizen.Wait(0)
_menuPool:ProcessMenus()
for elevatorName, elevatorFloors in pairs(Config.Elevator) do
for index, floor in pairs(elevatorFloors) do
local pedCoords = GetEntityCoords(PlayerPedId())
local distance = GetDistanceBetweenCoords(pedCoords.x, pedCoords.y, pedCoords.z, floor.coords.x, floor.coords.y, floor.coords.z, true)
if distance <= Config.MarkerDistance then
DrawMarker(floor.marker.type, floor.coords.x, floor.coords.y, floor.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, floor.marker.scale, floor.marker.scale, floor.marker.height, floor.marker.r, floor.marker.g, floor.marker.b, floor.marker.a, false, false, 2, nil, nil, true)
end
if distance <= floor.marker.scale / 1.35 then
SetTextComponentFormat("STRING")
AddTextComponentString(floor.text)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlJustReleased(1, Config.Key) then
showUI(elevatorName, floor.coords.x, floor.coords.y, floor.coords.z)
end
end
end
end
end
end)
Much better suggestion than Wait replacement would be changing that nasty loop to something like this:
CreateThread(function()
while true do
local sleep = 1500
_menuPool:ProcessMenus()
for elevatorName, elevatorFloors in pairs(Config.Elevator) do
for index, floor in pairs(elevatorFloors) do
local pedCoords = GetEntityCoords(PlayerPedId())
local distance = #(pedCoords - vector3(floor.coords.x, floor.coords.y, floor.coords.z))
if distance <= Config.MarkerDistance then
sleep = 0
DrawMarker(floor.marker.type, floor.coords.x, floor.coords.y, floor.coords.z, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, floor.marker.scale, floor.marker.scale, floor.marker.height, floor.marker.r, floor.marker.g, floor.marker.b, floor.marker.a, false, false, 2, nil, nil, true)
end
if distance <= floor.marker.scale / 1.35 then
sleep = 0
SetTextComponentFormat("STRING")
AddTextComponentString(floor.text)
DisplayHelpTextFromStringLabel(0, 0, 1, -1)
if IsControlJustReleased(1, Config.Key) then
showUI(elevatorName, floor.coords.x, floor.coords.y, floor.coords.z)
end
end
end
end
Wait(sleep)
end
end)
There, now both have extra knowledge