mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 08:13:21 +00:00
refactor: better Coord Handling
this method means we dont have to trust the client to send the correct info
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user