forked from mtcontrib/minetest_mana
Add optional compability with hudbars mod
This commit is contained in:
parent
205084ae1e
commit
b65e0ae812
6
README.txt
Normal file
6
README.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
License information:
|
||||
|
||||
textures/mana_icon.png: CC-BY by Buch <http://opengameart.org/users/Buch>.
|
||||
textures/mana_bar.png: WTFPL by Wuzzy.
|
||||
|
||||
Everything else: WTFPL.
|
1
depends.txt
Normal file
1
depends.txt
Normal file
|
@ -0,0 +1 @@
|
|||
hudbars?
|
27
init.lua
27
init.lua
|
@ -151,10 +151,14 @@ minetest.register_on_joinplayer(function(player)
|
|||
if mana.playerlist[playername] == nil then
|
||||
mana.playerlist[playername] = {}
|
||||
mana.playerlist[playername].mana = 0
|
||||
mana.playerlist[playername].maxmana = 20
|
||||
mana.playerlist[playername].maxmana = 100
|
||||
end
|
||||
|
||||
if minetest.get_modpath("hudbars") ~= nil then
|
||||
hud.hudtables.mana.add_all(player, mana.get(playername), mana.getmax(playername))
|
||||
else
|
||||
mana.hud_add(playername)
|
||||
end
|
||||
end)
|
||||
|
||||
|
||||
|
@ -163,6 +167,16 @@ end)
|
|||
HUD functions
|
||||
]===]
|
||||
|
||||
if minetest.get_modpath("hudbars") ~= nil then
|
||||
hud.register_hudbar("mana", 0xFFFFFF, "Mana", { bar = "mana_bar.png", icon = "mana_icon.png" }, 0, 100, false)
|
||||
|
||||
function mana.hud_update(playername)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
hud.change_hudbar(player, hud.hudtables.mana, mana.get(playername), mana.getmax(playername))
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
function mana.manastring(playername)
|
||||
return string.format("Mana: %d/%d", mana.get(playername), mana.getmax(playername))
|
||||
end
|
||||
|
@ -171,14 +185,13 @@ function mana.hud_add(playername)
|
|||
local player = minetest.get_player_by_name(playername)
|
||||
id = player:hud_add({
|
||||
hud_elem_type = "text",
|
||||
position = { x = 1, y=0.3 },
|
||||
name = "mana",
|
||||
position = { x = 0.5, y=0.9 },
|
||||
text = mana.manastring(playername),
|
||||
scale = { x = 0, y = 0 },
|
||||
alignment = { x = -1, y = 0},
|
||||
alignment = { x = 1, y = 0},
|
||||
direction = 1,
|
||||
number = 0xFFFFFF,
|
||||
offset = { x = 0, y = 0}
|
||||
offset = { x = -200, y = 15}
|
||||
})
|
||||
mana.playerlist[playername].hudid = id
|
||||
return id
|
||||
|
@ -186,10 +199,12 @@ end
|
|||
|
||||
function mana.hud_update(playername)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
player:hud_change(mana.playerlist[playername].hudid, "text", mana.manastring(playername))
|
||||
player:hud_change(mana.playerlist[playername].hudid, "number", mana.get(playername))
|
||||
end
|
||||
|
||||
function mana.hud_remove(playername)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
player:hud_remove(mana.playerlist[playername].hudid)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
BIN
textures/mana_bar.png
Normal file
BIN
textures/mana_bar.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 80 B |
BIN
textures/mana_icon.png
Normal file
BIN
textures/mana_icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
Loading…
Reference in New Issue
Block a user