git subrepo clone http://repo.or.cz/minetest_hbarmor.git mods/minetest_hbarmor
subrepo: subdir: "mods/minetest_hbarmor" merged: "878a351" upstream: origin: "http://repo.or.cz/minetest_hbarmor.git" branch: "master" commit: "878a351" git-subrepo: version: "0.3.1" origin: "https://github.com/ingydotnet/git-subrepo" commit: "a7ee886"
This commit is contained in:
parent
e2c75bbd22
commit
cc0827b25c
11
mods/minetest_hbarmor/.gitrepo
Normal file
11
mods/minetest_hbarmor/.gitrepo
Normal file
@ -0,0 +1,11 @@
|
||||
; DO NOT EDIT (unless you know what you are doing)
|
||||
;
|
||||
; This subdirectory is a git "subrepo", and this file is maintained by the
|
||||
; git-subrepo command. See https://github.com/git-commands/git-subrepo#readme
|
||||
;
|
||||
[subrepo]
|
||||
remote = http://repo.or.cz/minetest_hbarmor.git
|
||||
branch = master
|
||||
commit = 878a351e9db2905dec0bb3e9d809b33ce5a65ed0
|
||||
parent = e2c75bbd22c6619411bbcc0c2bc6875e9b34fff2
|
||||
cmdver = 0.3.1
|
43
mods/minetest_hbarmor/README.md
Normal file
43
mods/minetest_hbarmor/README.md
Normal file
@ -0,0 +1,43 @@
|
||||
# HUD bar for `3d_armor` [`hbarmor`]
|
||||
|
||||
* Version: 0.2.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: WTFPL (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 (WTFPL)
|
||||
|
||||
Everything else is WTFPL:
|
||||
© 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 Do What The Fuck You Want
|
||||
To Public License, Version 2, as published by Sam Hocevar. See
|
||||
http://sam.zoy.org/wtfpl/COPYING for more details.
|
3
mods/minetest_hbarmor/depends.txt
Normal file
3
mods/minetest_hbarmor/depends.txt
Normal file
@ -0,0 +1,3 @@
|
||||
hudbars
|
||||
3d_armor
|
||||
intllib?
|
1
mods/minetest_hbarmor/description.txt
Normal file
1
mods/minetest_hbarmor/description.txt
Normal file
@ -0,0 +1 @@
|
||||
Adds a HUD bar displaying the current damage of the player's armor.
|
154
mods/minetest_hbarmor/init.lua
Normal file
154
mods/minetest_hbarmor/init.lua
Normal file
@ -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.setting_getbool("hbarmor_autohide")
|
||||
if set ~= nil then
|
||||
hbarmor.autohide = set
|
||||
end
|
||||
|
||||
set = minetest.setting_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.setting_getbool("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.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.setting_getbool("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)
|
2
mods/minetest_hbarmor/locale/de.txt
Normal file
2
mods/minetest_hbarmor/locale/de.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Armor = Panzerung
|
||||
%s: %d%% = %s: %d%%
|
4
mods/minetest_hbarmor/locale/template.txt
Normal file
4
mods/minetest_hbarmor/locale/template.txt
Normal file
@ -0,0 +1,4 @@
|
||||
Armor =
|
||||
|
||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
||||
%s: %d%% =
|
1
mods/minetest_hbarmor/mod.conf
Normal file
1
mods/minetest_hbarmor/mod.conf
Normal file
@ -0,0 +1 @@
|
||||
name = hbarmor
|
BIN
mods/minetest_hbarmor/screenshot.png
Normal file
BIN
mods/minetest_hbarmor/screenshot.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
7
mods/minetest_hbarmor/settingtypes.txt
Normal file
7
mods/minetest_hbarmor/settingtypes.txt
Normal file
@ -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
|
BIN
mods/minetest_hbarmor/textures/hbarmor_bar.png
Normal file
BIN
mods/minetest_hbarmor/textures/hbarmor_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.7 KiB |
BIN
mods/minetest_hbarmor/textures/hbarmor_bgicon.png
Normal file
BIN
mods/minetest_hbarmor/textures/hbarmor_bgicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 424 B |
BIN
mods/minetest_hbarmor/textures/hbarmor_icon.png
Normal file
BIN
mods/minetest_hbarmor/textures/hbarmor_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
Loading…
x
Reference in New Issue
Block a user