mirror of
https://github.com/esx-framework/esx_core.git
synced 2026-09-04 00:03:21 +00:00
Optimized saving of player position
The changes I applied to the code regarding self.getCoords(), changing the conditions when joining the server at coordinates to userData.coords and getting rid of the self.updateCoords() function. I believe that my changes when saving are more efficient, because the player's position is not overwritten unnecessarily every second if he changes his position, but the position is saved when leaving the server to the database, and then loaded when entering the server.
This commit is contained in:
@@ -47,33 +47,20 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
|
|||||||
SetEntityHeading(Ped, vector.w)
|
SetEntityHeading(Ped, vector.w)
|
||||||
end
|
end
|
||||||
|
|
||||||
function self.updateCoords()
|
function self.getCoords(vector)
|
||||||
SetTimeout(1000,function()
|
local ped = GetPlayerPed(self.source)
|
||||||
local Ped = GetPlayerPed(self.source)
|
local coords = GetEntityCoords(ped)
|
||||||
if DoesEntityExist(Ped) then
|
|
||||||
local coords = GetEntityCoords(Ped)
|
if vector then
|
||||||
local distance = #(coords - vector3(self.coords.x, self.coords.y, self.coords.z))
|
return coords
|
||||||
if distance > 1.5 then
|
else
|
||||||
local heading = GetEntityHeading(Ped)
|
return {
|
||||||
self.coords = {
|
|
||||||
x = coords.x,
|
x = coords.x,
|
||||||
y = coords.y,
|
y = coords.y,
|
||||||
z = coords.z,
|
z = coords.z,
|
||||||
heading = heading or 0.0
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.updateCoords()
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.getCoords(vector)
|
|
||||||
if vector then
|
|
||||||
return vector3(self.coords.x, self.coords.y, self.coords.z)
|
|
||||||
else
|
|
||||||
return self.coords
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function self.kick(reason)
|
function self.kick(reason)
|
||||||
DropPlayer(self.source, reason)
|
DropPlayer(self.source, reason)
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ function loadESXPlayer(identifier, playerId, isNew)
|
|||||||
xPlayer.triggerEvent('esx:playerLoaded',
|
xPlayer.triggerEvent('esx:playerLoaded',
|
||||||
{
|
{
|
||||||
accounts = xPlayer.getAccounts(),
|
accounts = xPlayer.getAccounts(),
|
||||||
coords = xPlayer.getCoords(),
|
coords = userData.coords,
|
||||||
identifier = xPlayer.getIdentifier(),
|
identifier = xPlayer.getIdentifier(),
|
||||||
inventory = xPlayer.getInventory(),
|
inventory = xPlayer.getInventory(),
|
||||||
job = xPlayer.getJob(),
|
job = xPlayer.getJob(),
|
||||||
@@ -331,7 +331,7 @@ function loadESXPlayer(identifier, playerId, isNew)
|
|||||||
else
|
else
|
||||||
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
|
exports.ox_inventory:setPlayerInventory(xPlayer, userData.inventory)
|
||||||
end
|
end
|
||||||
xPlayer.updateCoords()
|
|
||||||
xPlayer.triggerEvent('esx:registerSuggestions', Core.RegisteredCommands)
|
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))
|
print(('[^2INFO^0] Player ^5"%s"^0 has connected to the server. ID: ^5%s^7'):format(xPlayer.getName(), playerId))
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user