forked from mtcontrib/minetest_mana
Keep mana in bounds when using set and setmax
This commit is contained in:
parent
9563fcffbc
commit
0e3af4e900
34
init.lua
34
init.lua
@ -18,16 +18,38 @@ mana.playerlist = {}
|
||||
API functions
|
||||
]===]
|
||||
|
||||
-- Sets the maximum mana of the specified player
|
||||
--[[ Sets the mana reserves of the specified player
|
||||
It is ensured that the resulting value will always be within the bounds of [0, maxmana]
|
||||
]]
|
||||
function mana.set(playername, value)
|
||||
mana.playerlist[playername].mana = value
|
||||
mana.hud_update(playername)
|
||||
if value < 0 then
|
||||
minetest.log("info", "[mana] Warning: mana.set was called with negative value!")
|
||||
value = 0
|
||||
end
|
||||
if value > mana.playerlist[playername].maxmana then
|
||||
value = mana.playerlist[playername].maxmana
|
||||
end
|
||||
if mana.playerlist[playername].mana ~= value then
|
||||
mana.playerlist[playername].mana = value
|
||||
mana.hud_update(playername)
|
||||
end
|
||||
end
|
||||
|
||||
-- Sets the maximum mana of the specified player
|
||||
--[[ Sets the maximum mana of the specified player. The value must be positive or 0.
|
||||
The player's mana reserves will be capped at the new maximum, if neccessary.
|
||||
]]
|
||||
function mana.setmax(playername, value)
|
||||
mana.playerlist[playername].maxmana = value
|
||||
mana.hud_update(playername)
|
||||
if value < 0 then
|
||||
value = 0
|
||||
minetest.log("info", "[mana] Warning: mana.setmax was called with negative value!")
|
||||
end
|
||||
if mana.playerlist[playername].maxmana ~= value then
|
||||
mana.playerlist[playername].maxmana = value
|
||||
if(mana.playerlist[playername].mana > value) then
|
||||
mana.playerlist[playername].mana = value
|
||||
end
|
||||
mana.hud_update(playername)
|
||||
end
|
||||
end
|
||||
|
||||
-- Returns the current mana of the specified player
|
||||
|
Loading…
Reference in New Issue
Block a user