From 5aedcd0c33064951ee7034346b1d993938c901fd Mon Sep 17 00:00:00 2001 From: Meyndflay Date: Mon, 9 Jun 2025 18:44:13 +0800 Subject: [PATCH 1/8] feat(es_extended): Optimize Tracking Of Ped Coords --- [core]/es_extended/client/modules/actions.lua | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/[core]/es_extended/client/modules/actions.lua b/[core]/es_extended/client/modules/actions.lua index 98b864b1..8308c017 100644 --- a/[core]/es_extended/client/modules/actions.lua +++ b/[core]/es_extended/client/modules/actions.lua @@ -40,6 +40,28 @@ function Actions:TrackPedCoords() ESX.SetPlayerData("coords", coords) end +function Actions:TrackPedCoordsOnce() + CreateThread(function() + while not ESX.IsPlayerLoaded() then + Wait(250) + 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 { x = coords.x, y = coords.y, z = coords.z } + end + }) + end) +end + function Actions:TrackPed() local playerPed = ESX.PlayerData.ped local newPed = PlayerPedId() @@ -193,7 +215,7 @@ end function Actions:SlowLoop() CreateThread(function() while ESX.PlayerLoaded do - self:TrackPedCoords() + -- self:TrackPedCoords() self:TrackPauseMenu() self:TrackVehicle() self:TrackWeapon() @@ -217,3 +239,4 @@ function Actions:Init() end Actions:Init() +Actions:TrackPedCoordsOnce() From fab7f88910a8dc3464e01f649d82eeaeebe9cbd0 Mon Sep 17 00:00:00 2001 From: Meyndflay Date: Mon, 9 Jun 2025 19:04:09 +0800 Subject: [PATCH 2/8] refactor(es_extended/client/modules/actions.lua): Return Raw Vector Coords for Actions:TrackPedCoordsOnce() --- [core]/es_extended/client/modules/actions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[core]/es_extended/client/modules/actions.lua b/[core]/es_extended/client/modules/actions.lua index 8308c017..ea54afb1 100644 --- a/[core]/es_extended/client/modules/actions.lua +++ b/[core]/es_extended/client/modules/actions.lua @@ -56,7 +56,7 @@ function Actions:TrackPedCoordsOnce() local coords = GetEntityCoords(ESX.PlayerData.ped) - return { x = coords.x, y = coords.y, z = coords.z } + return coords end }) end) From c10097df4f175c045f6d21d516f98cd549ca2f9a Mon Sep 17 00:00:00 2001 From: Meyndflay Date: Mon, 9 Jun 2025 20:23:44 +0800 Subject: [PATCH 3/8] fix(es_extended/client/modules/actions.lua) Fix Syntax Error --- [core]/es_extended/client/modules/actions.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/[core]/es_extended/client/modules/actions.lua b/[core]/es_extended/client/modules/actions.lua index ea54afb1..c021f350 100644 --- a/[core]/es_extended/client/modules/actions.lua +++ b/[core]/es_extended/client/modules/actions.lua @@ -42,7 +42,7 @@ end function Actions:TrackPedCoordsOnce() CreateThread(function() - while not ESX.IsPlayerLoaded() then + while not ESX.IsPlayerLoaded() do Wait(250) end From fe456264a586daab729b7490fd2a81239c8527a4 Mon Sep 17 00:00:00 2001 From: Meyndflay Date: Thu, 12 Jun 2025 07:23:44 +0800 Subject: [PATCH 4/8] fix(es_extended/imports.lua): Update Metatable On Imports --- .gitignore | 1 + [core]/es_extended/imports.lua | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..e43b0f98 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.DS_Store diff --git a/[core]/es_extended/imports.lua b/[core]/es_extended/imports.lua index 719d0623..91d5f887 100644 --- a/[core]/es_extended/imports.lua +++ b/[core]/es_extended/imports.lua @@ -3,7 +3,28 @@ ESX.currentResourceName = GetCurrentResourceName() OnPlayerData = function (key, val, last) end +local function TrackPedCoordsOnce() + 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 + -- On Resource Start + local OnStart = (function() + TrackPedCoordsOnce() + end)() + AddEventHandler("esx:setPlayerData", function(key, val, last) if GetInvokingResource() == "es_extended" then ESX.PlayerData[key] = val @@ -17,6 +38,8 @@ 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) ESX.SecureNetEvent("esx:onPlayerLogout", function() From b17ec840713eda633a74126a0b2eb70a95b3a41e Mon Sep 17 00:00:00 2001 From: Meyndflay Date: Thu, 12 Jun 2025 07:37:31 +0800 Subject: [PATCH 5/8] fix(es_extended/imports.lua): Add Checks --- [core]/es_extended/imports.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/[core]/es_extended/imports.lua b/[core]/es_extended/imports.lua index 91d5f887..46a79f93 100644 --- a/[core]/es_extended/imports.lua +++ b/[core]/es_extended/imports.lua @@ -20,8 +20,13 @@ local function TrackPedCoordsOnce() end if not IsDuplicityVersion() then -- Only register this event for the client - -- On Resource Start - local OnStart = (function() + -- On Resource Restarts + local OnResourceRestart = (function() + if not ESX.PlayerLoaded or not ESX.PlayerData then + -- Player hasn't loaded yet + return + end + TrackPedCoordsOnce() end)() From 8babae256bf5b22c6eec1acab010e34ff96b9865 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sun, 6 Jul 2025 10:45:48 +0200 Subject: [PATCH 6/8] fix(es_extended/imports): Remove unnecessary OnResourceRestart function --- [core]/es_extended/imports.lua | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/[core]/es_extended/imports.lua b/[core]/es_extended/imports.lua index 46a79f93..40f502b3 100644 --- a/[core]/es_extended/imports.lua +++ b/[core]/es_extended/imports.lua @@ -20,16 +20,6 @@ local function TrackPedCoordsOnce() end if not IsDuplicityVersion() then -- Only register this event for the client - -- On Resource Restarts - local OnResourceRestart = (function() - if not ESX.PlayerLoaded or not ESX.PlayerData then - -- Player hasn't loaded yet - return - end - - TrackPedCoordsOnce() - end)() - AddEventHandler("esx:setPlayerData", function(key, val, last) if GetInvokingResource() == "es_extended" then ESX.PlayerData[key] = val From 23615a0dd90a7c233c3d347017c7a68d7385b41e Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sun, 6 Jul 2025 10:58:59 +0200 Subject: [PATCH 7/8] refactor(client/modules/actions): remove unused TrackPedCoords --- [core]/es_extended/client/modules/actions.lua | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/[core]/es_extended/client/modules/actions.lua b/[core]/es_extended/client/modules/actions.lua index c021f350..de174910 100644 --- a/[core]/es_extended/client/modules/actions.lua +++ b/[core]/es_extended/client/modules/actions.lua @@ -33,13 +33,6 @@ function Actions:SetVehicleStatus() ESX.SetPlayerData("seat", self.seat) end -function Actions:TrackPedCoords() - local playerPed = ESX.PlayerData.ped - local coords = GetEntityCoords(playerPed) - - ESX.SetPlayerData("coords", coords) -end - function Actions:TrackPedCoordsOnce() CreateThread(function() while not ESX.IsPlayerLoaded() do @@ -49,7 +42,7 @@ function Actions:TrackPedCoordsOnce() ESX.PlayerData.coords = nil setmetatable(ESX.PlayerData, { - __index = function(self, key) + __index = function(_, key) if key ~= "coords" then return end @@ -215,7 +208,6 @@ end function Actions:SlowLoop() CreateThread(function() while ESX.PlayerLoaded do - -- self:TrackPedCoords() self:TrackPauseMenu() self:TrackVehicle() self:TrackWeapon() @@ -236,7 +228,7 @@ end function Actions:Init() self:SlowLoop() self:PedLoop() + self:TrackPedCoordsOnce() end Actions:Init() -Actions:TrackPedCoordsOnce() From f692f6fc0682d968a63b4e840aa046ca8ecf1f35 Mon Sep 17 00:00:00 2001 From: Kenshin13 <63159154+Kenshiin13@users.noreply.github.com> Date: Sun, 6 Jul 2025 16:06:36 +0200 Subject: [PATCH 8/8] fix(es_extended/imports): init metatable --- [core]/es_extended/imports.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/[core]/es_extended/imports.lua b/[core]/es_extended/imports.lua index 40f502b3..95ba5305 100644 --- a/[core]/es_extended/imports.lua +++ b/[core]/es_extended/imports.lua @@ -4,6 +4,10 @@ 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, { @@ -37,6 +41,8 @@ if not IsDuplicityVersion() then -- Only register this event for the client TrackPedCoordsOnce() end) + TrackPedCoordsOnce() + ESX.SecureNetEvent("esx:onPlayerLogout", function() ESX.PlayerLoaded = false ESX.PlayerData = {}