Merge pull request #1058 from falszywyyy/main

refactor(server/player): Optimized player coords updating system
This commit is contained in:
Thekuca
2023-06-10 00:50:18 +02:00
committed by GitHub
2 changed files with 10 additions and 24 deletions
+9 -22
View File
@@ -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
+1 -2
View File
@@ -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