Add in armor GUI

This commit is contained in:
oilboi 2020-05-31 00:55:13 -04:00
parent 861ee7c9d4
commit 5e1ddf3e47
4 changed files with 46 additions and 9 deletions

View File

@ -74,6 +74,16 @@ function calculate_armor_absorbtion(player)
return(armor_absorbtion)
end
function set_armor_gui(player)
if not player or (player and not player:is_player()) then return end
local meta = player:get_meta()
local level = calculate_armor_absorbtion(player)
local hud = meta:get_int("armor_bar")
player:hud_change(hud, "number", level)
end
function damage_armor(player,damage)
if not player or (player and not player:is_player()) then return end
@ -132,13 +142,35 @@ function damage_armor(player,damage)
if recalc == true then
minetest.sound_play("armor_break",{to_player=player:get_player_name(),gain=1,pitch=math.random(80,100)/100})
recalculate_armor(player)
set_armor_gui(player)
--do particles too
end
end
minetest.register_on_joinplayer(function(player)
local inv = player:get_inventory()
minetest.register_on_joinplayer(function(player)
local meta = player:get_meta()
player:hud_add({
hud_elem_type = "statbar",
position = {x = 0.5, y = 1},
text = "armor_icon_bg.png",
number = 20,
--direction = 1,
size = {x = 24, y = 24},
offset = {x = (-10 * 24) - 25, y = -(48 + 50 + 39)},
})
local armor_bar = player:hud_add({
hud_elem_type = "statbar",
position = {x = 0.5, y = 1},
text = "armor_icon.png",
number = calculate_armor_absorbtion(player),--meta:get_int("hunger"),
--direction = 1,
size = {x = 24, y = 24},
offset = {x = (-10 * 24) - 25, y = -(48 + 50 + 39)},
})
meta:set_int("armor_bar", armor_bar)
local inv = player:get_inventory()
inv:set_size("armor_head" ,1)
inv:set_size("armor_torso",1)
inv:set_size("armor_legs" ,1)
@ -149,11 +181,16 @@ minetest.register_on_joinplayer(function(player)
end)
end)
minetest.register_on_dieplayer(function(player)
set_armor_gui(player)
end)
minetest.register_on_player_inventory_action(function(player, action, inventory, inventory_info)
if inventory_info.from_list == "armor_head" or inventory_info.from_list == "armor_torso" or inventory_info.from_list == "armor_legs" or inventory_info.from_list == "armor_feet" or
inventory_info.to_list == "armor_head" or inventory_info.to_list == "armor_torso" or inventory_info.to_list == "armor_legs" or inventory_info.to_list == "armor_feet" then
minetest.after(0,function()
recalculate_armor(player)
set_armor_gui(player)
end)
end
end)

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -7,14 +7,7 @@ minetest.register_on_player_hpchange(function(player, hp_change, reason)
minetest.sound_play("hurt", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
end
elseif hp_change < 0 then
local hp_modifier = math.ceil(calculate_armor_absorbtion(player)/2)
damage_armor(player,math.abs(hp_change))
hp_change = hp_change + hp_modifier
minetest.sound_play("hurt", {object=player, gain = 1.0, max_hear_distance = 60,pitch = math.random(80,100)/100})
if hp_change >= 0 then
hp_change = -1
end
end
return(hp_change)
end, true)
@ -215,6 +208,13 @@ minetest.register_on_punchplayer(function(player, hitter, time_from_last_punch,
if vel.y <= 0 then
dir.y = 7
end
local hp_modifier = math.ceil(calculate_armor_absorbtion(player)/2)
damage_armor(player,math.abs(hurt))
hurt = hurt - hp_modifier
if hurt <= 0 then
hurt = 1
end
punch_timers[name] = 0
player:add_player_velocity(dir)
player:set_hp(hp-hurt)