From a7a064119d845fcf159a4c74106b841dd2a25e24 Mon Sep 17 00:00:00 2001 From: ZioPao Date: Sun, 5 May 2024 21:07:33 +0200 Subject: [PATCH] Added destroy instance in DataController after death --- .../client/TOC/Controllers/DataController.lua | 8 ++++++++ media/lua/client/TOC/Main.lua | 16 +++++++++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/media/lua/client/TOC/Controllers/DataController.lua b/media/lua/client/TOC/Controllers/DataController.lua index 7a96f88..a9d5fae 100644 --- a/media/lua/client/TOC/Controllers/DataController.lua +++ b/media/lua/client/TOC/Controllers/DataController.lua @@ -474,4 +474,12 @@ function DataController.GetInstance(username) end end + +function DataController.DestroyInstance(username) + if DataController.instances[username] ~= nil then + DataController.instances[username] = nil + end + +end + return DataController \ No newline at end of file diff --git a/media/lua/client/TOC/Main.lua b/media/lua/client/TOC/Main.lua index 61c3367..6568811 100644 --- a/media/lua/client/TOC/Main.lua +++ b/media/lua/client/TOC/Main.lua @@ -36,16 +36,15 @@ function Main.InitializePlayer() CommonMethods.SafeStartEvent("OnTick", TryToInitialize) 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 function Main.WipeData(player) - TOC_DEBUG.print("Wiping data after death") - local key = CommandsData.GetKey(player:getUsername()) + local username = player:getUsername() + TOC_DEBUG.print("Wiping data after death: " .. username) + local key = CommandsData.GetKey(username) --ModData.remove(key) - - if not isClient() then -- For SP, it's enough just removing the data this way ModData.remove(key) @@ -54,7 +53,14 @@ function Main.WipeData(player) -- at the next character by passing an empty mod data ModData.add(key, {}) ModData.transmit(key) + end + + + -- Let's wipe the instance too just to be sure + local DataController = require("TOC/Controllers/DataController") + DataController.DestroyInstance(username) + end --* Events *--