mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-18 15:36:02 +01:00
refactor(player): simplify
Was planning to support checking other user playerdata, but will require much more planning to implement properly.
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
local CPlayer = {}
|
local CPlayer = {}
|
||||||
CPlayer.__index = CPlayer
|
CPlayer.__index = CPlayer
|
||||||
|
|
||||||
function CPlayer:getCoords()
|
function CPlayer:getCoords(update)
|
||||||
if not self.coords then
|
if update or not self.coords then
|
||||||
self.coords = GetEntityCoords(self.ped)
|
self.coords = GetEntityCoords(self.ped)
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -17,26 +17,10 @@ function lib.addPlayerMethod(name, fn)
|
|||||||
CPlayer[name] = fn
|
CPlayer[name] = fn
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.getPlayer(id, ped, serverId)
|
function lib.getPlayer()
|
||||||
return setmetatable({
|
return setmetatable({
|
||||||
id = id or cache.playerId,
|
id = cache.playerId,
|
||||||
ped = ped or cache.ped,
|
ped = cache.ped,
|
||||||
serverId = serverId or cache.serverId,
|
serverId = cache.serverId,
|
||||||
}, CPlayer)
|
}, CPlayer)
|
||||||
end
|
end
|
||||||
|
|
||||||
function lib.getPlayerFromServerId(serverId)
|
|
||||||
local playerId = GetPlayerFromServerId(serverId)
|
|
||||||
|
|
||||||
if playerId then
|
|
||||||
return lib.getPlayer(playerId, playerId == cache.playerId and cache.ped or NetworkGetEntityFromNetworkId(serverId), serverId)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function lib.getPlayerFromPed(ped)
|
|
||||||
local playerId = NetworkGetPlayerIndexFromPed(ped)
|
|
||||||
|
|
||||||
if playerId then
|
|
||||||
return lib.getPlayer(playerId, ped, playerId == cache.playerId and cache.serverId or GetPlayerServerId(playerId))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|||||||
Reference in New Issue
Block a user