refactor: better Coord Handling

this method means we dont have to trust the client to send the correct info
This commit is contained in:
Mycroft
2022-08-28 18:09:13 +01:00
parent 329ba0d7f3
commit 4402a62e74
3 changed files with 7 additions and 6 deletions
+1 -3
View File
@@ -454,9 +454,7 @@ function StartServerSyncLoops()
if distance > 1 then
previousCoords = playerCoords
local playerHeading = ESX.Math.Round(GetEntityHeading(ESX.PlayerData.ped), 1)
local formattedCoords = {x = ESX.Math.Round(playerCoords.x, 1), y = ESX.Math.Round(playerCoords.y, 1), z = ESX.Math.Round(playerCoords.z, 1), heading = playerHeading}
TriggerServerEvent('esx:updateCoords', formattedCoords)
TriggerServerEvent('esx:updateCoords')
end
end
Wait(1500)
+3 -1
View File
@@ -33,7 +33,9 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
SetEntityHeading(Ped, vector.w)
end
function self.updateCoords(coords)
function self.updateCoords()
local Ped = GetPlayerPed(self.source)
local coords = GetEntityCoords(Ped)
self.coords = {x = ESX.Math.Round(coords.x, 1), y = ESX.Math.Round(coords.y, 1), z = ESX.Math.Round(coords.z, 1), heading = ESX.Math.Round(coords.heading or 0.0, 1)}
end
+3 -2
View File
@@ -380,11 +380,12 @@ AddEventHandler('esx:playerLogout', function(playerId, cb)
end)
RegisterNetEvent('esx:updateCoords')
AddEventHandler('esx:updateCoords', function(coords)
AddEventHandler('esx:updateCoords', function()
local source = source
local xPlayer = ESX.GetPlayerFromId(source)
if xPlayer then
xPlayer.updateCoords(coords)
xPlayer.updateCoords()
end
end)