From b9ed37f3ba9def6512186496f128985d9d7c199f Mon Sep 17 00:00:00 2001 From: ZioPao Date: Fri, 12 Jan 2024 14:03:22 +0100 Subject: [PATCH] Fixed error in UpdateAmputations during init in MP --- media/lua/client/TOC/Controllers/DataController.lua | 11 ++++++++--- .../client/TOC/Controllers/LocalPlayerController.lua | 6 +++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/media/lua/client/TOC/Controllers/DataController.lua b/media/lua/client/TOC/Controllers/DataController.lua index 2813cb9..5e6880b 100644 --- a/media/lua/client/TOC/Controllers/DataController.lua +++ b/media/lua/client/TOC/Controllers/DataController.lua @@ -20,12 +20,14 @@ DataController.instances = {} ---@return DataController function DataController:new(username, isResetForced) TOC_DEBUG.print("Creating new DataController instance for " .. username) + ---@type DataController + ---@diagnostic disable-next-line: missing-fields local o = {} setmetatable(o, self) self.__index = self o.username = username - o.isResetForced = isResetForced + o.isResetForced = isResetForced or false o.isDataReady = false -- We're gonna set it already from here, to prevent it from looping in SP (in case we need to fetch this instance) @@ -34,8 +36,10 @@ function DataController:new(username, isResetForced) local key = CommandsData.GetKey(username) if isClient() then + -- In MP, we request the data from the server to trigger DataController.ReceiveData ModData.request(key) else + -- In SP, we handle it with another function which will reference the saved instance in DataController.instances o:initSinglePlayer(key) end @@ -373,7 +377,6 @@ function DataController.ReceiveData(key, data) handler:applyOnlineData(data) end - handler:setIsResetForced(false) handler:setIsDataReady(true) @@ -389,7 +392,9 @@ end Events.OnReceiveGlobalModData.Add(DataController.ReceiveData) ---* SP Only initialization + +--- SP Only initialization +---@param key string function DataController:initSinglePlayer(key) self:loadLocalData(key) if self.tocData == nil or self.isResetForced then diff --git a/media/lua/client/TOC/Controllers/LocalPlayerController.lua b/media/lua/client/TOC/Controllers/LocalPlayerController.lua index ab8c481..8da5c20 100644 --- a/media/lua/client/TOC/Controllers/LocalPlayerController.lua +++ b/media/lua/client/TOC/Controllers/LocalPlayerController.lua @@ -216,7 +216,11 @@ Events.OnPlayerGetDamage.Add(LocalPlayerController.OnGetDamage) ---Updates the cicatrization process, run when a limb has been cut. Run it every 1 hour function LocalPlayerController.UpdateAmputations() local dcInst = DataController.GetInstance() - if dcInst:getIsAnyLimbCut() == false then + if not dcInst:getIsDataReady() then + TOC_DEBUG.print("Data not ready for UpdateAmputations, waiting next loop") + return + end + if not dcInst:getIsAnyLimbCut() then Events.EveryHours.Remove(LocalPlayerController.UpdateAmputations) end