Fixed error in UpdateAmputations during init in MP

This commit is contained in:
ZioPao
2024-01-12 14:03:22 +01:00
parent 15b1d070bf
commit b9ed37f3ba
2 changed files with 13 additions and 4 deletions

View File

@@ -20,12 +20,14 @@ DataController.instances = {}
---@return DataController ---@return DataController
function DataController:new(username, isResetForced) function DataController:new(username, isResetForced)
TOC_DEBUG.print("Creating new DataController instance for " .. username) TOC_DEBUG.print("Creating new DataController instance for " .. username)
---@type DataController
---@diagnostic disable-next-line: missing-fields
local o = {} local o = {}
setmetatable(o, self) setmetatable(o, self)
self.__index = self self.__index = self
o.username = username o.username = username
o.isResetForced = isResetForced o.isResetForced = isResetForced or false
o.isDataReady = 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) -- 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) local key = CommandsData.GetKey(username)
if isClient() then if isClient() then
-- In MP, we request the data from the server to trigger DataController.ReceiveData
ModData.request(key) ModData.request(key)
else else
-- In SP, we handle it with another function which will reference the saved instance in DataController.instances
o:initSinglePlayer(key) o:initSinglePlayer(key)
end end
@@ -373,7 +377,6 @@ function DataController.ReceiveData(key, data)
handler:applyOnlineData(data) handler:applyOnlineData(data)
end end
handler:setIsResetForced(false) handler:setIsResetForced(false)
handler:setIsDataReady(true) handler:setIsDataReady(true)
@@ -389,7 +392,9 @@ end
Events.OnReceiveGlobalModData.Add(DataController.ReceiveData) Events.OnReceiveGlobalModData.Add(DataController.ReceiveData)
--* SP Only initialization
--- SP Only initialization
---@param key string
function DataController:initSinglePlayer(key) function DataController:initSinglePlayer(key)
self:loadLocalData(key) self:loadLocalData(key)
if self.tocData == nil or self.isResetForced then if self.tocData == nil or self.isResetForced then

View File

@@ -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 ---Updates the cicatrization process, run when a limb has been cut. Run it every 1 hour
function LocalPlayerController.UpdateAmputations() function LocalPlayerController.UpdateAmputations()
local dcInst = DataController.GetInstance() 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) Events.EveryHours.Remove(LocalPlayerController.UpdateAmputations)
end end