From 83e2e879f0f455c3042c92c42e470847ed19fa7d Mon Sep 17 00:00:00 2001 From: daiguel Date: Mon, 5 Dec 2022 18:47:08 +0100 Subject: [PATCH] refacto code to avoid bug when multiple client are carrying at same time --- server/main.lua | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/server/main.lua b/server/main.lua index 7fe82d9..a3fd7f8 100644 --- a/server/main.lua +++ b/server/main.lua @@ -130,14 +130,19 @@ lib.callback.register('hunterXhunter:canCarry', function(source, animalNetID) end end table.insert(animalsCarriedNetIDs, animalNetID) - local index= #animalsCarriedNetIDs - print(index) - print(json.encode(animalsCarriedNetIDs, {indent=true})) + SetTimeout(2, function() - table.remove(animalsCarriedNetIDs, index) - print(json.encode(animalsCarriedNetIDs, {indent=true})) + local index = nil + for k, v in pairs(animalsCarriedNetIDs) do + if v == animalNetID then + index = k + end + end + if index ~= nil then + table.remove(animalsCarriedNetIDs, index) + end end) - print("tototo finished") + return true end)