Added destroy instance in DataController after death

This commit is contained in:
ZioPao
2024-05-05 21:07:33 +02:00
parent 9b1876b235
commit a7a064119d
2 changed files with 19 additions and 5 deletions

View File

@@ -474,4 +474,12 @@ function DataController.GetInstance(username)
end end
end end
function DataController.DestroyInstance(username)
if DataController.instances[username] ~= nil then
DataController.instances[username] = nil
end
end
return DataController return DataController

View File

@@ -36,16 +36,15 @@ function Main.InitializePlayer()
CommonMethods.SafeStartEvent("OnTick", TryToInitialize) CommonMethods.SafeStartEvent("OnTick", TryToInitialize)
end end
---Clean the TOC table for that SP player, to prevent from clogging it up ---Clean the TOC table for that SP player, to prevent it from clogging ModData up
---@param player IsoPlayer ---@param player IsoPlayer
function Main.WipeData(player) function Main.WipeData(player)
TOC_DEBUG.print("Wiping data after death") local username = player:getUsername()
local key = CommandsData.GetKey(player:getUsername()) TOC_DEBUG.print("Wiping data after death: " .. username)
local key = CommandsData.GetKey(username)
--ModData.remove(key) --ModData.remove(key)
if not isClient() then if not isClient() then
-- For SP, it's enough just removing the data this way -- For SP, it's enough just removing the data this way
ModData.remove(key) ModData.remove(key)
@@ -54,7 +53,14 @@ function Main.WipeData(player)
-- at the next character by passing an empty mod data -- at the next character by passing an empty mod data
ModData.add(key, {}) ModData.add(key, {})
ModData.transmit(key) ModData.transmit(key)
end end
-- Let's wipe the instance too just to be sure
local DataController = require("TOC/Controllers/DataController")
DataController.DestroyInstance(username)
end end
--* Events *-- --* Events *--