Merge pull request #1651 from Meyndflay/feature

feat(es_extended): Optimize Tracking Of Ped Coords
This commit is contained in:
Kenshin13
2025-07-06 16:19:56 +02:00
committed by GitHub
3 changed files with 45 additions and 5 deletions
+1
View File
@@ -0,0 +1 @@
.DS_Store
+20 -5
View File
@@ -33,11 +33,26 @@ function Actions:SetVehicleStatus()
ESX.SetPlayerData("seat", self.seat)
end
function Actions:TrackPedCoords()
local playerPed = ESX.PlayerData.ped
local coords = GetEntityCoords(playerPed)
function Actions:TrackPedCoordsOnce()
CreateThread(function()
while not ESX.IsPlayerLoaded() do
Wait(250)
end
ESX.SetPlayerData("coords", coords)
ESX.PlayerData.coords = nil
setmetatable(ESX.PlayerData, {
__index = function(_, key)
if key ~= "coords" then
return
end
local coords = GetEntityCoords(ESX.PlayerData.ped)
return coords
end
})
end)
end
function Actions:TrackPed()
@@ -193,7 +208,6 @@ end
function Actions:SlowLoop()
CreateThread(function()
while ESX.PlayerLoaded do
self:TrackPedCoords()
self:TrackPauseMenu()
self:TrackVehicle()
self:TrackWeapon()
@@ -214,6 +228,7 @@ end
function Actions:Init()
self:SlowLoop()
self:PedLoop()
self:TrackPedCoordsOnce()
end
Actions:Init()
+24
View File
@@ -3,6 +3,26 @@ ESX.currentResourceName = GetCurrentResourceName()
OnPlayerData = function (key, val, last) end
local function TrackPedCoordsOnce()
if not ESX or not ESX.PlayerData then
return
end
ESX.PlayerData.coords = nil
setmetatable(ESX.PlayerData, {
__index = function(self, key)
if key ~= "coords" then
return
end
local coords = GetEntityCoords(ESX.PlayerData.ped)
return coords
end
})
end
if not IsDuplicityVersion() then -- Only register this event for the client
AddEventHandler("esx:setPlayerData", function(key, val, last)
if GetInvokingResource() == "es_extended" then
@@ -17,8 +37,12 @@ if not IsDuplicityVersion() then -- Only register this event for the client
ESX.PlayerData = xPlayer
while not ESX.PlayerData.ped or not DoesEntityExist(ESX.PlayerData.ped) do Wait(0) end
ESX.PlayerLoaded = true
TrackPedCoordsOnce()
end)
TrackPedCoordsOnce()
ESX.SecureNetEvent("esx:onPlayerLogout", function()
ESX.PlayerLoaded = false
ESX.PlayerData = {}