refactor(player/client): set CPlayer.__index as a function

Match server implementation.
This commit is contained in:
Linden
2022-05-29 10:29:52 +10:00
parent 04beaf1b5a
commit eb54fc4675

View File

@@ -1,5 +1,14 @@
local CPlayer = {}
CPlayer.__index = CPlayer
function CPlayer:__index(index, ...)
local method = CPlayer[index]
if method then
return function(...)
return method(self, ...)
end
end
end
function CPlayer:getCoords(update)
if update or not self.coords then
@@ -13,15 +22,6 @@ function CPlayer:getDistance(coords)
return #(self:getCoords() - coords)
end
function lib.addPlayerMethod(name, fn)
CPlayer[name] = fn
end
function lib.getPlayer()
return setmetatable({
id = cache.playerId,
serverId = cache.serverId,
}, CPlayer)
return CPlayer
end
player = lib.getPlayer()