forked from mtcontrib/minetest_mana
Regen can now be a float and negative
This commit is contained in:
parent
6f1b549931
commit
336b6dac87
20
init.lua
20
init.lua
@ -70,11 +70,6 @@ function mana.setmax(playername, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function mana.setregen(playername, value)
|
function mana.setregen(playername, value)
|
||||||
if value < 0 then
|
|
||||||
value = 0
|
|
||||||
minetest.log("info", "[mana] Warning: mana.setregen was called with negative value!")
|
|
||||||
end
|
|
||||||
value = mana.round(value)
|
|
||||||
mana.playerlist[playername].regen = value
|
mana.playerlist[playername].regen = value
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -223,6 +218,7 @@ minetest.register_on_joinplayer(function(player)
|
|||||||
mana.playerlist[playername].mana = 0
|
mana.playerlist[playername].mana = 0
|
||||||
mana.playerlist[playername].maxmana = mana.settings.default_max
|
mana.playerlist[playername].maxmana = mana.settings.default_max
|
||||||
mana.playerlist[playername].regen = mana.settings.default_regen
|
mana.playerlist[playername].regen = mana.settings.default_regen
|
||||||
|
mana.playerlist[playername].remainder = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
if minetest.get_modpath("hudbars") ~= nil then
|
if minetest.get_modpath("hudbars") ~= nil then
|
||||||
@ -248,7 +244,19 @@ minetest.register_globalstep(function(dtime)
|
|||||||
local name = players[i]:get_player_name()
|
local name = players[i]:get_player_name()
|
||||||
if mana.playerlist[name] ~= nil then
|
if mana.playerlist[name] ~= nil then
|
||||||
if players[i]:get_hp() > 0 then
|
if players[i]:get_hp() > 0 then
|
||||||
mana.add_up_to(name, mana.playerlist[name].regen * factor)
|
local plus = mana.playerlist[name].regen * factor
|
||||||
|
-- Compability check for version <= 1.0.2 which did not have the remainder field
|
||||||
|
if mana.playerlist[name].remainder ~= nil then
|
||||||
|
plus = plus + mana.playerlist[name].remainder
|
||||||
|
end
|
||||||
|
local plus_now = math.floor(plus)
|
||||||
|
local floor = plus - plus_now
|
||||||
|
if plus_now > 0 then
|
||||||
|
mana.add_up_to(name, plus_now)
|
||||||
|
else
|
||||||
|
mana.subtract_up_to(name, math.abs(plus_now))
|
||||||
|
end
|
||||||
|
mana.playerlist[name].remainder = floor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user