mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 03:01:31 +00:00
Merge pull request #1651 from Meyndflay/feature
feat(es_extended): Optimize Tracking Of Ped Coords
This commit is contained in:
@@ -0,0 +1 @@
|
||||
.DS_Store
|
||||
@@ -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()
|
||||
|
||||
@@ -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 = {}
|
||||
|
||||
Reference in New Issue
Block a user