mirror of
https://repo.or.cz/minetest_hbarmor.git
synced 2025-06-28 22:36:29 +02:00
Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
9d41c0f34d |
42
README.md
42
README.md
@ -1,42 +0,0 @@
|
||||
# HUD bar for `3d_armor` [`hbarmor`]
|
||||
|
||||
* Version: 1.0.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 2
|
||||
* 3D Armor [`3d_armor`] (tested with Minetest 5.0.0)
|
||||
|
||||
## 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.
|
48
README.txt
Executable file
48
README.txt
Executable file
@ -0,0 +1,48 @@
|
||||
Minetest mod: HUD bar for armor [hbarmor]
|
||||
=========================================
|
||||
Version: 0.1.0
|
||||
|
||||
License of source code: WTFPL
|
||||
-----------------------------
|
||||
By Wuzzy,
|
||||
|
||||
forked from the mod “Better HUD (and hunger)” [hud]
|
||||
by BlockMen (2013-2014).
|
||||
|
||||
|
||||
|
||||
Using the mod:
|
||||
--------------
|
||||
This mod adds a simple HUD bar which displays the current
|
||||
damage of the player's armor (from the 3D Armor mod) as a percentage,
|
||||
this number is of course rounded.
|
||||
100% 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 0.4.3)
|
||||
|
||||
|
||||
|
||||
License of textures:
|
||||
--------------------
|
||||
hbarmor_icon.png - Stu (CC BY-SA 3.0), modified by BlockMen
|
||||
hbarmor_bar.png - Wuzzy (WTFPL)
|
||||
|
||||
|
||||
everything else is WTFPL:
|
||||
(c) 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.
|
37
armor.lua
Executable file
37
armor.lua
Executable file
@ -0,0 +1,37 @@
|
||||
minetest.after(0, function()
|
||||
if not armor.def then
|
||||
minetest.after(2,minetest.chat_send_all,"#Better HUD: Please update your version of 3darmor")
|
||||
HUD_SHOW_ARMOR = false
|
||||
end
|
||||
end)
|
||||
|
||||
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] = lvl* (items * (100 / max_items))
|
||||
|
||||
|
||||
end
|
88
changelog.txt
Executable file
88
changelog.txt
Executable file
@ -0,0 +1,88 @@
|
||||
0.2 Beta
|
||||
--------
|
||||
- added support of custom config files
|
||||
- you can eat max. 50% more than before (although it isnt shown in hunger bar)
|
||||
- you get healed with 8 breads and more (in hunger bar) now
|
||||
- a bread (from farming) == 2 breads in hunger bar
|
||||
|
||||
0.2.1 Beta
|
||||
----------
|
||||
- tweaked override of food
|
||||
- added support for food of dwares, moretrees and simple mobs
|
||||
|
||||
0.2.2 Beta
|
||||
----------
|
||||
- added support for food of animalmaterials (mobf modpack),fishing
|
||||
|
||||
0.2.3 Beta
|
||||
----------
|
||||
- added support for food of glooptest and bushes (commit by CheeseKeg)
|
||||
|
||||
0.3 Beta
|
||||
----------
|
||||
- added fancy borders of hud inventory bar (only for screenheight <= 800)
|
||||
|
||||
0.4 Beta
|
||||
----------
|
||||
- enabled drowning
|
||||
|
||||
0.5 Beta
|
||||
----------
|
||||
- removed the fancy borders of hud inventory bar and moved to new native support
|
||||
- moved crosshair to native support too
|
||||
|
||||
1.0
|
||||
---
|
||||
- hunger is reset after death
|
||||
- health and hunger bar is shown correct on all screen resolutions now
|
||||
- switched to changed native hotbar image support
|
||||
- fixed revival of player when drown
|
||||
- hunger bar is not shown anymore if hunger is disabled
|
||||
- hunger can be disabled by minetest.conf ("hud_hunger_enable = false")
|
||||
|
||||
1.1
|
||||
---
|
||||
- added support for stu's 3darmor mod
|
||||
- restructured and cleaned up code
|
||||
- added support for poisen food (damages player, but does not kill)
|
||||
|
||||
1.2
|
||||
---
|
||||
- Send statbar values only to client when changed
|
||||
- Hide armor bar if not wearing armor
|
||||
- More reliable food overrides (by CiaranG)
|
||||
- Support for bushes_classic foods (plantlife modpack) (by CiaranG)
|
||||
- Add support for mushroom mod food/poison (by CiaranG)
|
||||
- Add support for mods: fruit and mush45
|
||||
- New images for hotbar, smaller armor icons
|
||||
|
||||
1.3
|
||||
---
|
||||
- New way hunger is saved (all old files in world dirctory can get deleted [e.g. hud_BlockMen_hunger])
|
||||
- Fixed healing (not while drowning, fix after death)
|
||||
- Add support for mods: seaplants[sea] and mobfcooking (by Xanthin)
|
||||
- Tweaked hand image
|
||||
- Player can die caus of starving now
|
||||
|
||||
1.3.1
|
||||
-----
|
||||
- Add compatibility for statbar scaling
|
||||
- Fix typo in depends.txt
|
||||
- Lower maintimer tick
|
||||
|
||||
1.3.2
|
||||
-----
|
||||
- Fix dependecies (by Chris Beelby)
|
||||
- Add support for creatures mod
|
||||
- Add optional healing for food (by TenPlus1)
|
||||
|
||||
1.3.3
|
||||
-----
|
||||
- Prevent crash with armor mod and missing player
|
||||
- Add support for ethereal mod (by TenPlus1)
|
||||
|
||||
1.4
|
||||
---
|
||||
- New hunger mechanics/added experimental player-action based hunger
|
||||
- Better crosshair texture, switched to "new" default hand
|
||||
- Added support for farming redo mod, kpgmobs and jkmod
|
2
depends.txt
Executable file
2
depends.txt
Executable file
@ -0,0 +1,2 @@
|
||||
hudbars
|
||||
3d_armor
|
9
hbarmor.conf.example
Executable file
9
hbarmor.conf.example
Executable file
@ -0,0 +1,9 @@
|
||||
-- If true, automatically hides the armor when the player wears no armor.
|
||||
-- Otherwise, the armor bar shows “0%”.
|
||||
|
||||
--hbarmor.autohide = true
|
||||
|
||||
-- Time difference in seconds between updates to the HUD armor bar.
|
||||
-- Increase this number for slow servers.
|
||||
|
||||
-- hbarmor.tick = 0.1
|
94
init.lua
Normal file → Executable file
94
init.lua
Normal file → Executable file
@ -1,11 +1,4 @@
|
||||
local S = minetest.get_translator("hbarmor")
|
||||
local N = function(s) return s 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 = {}
|
||||
hbarmor = {}
|
||||
|
||||
-- HUD statbar values
|
||||
hbarmor.armor = {}
|
||||
@ -13,25 +6,21 @@ 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.
|
||||
-- HUD item ids
|
||||
local armor_hud = {}
|
||||
|
||||
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
|
||||
local set = io.open(minetest.get_modpath("hbarmor").."/hbarmor.conf", "r")
|
||||
if set then
|
||||
dofile(minetest.get_modpath("hbarmor").."/hbarmor.conf")
|
||||
set:close()
|
||||
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
|
||||
@ -43,7 +32,7 @@ end
|
||||
local function custom_hud(player)
|
||||
local name = player:get_player_name()
|
||||
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
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!")
|
||||
@ -61,41 +50,15 @@ local function custom_hud(player)
|
||||
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, N("@1: @2%"), { order = { "label", "value" }, textdomain = "hbarmor" } )
|
||||
hb.register_hudbar("armor", 0xFFFFFF, "Armor", { icon = "hbarmor_icon.png", bar = "hbarmor_bar.png" }, 0, 100, hbarmor.autohide, "%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
|
||||
dofile(minetest.get_modpath("hbarmor").."/armor.lua")
|
||||
|
||||
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
|
||||
--armor
|
||||
local arm = tonumber(hbarmor.armor[name])
|
||||
if not arm then
|
||||
arm = 0
|
||||
@ -125,26 +88,21 @@ minetest.register_on_leaveplayer(function(player)
|
||||
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)
|
||||
local function hbarmor_step()
|
||||
if minetest.setting_getbool("enable_damage") then
|
||||
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 step returned with false!")
|
||||
end
|
||||
-- update all hud elements
|
||||
update_hud(player)
|
||||
end
|
||||
end
|
||||
end
|
||||
if timer > 4 then timer = 0 end
|
||||
end)
|
||||
|
||||
minetest.after(hbarmor.tick, hbarmor_step)
|
||||
end
|
||||
minetest.after(0, hbarmor_step)
|
||||
|
@ -1,3 +0,0 @@
|
||||
# textdomain:hbarmor
|
||||
Armor=Panzerung
|
||||
@1: @2%=@1: @2%
|
@ -1,3 +0,0 @@
|
||||
# textdomain:hbarmor
|
||||
Armor=Armatura
|
||||
@1: @2%=@1:@2%
|
@ -1,5 +0,0 @@
|
||||
# textdomain:hbarmor
|
||||
Armor=
|
||||
|
||||
# Format string for displaying the armor. E.g. "Armor: 100%"
|
||||
@1: @2%=
|
3
mod.conf
3
mod.conf
@ -1,3 +0,0 @@
|
||||
name = hbarmor
|
||||
description = Adds a HUD bar displaying the current damage of the player's armor.
|
||||
depends = hudbars, 3d_armor
|
BIN
screenshot.png
BIN
screenshot.png
Binary file not shown.
Before Width: | Height: | Size: 11 KiB |
@ -1,7 +0,0 @@
|
||||
#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
textures/hbarmor_bar.png
Normal file → Executable file
BIN
textures/hbarmor_bar.png
Normal file → Executable file
Binary file not shown.
Before Width: | Height: | Size: 70 B After Width: | Height: | Size: 82 B |
Binary file not shown.
Before Width: | Height: | Size: 369 B |
BIN
textures/hbarmor_icon.png
Normal file → Executable file
BIN
textures/hbarmor_icon.png
Normal file → Executable file
Binary file not shown.
Before Width: | Height: | Size: 361 B After Width: | Height: | Size: 397 B |
Reference in New Issue
Block a user