diff --git a/_compatible_mods/3d_armor/init_3d_armor.lua b/_compatible_mods/3d_armor/init_3d_armor.lua index 9b19cc8..4cba97e 100644 --- a/_compatible_mods/3d_armor/init_3d_armor.lua +++ b/_compatible_mods/3d_armor/init_3d_armor.lua @@ -1,3 +1,6 @@ +local function get_armor_importance() end + + minetest.register_on_joinplayer(function(player) if skywars_settings.remove_armors_on_join and minetest.get_modpath("3d_armor") then minetest.after(5, function() armor:remove_all(player) end) @@ -10,4 +13,52 @@ function skywars.remove_armor(player) if minetest.get_modpath("3d_armor") then armor:remove_all(player) end +end + + + +minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info) + local pl_name = player:get_player_name() + + if minetest.get_modpath("3d_armor") and arena_lib.is_player_in_arena(pl_name, "skywars") then + -- The armor that the player's taking. + local armor_itemstack = inventory_info.stack + if not armor_itemstack then return end + local armor_name = armor_itemstack:get_name() + -- The body part that the armor's assigned to, returns nil if it's not an armor. + local armor_element = armor:get_element(armor_name) + + if action == "put" and armor_element then + -- A table containing pairs of [armor_element : string] = armor_name : string. + local player_armor_elements = armor:get_weared_armor_elements(player) + local equipped_armor = player_armor_elements[armor_element] + + if equipped_armor then + local armor_importance = get_armor_importance(armor_name) + local weared_armor_importance = get_armor_importance(equipped_armor) + -- Returning if the just taken armor is worse or as good as the equipped one. + if armor_importance <= weared_armor_importance then return end + end + + armor:equip(player, armor_itemstack) + minetest.after(0, function() + inventory:remove_item("main", ItemStack(armor_name)) + end) + end + end +end) + + + +function get_armor_importance(armor_name) + local importance + + if (armor_name:match("wood")) then importance = 1 + elseif (armor_name:match("gold")) then importance = 2 + elseif (armor_name:match("bronze")) then importance = 3 + elseif (armor_name:match("steel")) then importance = 4 + elseif (armor_name:match("diamond")) then importance = 5 + end + + return importance end \ No newline at end of file diff --git a/_kits/formspec.lua b/_kits/formspec.lua index c211e0c..05a4bbb 100644 --- a/_kits/formspec.lua +++ b/_kits/formspec.lua @@ -24,6 +24,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields) if fields[kit_name] then select_kit(pl_name, kits[kit_name]) minetest.close_formspec(pl_name, "skywars:kit_selector") + arena_lib.HUD_hide("broadcast", pl_name) end end end)