Add 'hbarmor/' from commit 'e513aeb9cbfad2ddb1714f7808d1a977666d9430'
git-subtree-dir: hbarmor git-subtree-mainline:master62390d81c8
git-subtree-split:e513aeb9cb
commit
a503ec1800
|
@ -0,0 +1,42 @@
|
|||
# HUD bar for `3d_armor` [`hbarmor`]
|
||||
|
||||
* Version: 0.4.0
|
||||
|
||||
## Description
|
||||
This mod adds a simple HUD bar which displays the current damage
|
||||
of the player's armor (from the 3D Armor [`3d_armor`] mod) as a percentage (rounded).
|
||||
|
||||
100% armor means the armor is in perfect shape. 0% means the armor is almost destroyed
|
||||
or non-existant. Note that to reach 100%, the player must wear at least 4 different
|
||||
pieces of armor in perfect shape.
|
||||
|
||||
The armor bar also does not tell anything about the armor's strength,
|
||||
only how worn out it already is.
|
||||
|
||||
By default, the armor bar is hidden if the player wears no armor.
|
||||
|
||||
## Dependencies
|
||||
* HUD bars [`hudbars`], major version 1
|
||||
* 3D Armor [`3d_armor`] (tested with Minetest 0.4.14)
|
||||
|
||||
## Licensing
|
||||
This mod is entirly free softare.
|
||||
|
||||
### Source code
|
||||
|
||||
* License: MIT License (see below)
|
||||
* Authors: Wuzzy, forked from the mod “Better HUD (and hunger)” [`hud`] by BlockMen (2013-2014)
|
||||
|
||||
### Textures
|
||||
|
||||
* `hbarmor_icon.png`—Stu ([CC BY-SA 3.0](https://creativecommons.org/licenses/by-sa/3.0/)), modified by BlockMen
|
||||
* `hbarmor_bgicon.png`—Stu (CC BY-SA 3.0), modified by BlockMen
|
||||
* `hbarmor_bar.png`—Wuzzy (MIT License)
|
||||
|
||||
Everything else is under the MIT License:
|
||||
© Copyright BlockMen (2013-2014)
|
||||
|
||||
This program is free software. It comes without any warranty, to
|
||||
the extent permitted by applicable law. You can redistribute it
|
||||
and/or modify it under the terms of the MIT License.
|
||||
See <https://opensource.org/licenses/MIT> for more details.
|
|
@ -0,0 +1,3 @@
|
|||
hudbars
|
||||
3d_armor
|
||||
intllib?
|
|
@ -0,0 +1 @@
|
|||
Adds a HUD bar displaying the current damage of the player's armor.
|
|
@ -0,0 +1,154 @@
|
|||
local S
|
||||
if (minetest.get_modpath("intllib")) then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
S = function ( s ) return s end
|
||||
end
|
||||
|
||||
if (not armor) or (not armor.def) then
|
||||
minetest.log("error", "[hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
|
||||
end
|
||||
|
||||
local hbarmor = {}
|
||||
|
||||
-- HUD statbar values
|
||||
hbarmor.armor = {}
|
||||
|
||||
-- Stores if player's HUD bar has been initialized so far.
|
||||
hbarmor.player_active = {}
|
||||
|
||||
-- Time difference in seconds between updates to the HUD armor bar.
|
||||
-- Increase this number for slow servers.
|
||||
hbarmor.tick = 0.1
|
||||
|
||||
-- If true, the armor bar is hidden when the player does not wear any armor
|
||||
hbarmor.autohide = true
|
||||
|
||||
--load custom settings
|
||||
local set = minetest.settings:get_bool("hbarmor_autohide")
|
||||
if set ~= nil then
|
||||
hbarmor.autohide = set
|
||||
end
|
||||
|
||||
set = minetest.settings:get("hbarmor_tick")
|
||||
if tonumber(set) ~= nil then
|
||||
hbarmor.tick = tonumber(set)
|
||||
end
|
||||
|
||||
|
||||
local must_hide = function(playername, arm)
|
||||
return ((not armor.def[playername].count or armor.def[playername].count == 0) and arm == 0)
|
||||
end
|
||||
|
||||
local arm_printable = function(arm)
|
||||
return math.ceil(math.floor(arm+0.5))
|
||||
end
|
||||
|
||||
local function custom_hud(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
local ret = hbarmor.get_armor(player)
|
||||
if ret == false then
|
||||
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in custom_hud returned with false!")
|
||||
end
|
||||
local arm = tonumber(hbarmor.armor[name])
|
||||
if not arm then arm = 0 end
|
||||
local hide
|
||||
if hbarmor.autohide then
|
||||
hide = must_hide(name, arm)
|
||||
else
|
||||
hide = false
|
||||
end
|
||||
hb.init_hudbar(player, "armor", arm_printable(arm), nil, hide)
|
||||
end
|
||||
end
|
||||
|
||||
--register and define armor HUD bar
|
||||
hb.register_hudbar("armor", 0xFFFFFF, S("Armor"), { icon = "hbarmor_icon.png", bgicon = "hbarmor_bgicon.png", bar = "hbarmor_bar.png" }, 0, 100, hbarmor.autohide, S("%s: %d%%"))
|
||||
|
||||
function hbarmor.get_armor(player)
|
||||
if not player or not armor.def then
|
||||
return false
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local def = armor.def[name] or nil
|
||||
if def and def.state and def.count then
|
||||
hbarmor.set_armor(name, def.state, def.count)
|
||||
else
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function hbarmor.set_armor(player_name, ges_state, items)
|
||||
local max_items = 4
|
||||
if items == 5 then
|
||||
max_items = items
|
||||
end
|
||||
local max = max_items * 65535
|
||||
local lvl = max - ges_state
|
||||
lvl = lvl/max
|
||||
if ges_state == 0 and items == 0 then
|
||||
lvl = 0
|
||||
end
|
||||
|
||||
hbarmor.armor[player_name] = math.max(0, math.min(lvl* (items * (100 / max_items)), 100))
|
||||
end
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
local function update_hud(player)
|
||||
local name = player:get_player_name()
|
||||
--armor
|
||||
local arm = tonumber(hbarmor.armor[name])
|
||||
if not arm then
|
||||
arm = 0
|
||||
hbarmor.armor[name] = 0
|
||||
end
|
||||
if hbarmor.autohide then
|
||||
-- hide armor bar completely when there is none
|
||||
if must_hide(name, arm) then
|
||||
hb.hide_hudbar(player, "armor")
|
||||
else
|
||||
hb.change_hudbar(player, "armor", arm_printable(arm))
|
||||
hb.unhide_hudbar(player, "armor")
|
||||
end
|
||||
else
|
||||
hb.change_hudbar(player, "armor", arm_printable(arm))
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
custom_hud(player)
|
||||
hbarmor.player_active[name] = true
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
hbarmor.player_active[name] = false
|
||||
end)
|
||||
|
||||
local main_timer = 0
|
||||
local timer = 0
|
||||
minetest.register_globalstep(function(dtime)
|
||||
main_timer = main_timer + dtime
|
||||
timer = timer + dtime
|
||||
if main_timer > hbarmor.tick or timer > 4 then
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
if main_timer > hbarmor.tick then main_timer = 0 end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
if hbarmor.player_active[name] == true then
|
||||
local ret = hbarmor.get_armor(player)
|
||||
if ret == false then
|
||||
minetest.log("error", "[hbarmor] Call to hbarmor.get_armor in globalstep returned with false!")
|
||||
end
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if timer > 4 then timer = 0 end
|
||||
end)
|
|
@ -0,0 +1,2 @@
|
|||
Armor = Panzerung
|
||||
%s: %d%% = %s: %d%%
|
|
@ -0,0 +1,4 @@
|
|||
Armor = Armatura
|
||||
|
||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
||||
%s: %d%% =
|
|
@ -0,0 +1,4 @@
|
|||
Armor =
|
||||
|
||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
||||
%s: %d%% =
|
|
@ -0,0 +1 @@
|
|||
name = hbarmor
|
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
|
@ -0,0 +1,7 @@
|
|||
#If true, automatically hides the armor HUD bar when the player wears no
|
||||
#armor. Otherwise, the armor bar shows “0%”.
|
||||
hbarmor_autohide (Automatically hide armor HUD bar) bool true
|
||||
|
||||
#Time difference in seconds between updates to the armor HUD bar.
|
||||
#Increase this number for slow servers.
|
||||
hbarmor_tick (Armor HUD bar update frequency) float 0.1 0.0 4.0
|
Binary file not shown.
After Width: | Height: | Size: 70 B |
Binary file not shown.
After Width: | Height: | Size: 369 B |
Binary file not shown.
After Width: | Height: | Size: 361 B |
Loading…
Reference in New Issue