mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +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 = {}
|
||||
CPlayer.__index = CPlayer
|
||||
|
||||
function CPlayer:getCoords()
|
||||
if not self.coords then
|
||||
function CPlayer:getCoords(update)
|
||||
if update or not self.coords then
|
||||
self.coords = GetEntityCoords(self.ped)
|
||||
end
|
||||
|
||||
@@ -17,26 +17,10 @@ function lib.addPlayerMethod(name, fn)
|
||||
CPlayer[name] = fn
|
||||
end
|
||||
|
||||
function lib.getPlayer(id, ped, serverId)
|
||||
function lib.getPlayer()
|
||||
return setmetatable({
|
||||
id = id or cache.playerId,
|
||||
ped = ped or cache.ped,
|
||||
serverId = serverId or cache.serverId,
|
||||
id = cache.playerId,
|
||||
ped = cache.ped,
|
||||
serverId = cache.serverId,
|
||||
}, CPlayer)
|
||||
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