forked from mtcontrib/minetest_mana
Add Mana regeneration
This commit is contained in:
parent
271c994267
commit
97f1079852
30
init.lua
30
init.lua
@ -14,12 +14,24 @@ mana.playerlist = {}
|
||||
|
||||
mana.settings = {}
|
||||
mana.settings.default_max = 200
|
||||
mana.settings.default_regen = 1
|
||||
mana.settings.regen_timer = 0.1
|
||||
|
||||
do
|
||||
local default_max = tonumber(minetest.setting_get("mana_default_max"))
|
||||
if default_max ~= nil then
|
||||
mana.settings.default_max = default_max
|
||||
end
|
||||
|
||||
local default_regen = tonumber(minetest.setting_get("mana_default_regen"))
|
||||
if default_regen ~= nil then
|
||||
mana.settings.default_regen = default_regen
|
||||
end
|
||||
|
||||
local regen_timer = tonumber(minetest.setting_get("mana_regen_timer"))
|
||||
if regen_timer ~= nil then
|
||||
mana.settings.regen_timer = regen_timer
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -189,6 +201,7 @@ minetest.register_on_joinplayer(function(player)
|
||||
mana.playerlist[playername] = {}
|
||||
mana.playerlist[playername].mana = 0
|
||||
mana.playerlist[playername].maxmana = mana.settings.default_max
|
||||
mana.playerlist[playername].regen = mana.settings.default_regen
|
||||
end
|
||||
|
||||
if minetest.get_modpath("hudbars") ~= nil then
|
||||
@ -199,6 +212,21 @@ minetest.register_on_joinplayer(function(player)
|
||||
end)
|
||||
|
||||
|
||||
--[===[
|
||||
Mana regeneration
|
||||
]===]
|
||||
|
||||
mana.regen_timer = 0
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
mana.regen_timer = mana.regen_timer + dtime
|
||||
if mana.regen_timer >= mana.settings.regen_timer then
|
||||
for name, infotable in pairs(mana.playerlist) do
|
||||
mana.add_up_to(name, infotable.regen)
|
||||
end
|
||||
mana.regen_timer = 0
|
||||
end
|
||||
end)
|
||||
|
||||
--[===[
|
||||
HUD functions
|
||||
@ -209,8 +237,10 @@ if minetest.get_modpath("hudbars") ~= nil then
|
||||
|
||||
function mana.hud_update(playername)
|
||||
local player = minetest.get_player_by_name(playername)
|
||||
if player ~= nil then
|
||||
hb.change_hudbar(player, "mana", mana.get(playername), mana.getmax(playername))
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user