From bfbac33a9d5186a76116319926285571c493a058 Mon Sep 17 00:00:00 2001 From: Giov4 Date: Mon, 21 Dec 2020 15:53:07 +0100 Subject: [PATCH] Fixed the chest id generation --- _chest_handler/chest_setter.lua | 14 ++++++++++++++ commands.lua | 3 +-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/_chest_handler/chest_setter.lua b/_chest_handler/chest_setter.lua index 8380cde..d91d50d 100644 --- a/_chest_handler/chest_setter.lua +++ b/_chest_handler/chest_setter.lua @@ -10,6 +10,20 @@ end +function skywars.generate_chest_id(arena) + local max_id = 1 + + for i = 1, #arena.chests do + if arena.chests[i].id > max_id then + max_id = arena.chests[i].id + end + end + + return max_id+1 +end + + + function fill_chests(arena) for i, chest in pairs(arena.chests) do local treasures = skywars.select_random_treasures(chest, arena) diff --git a/commands.lua b/commands.lua index c719c8f..2f17b51 100644 --- a/commands.lua +++ b/commands.lua @@ -385,8 +385,7 @@ ChatCmdBuilder.new("skywars", function(cmd) return end - local chest_id = 1 - if arena.chests[#arena.chests] then chest_id = arena.chests[#arena.chests].id+1 end + local chest_id = skywars.generate_chest_id(arena) local chest = { pos = pos,