Add HUD to show worn armor
This commit is contained in:
parent
8bb21de099
commit
003ff26daa
@ -9,6 +9,7 @@ local add_node = minetest.add_node
|
||||
local get_node = minetest.get_node
|
||||
local remove_node = minetest.remove_node
|
||||
local S = skywars.T
|
||||
local is_3d_armor_enabled = minetest.get_modpath("3d_armor")
|
||||
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
@ -29,6 +30,10 @@ arena_lib.on_load("skywars", function(arena)
|
||||
|
||||
create_barrier_cage(player)
|
||||
player:get_inventory():add_item("main", "skywars:kit_selector")
|
||||
|
||||
if is_3d_armor_enabled then
|
||||
skywars.HUD_armor_create(player)
|
||||
end
|
||||
end
|
||||
|
||||
arena_lib.HUD_send_msg_all(
|
||||
|
77
src/_compatible_mods/3d_armor/armor_hud.lua
Normal file
77
src/_compatible_mods/3d_armor/armor_hud.lua
Normal file
@ -0,0 +1,77 @@
|
||||
local saved_huds = {} -- id = hud
|
||||
|
||||
|
||||
|
||||
function skywars.HUD_armor_create(player)
|
||||
local pl_name = player:get_player_name()
|
||||
|
||||
if saved_huds[pl_name] then return end
|
||||
|
||||
local x_pos = 0.5
|
||||
local y_pos = 1
|
||||
local scale = 1.6
|
||||
local x_off = -32 * player:hud_get_hotbar_itemcount()
|
||||
local y_off = -20
|
||||
|
||||
local head = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = x_pos, y = y_pos},
|
||||
offset = {x = x_off -25, y = y_off - 25},
|
||||
text = "3d_armor_inv_helmet_bronze.png^[multiply:#000000",
|
||||
alignment = {x = 1},
|
||||
scale = {x = scale, y = scale},
|
||||
})
|
||||
|
||||
local torso = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = x_pos, y = y_pos},
|
||||
offset = {x = x_off, y = y_off - 25},
|
||||
text = "3d_armor_inv_chestplate_bronze.png^[multiply:#000000",
|
||||
alignment = {x = 1},
|
||||
scale = {x = scale, y = scale},
|
||||
})
|
||||
|
||||
local legs = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = x_pos, y = y_pos},
|
||||
offset = {x = x_off -25, y = y_off},
|
||||
text = "3d_armor_inv_leggings_bronze.png^[multiply:#000000",
|
||||
alignment = {x = 1},
|
||||
scale = {x = scale, y = scale},
|
||||
})
|
||||
|
||||
local feet = player:hud_add({
|
||||
hud_elem_type = "image",
|
||||
position = {x = x_pos, y = y_pos},
|
||||
offset = {x = x_off, y = y_off},
|
||||
text = "3d_armor_inv_boots_bronze.png^[multiply:#000000",
|
||||
alignment = {x = 1},
|
||||
scale = {x = scale, y = scale},
|
||||
})
|
||||
|
||||
saved_huds[pl_name] = { head = head, torso = torso, legs = legs, feet = feet}
|
||||
end
|
||||
|
||||
|
||||
|
||||
function skywars.HUD_armor_remove(player)
|
||||
local pl_name = player:get_player_name()
|
||||
|
||||
if not saved_huds[pl_name] then return end
|
||||
|
||||
for _, id in pairs(saved_huds[pl_name]) do
|
||||
player:hud_remove(id)
|
||||
end
|
||||
|
||||
saved_huds[pl_name] = nil
|
||||
end
|
||||
|
||||
|
||||
|
||||
function skywars.HUD_armor_update(player, stack)
|
||||
local type = armor:get_element(stack:get_name())
|
||||
local txtr = stack:get_definition().inventory_image
|
||||
|
||||
-- there's no way they can simply unequip a piece at the moment, so I don't run further checks
|
||||
player:hud_change(saved_huds[player:get_player_name()][type], "text", txtr)
|
||||
end
|
@ -10,7 +10,6 @@ function skywars.auto_equip_armor(player, armor_itemstack)
|
||||
-- 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]
|
||||
local inventory = player:get_inventory()
|
||||
|
||||
if equipped_armor then
|
||||
local armor_importance = get_armor_importance(armor_name)
|
||||
@ -22,6 +21,10 @@ function skywars.auto_equip_armor(player, armor_itemstack)
|
||||
if armor_importance <= weared_armor_importance then return end
|
||||
end
|
||||
|
||||
if arena_lib.is_player_in_arena(player:get_player_name()) then
|
||||
skywars.HUD_armor_update(player, armor_itemstack)
|
||||
end
|
||||
|
||||
armor:equip(player, armor_itemstack)
|
||||
|
||||
return true
|
||||
|
@ -9,9 +9,19 @@ end)
|
||||
function skywars.remove_armor(player)
|
||||
if minetest.get_modpath("3d_armor") then
|
||||
armor:remove_all(player)
|
||||
skywars.HUD_armor_remove(player)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
armor:register_on_equip(function(player, index, stack)
|
||||
if arena_lib.is_player_in_arena(player:get_player_name(), "skywars") then
|
||||
skywars.HUD_armor_update(player, stack)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
||||
dofile(minetest.get_modpath("skywars") .. "/src/_compatible_mods/3d_armor/auto_equip_armors.lua")
|
||||
dofile(minetest.get_modpath("skywars") .. "/src/_compatible_mods/3d_armor/armor_hud.lua")
|
Loading…
x
Reference in New Issue
Block a user