mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-08-29 01:08:54 +00:00
Merge pull request #1058 from falszywyyy/main
refactor(server/player): Optimized player coords updating system
This commit is contained in:
@@ -47,31 +47,18 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
||||
SetEntityHeading(Ped, vector.w)
|
||||
end
|
||||
|
||||
function self.updateCoords()
|
||||
SetTimeout(1000,function()
|
||||
local Ped = GetPlayerPed(self.source)
|
||||
if DoesEntityExist(Ped) then
|
||||
local coords = GetEntityCoords(Ped)
|
||||
local distance = #(coords - vector3(self.coords.x, self.coords.y, self.coords.z))
|
||||
if distance > 1.5 then
|
||||
local heading = GetEntityHeading(Ped)
|
||||
self.coords = {
|
||||
x = coords.x,
|
||||
y = coords.y,
|
||||
z = coords.z,
|
||||
heading = heading or 0.0
|
||||
}
|
||||
end
|
||||
end
|
||||
self.updateCoords()
|
||||
end)
|
||||
end
|
||||
|
||||
function self.getCoords(vector)
|
||||
local ped = GetPlayerPed(self.source)
|
||||
local coords = GetEntityCoords(ped)
|
||||
|
||||
if vector then
|
||||
return vector3(self.coords.x, self.coords.y, self.coords.z)
|
||||
return coords
|
||||
else
|
||||
return self.coords
|
||||
return {
|
||||
x = coords.x,
|
||||
y = coords.y,
|
||||
z = coords.z,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -309,7 +309,7 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
xPlayer.triggerEvent('esx:playerLoaded',
|
||||
{
|
||||
accounts = xPlayer.getAccounts(),
|
||||
coords = xPlayer.getCoords(),
|
||||
coords = userData.coords,
|
||||
identifier = xPlayer.getIdentifier(),
|
||||
inventory = xPlayer.getInventory(),
|
||||
job = xPlayer.getJob(),
|
||||
@@ -331,7 +331,6 @@ function loadESXPlayer(identifier, playerId, isNew)
|
||||
else
|
||||
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
|
||||
end
|
||||
xPlayer.updateCoords()
|
||||
xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands)
|
||||
print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user