From 15106acfb994c2b96edc51a96cb8ff3607d6f0d5 Mon Sep 17 00:00:00 2001 From: Musiker15 Date: Sun, 17 Nov 2024 13:43:23 +0100 Subject: [PATCH] Update v2.7.4 --- client/functions/player.lua | 39 ++++++++++++++++++++++++++++++++++++- fxmanifest.lua | 2 +- import.lua | 23 +++++++++++++++++++--- 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/client/functions/player.lua b/client/functions/player.lua index 1e2a87b..e832098 100644 --- a/client/functions/player.lua +++ b/client/functions/player.lua @@ -59,6 +59,21 @@ setmetatable(Player, { if tonumber(key) then return MSK.Trigger('msk_core:player', key) end + end, + __call = function(self, key, val, update) + local value = rawget(self, key) + + if value == nil then + if type(val) == 'function' then + value = func() + else + value = val + end + + rawset(self, key, value) + end + + return value end }) @@ -89,4 +104,26 @@ CreateThread(function() end end) -MSK.Player = Player \ No newline at end of file +MSK.Player = Player + +local Contains = function(key) + local keys = { + 'clientId', 'serverId', 'playerId', 'Notify', + 'coords', 'heading', 'state', + 'ped', 'playerPed', 'vehicle', 'seat', 'weapon', 'isDead', + } + + for k, v in pairs(keys) do + if k == key then + return true + end + end + + return false +end + +AddEventHandler('msk_core:invokingUpdate', function(key, value) + if Contains(key) then return end + + Player:set(key, value) +end) \ No newline at end of file diff --git a/fxmanifest.lua b/fxmanifest.lua index f1a39ac..9ae4d72 100644 --- a/fxmanifest.lua +++ b/fxmanifest.lua @@ -4,7 +4,7 @@ games { 'gta5' } author 'Musiker15 - MSK Scripts' name 'msk_core' description 'Functions for MSK Scripts' -version '2.7.3' +version '2.7.4' lua54 'yes' diff --git a/import.lua b/import.lua index 65137ee..61ac821 100644 --- a/import.lua +++ b/import.lua @@ -98,15 +98,32 @@ if context == 'client' then if tonumber(key) then return MSK.Trigger('msk_core:player', key) end + end, + __call = function(self, key, val, update) + local value = rawget(self, key) + + if value == nil then + if type(val) == 'function' then + value = func() + else + value = val + end + + rawset(self, key, value) + + if update then + TriggerEvent('msk_core:invokingUpdate', key, value) + end + end + + return value end }) AddEventHandler('msk_core:onPlayer', function(key, value, oldValue) MSK.Player[key] = value end) -end - -if context == 'server' then +elseif context == 'server' then local metatable = { __index = function(self, key) if type(key) == "string" then