Rename mod: hbarmor → mcl_hbarmor
This commit is contained in:
parent
e3b68c4364
commit
bef99ac211
16 changed files with 60 additions and 86 deletions
26
mods/HUD/mcl_hbarmor/README.md
Normal file
26
mods/HUD/mcl_hbarmor/README.md
Normal file
|
@ -0,0 +1,26 @@
|
|||
# MineClone 2 HUD bar for `3d_armor` [`mcl_hbarmor`]
|
||||
|
||||
## Description
|
||||
This mod adds a simple HUD bar which displays the player's armor points.
|
||||
The players has 0-20 armor points.
|
||||
|
||||
The armor bar is hidden if the player wears no armor.
|
||||
|
||||
## Licensing
|
||||
This mod is entirly free softare.
|
||||
|
||||
### Source code
|
||||
License: MIT License (see below)
|
||||
|
||||
### Textures
|
||||
|
||||
See MineClone 2 license.
|
||||
|
||||
### 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.
|
1
mods/HUD/mcl_hbarmor/description.txt
Normal file
1
mods/HUD/mcl_hbarmor/description.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Adds a HUD bar displaying the current damage of the player's armor.
|
135
mods/HUD/mcl_hbarmor/init.lua
Normal file
135
mods/HUD/mcl_hbarmor/init.lua
Normal file
|
@ -0,0 +1,135 @@
|
|||
local S = minetest.get_translator("mcl_hbarmor")
|
||||
|
||||
if (not armor) or (not armor.def) then
|
||||
minetest.log("error", "[mcl_hbarmor] Outdated 3d_armor version. Please update your version of 3d_armor!")
|
||||
end
|
||||
|
||||
local mcl_hbarmor = {}
|
||||
|
||||
-- HUD statbar values
|
||||
mcl_hbarmor.armor = {}
|
||||
|
||||
-- Stores if player's HUD bar has been initialized so far.
|
||||
mcl_hbarmor.player_active = {}
|
||||
|
||||
-- Time difference in seconds between updates to the HUD armor bar.
|
||||
-- Increase this number for slow servers.
|
||||
mcl_hbarmor.tick = 0.1
|
||||
|
||||
-- If true, the armor bar is hidden when the player does not wear any armor
|
||||
mcl_hbarmor.autohide = true
|
||||
|
||||
set = minetest.settings:get("mcl_hbarmor_tick")
|
||||
if tonumber(set) ~= nil then
|
||||
mcl_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 = mcl_hbarmor.get_armor(player)
|
||||
if ret == false then
|
||||
minetest.log("error", "[mcl_hbarmor] Call to mcl_hbarmor.get_armor in custom_hud returned with false!")
|
||||
return
|
||||
end
|
||||
local arm = tonumber(mcl_hbarmor.armor[name])
|
||||
if not arm then
|
||||
arm = 0
|
||||
end
|
||||
local hide
|
||||
if mcl_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, 20, mcl_hbarmor.autohide)
|
||||
|
||||
function mcl_hbarmor.get_armor(player)
|
||||
if not player or not armor.def then
|
||||
return false
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
local pts = armor:get_armor_points(player)
|
||||
if not pts then
|
||||
return false
|
||||
else
|
||||
mcl_hbarmor.set_armor(name, pts)
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function mcl_hbarmor.set_armor(player_name, pts)
|
||||
mcl_hbarmor.armor[player_name] = math.max(0, math.min(20, pts))
|
||||
end
|
||||
|
||||
-- update hud elemtens if value has changed
|
||||
local function update_hud(player)
|
||||
local name = player:get_player_name()
|
||||
--armor
|
||||
local arm = tonumber(mcl_hbarmor.armor[name])
|
||||
if not arm then
|
||||
arm = 0
|
||||
mcl_hbarmor.armor[name] = 0
|
||||
end
|
||||
if mcl_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)
|
||||
mcl_hbarmor.player_active[name] = true
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
local name = player:get_player_name()
|
||||
mcl_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 > mcl_hbarmor.tick or timer > 4 then
|
||||
if minetest.settings:get_bool("enable_damage") then
|
||||
if main_timer > mcl_hbarmor.tick then main_timer = 0 end
|
||||
for _,player in ipairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
if mcl_hbarmor.player_active[name] == true then
|
||||
local ret = mcl_hbarmor.get_armor(player)
|
||||
if ret == false then
|
||||
minetest.log("error", "[mcl_hbarmor] Call to mcl_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/HUD/mcl_hbarmor/locale/hbarmor.de.tr
Normal file
2
mods/HUD/mcl_hbarmor/locale/hbarmor.de.tr
Normal file
|
@ -0,0 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=Panzerung
|
2
mods/HUD/mcl_hbarmor/locale/hbarmor.es.tr
Normal file
2
mods/HUD/mcl_hbarmor/locale/hbarmor.es.tr
Normal file
|
@ -0,0 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=Armadura
|
2
mods/HUD/mcl_hbarmor/locale/hbarmor.it.tr
Normal file
2
mods/HUD/mcl_hbarmor/locale/hbarmor.it.tr
Normal file
|
@ -0,0 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=Armatura
|
2
mods/HUD/mcl_hbarmor/locale/template.txt
Normal file
2
mods/HUD/mcl_hbarmor/locale/template.txt
Normal file
|
@ -0,0 +1,2 @@
|
|||
# textdomain:hbarmor
|
||||
Armor=
|
2
mods/HUD/mcl_hbarmor/mod.conf
Normal file
2
mods/HUD/mcl_hbarmor/mod.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
name = mcl_hbarmor
|
||||
depends = hudbars, 3d_armor
|
3
mods/HUD/mcl_hbarmor/settingtypes.txt
Normal file
3
mods/HUD/mcl_hbarmor/settingtypes.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
#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/HUD/mcl_hbarmor/textures/hbarmor_bar.png
Normal file
BIN
mods/HUD/mcl_hbarmor/textures/hbarmor_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 91 B |
BIN
mods/HUD/mcl_hbarmor/textures/hbarmor_bgicon.png
Normal file
BIN
mods/HUD/mcl_hbarmor/textures/hbarmor_bgicon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 896 B |
BIN
mods/HUD/mcl_hbarmor/textures/hbarmor_icon.png
Normal file
BIN
mods/HUD/mcl_hbarmor/textures/hbarmor_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 904 B |
Loading…
Add table
Add a link
Reference in a new issue