forked from mtcontrib/minetest_mana
Optimize mana regeneration for slow servers
Slow servers are servers which call globalstep in a lower frequency than specified by the mana tick.
This commit is contained in:
parent
8b02324870
commit
1a4adfb71b
5
init.lua
5
init.lua
@ -240,16 +240,17 @@ mana.regen_timer = 0
|
|||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
mana.regen_timer = mana.regen_timer + dtime
|
mana.regen_timer = mana.regen_timer + dtime
|
||||||
if mana.regen_timer >= mana.settings.regen_timer then
|
if mana.regen_timer >= mana.settings.regen_timer then
|
||||||
|
local factor = math.floor(mana.regen_timer / mana.settings.regen_timer)
|
||||||
local players = minetest.get_connected_players()
|
local players = minetest.get_connected_players()
|
||||||
for i=1, #players do
|
for i=1, #players do
|
||||||
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)
|
mana.add_up_to(name, mana.playerlist[name].regen * factor)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
mana.regen_timer = 0
|
mana.regen_timer = mana.regen_timer % mana.settings.regen_timer
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user