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/client/modules/actions.lua b/[core]/es_extended/client/modules/actions.lua index 98b864b1..de174910 100644 --- a/[core]/es_extended/client/modules/actions.lua +++ b/[core]/es_extended/client/modules/actions.lua @@ -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() diff --git a/[core]/es_extended/imports.lua b/[core]/es_extended/imports.lua index 9bd1d4ff..18465fd7 100644 --- a/[core]/es_extended/imports.lua +++ b/[core]/es_extended/imports.lua @@ -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 = {}