Skip to content

Commit

Permalink
fix(es_extended): xPlayer.getCoords backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Arctos2win authored Jun 18, 2024
1 parent 5504745 commit faace18
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions [core]/es_extended/server/classes/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,23 @@ function CreateExtendedPlayer(playerId, identifier, group, accounts, inventory,
end

---@param vector boolean
---@return vector3 | table
function self.getCoords(vector)
local ped <const> = _GetPlayerPed(self.source)
local coordinates <const> = _GetEntityCoords(ped)
local heading <const> = _GetEntityHeading(ped)
--- @param heading boolean
---@return vector3 | vector4 | table
function self.getCoords(vector, heading)
local ped <const> = _GetPlayerPed(self.source)
local coords <const> = _GetEntityCoords(ped)

local coordinates
if vector then
coordinates = (heading and vector4(coords.xyz, _GetEntityHeading(ped)) or coords)
else
coordinates = { x = coords.x, y = coords.y, z = coords.z }
if heading then
coordinates.heading = _GetEntityHeading(ped)
end
end

return vector and vector4(coordinates.xyz, heading) or { x = coordinates.x, y = coordinates.y, z = coordinates.z, heading = heading }
return coordinates
end

---@param reason string
Expand Down
2 changes: 1 addition & 1 deletion [core]/es_extended/server/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ function Core.SavePlayer(xPlayer, cb)
xPlayer.job.name,
xPlayer.job.grade,
xPlayer.group,
json.encode(xPlayer.getCoords()),
json.encode(xPlayer.getCoords(false, true)),
json.encode(xPlayer.getInventory(true)),
json.encode(xPlayer.getLoadout(true)),
json.encode(xPlayer.getMeta()),
Expand Down

0 comments on commit faace18

Please sign in to comment.