From eb54fc4675d5142983cd359e87673d65b3ac22b6 Mon Sep 17 00:00:00 2001 From: Linden <65407488+thelindat@users.noreply.github.com> Date: Sun, 29 May 2022 10:29:52 +1000 Subject: [PATCH] refactor(player/client): set CPlayer.__index as a function Match server implementation. --- imports/player/client.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/imports/player/client.lua b/imports/player/client.lua index 29c9216..8b4f36a 100644 --- a/imports/player/client.lua +++ b/imports/player/client.lua @@ -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()