mirror of
git://repo.or.cz/minetest_mana.git
synced 2024-11-04 17:20:33 +01:00
Keep mana in bounds when using set and setmax
This commit is contained in:
parent
9563fcffbc
commit
0e3af4e900
26
init.lua
26
init.lua
|
@ -18,17 +18,39 @@ mana.playerlist = {}
|
||||||
API functions
|
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)
|
function mana.set(playername, value)
|
||||||
|
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.playerlist[playername].mana = value
|
||||||
mana.hud_update(playername)
|
mana.hud_update(playername)
|
||||||
end
|
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)
|
function mana.setmax(playername, value)
|
||||||
|
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
|
mana.playerlist[playername].maxmana = value
|
||||||
|
if(mana.playerlist[playername].mana > value) then
|
||||||
|
mana.playerlist[playername].mana = value
|
||||||
|
end
|
||||||
mana.hud_update(playername)
|
mana.hud_update(playername)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Returns the current mana of the specified player
|
-- Returns the current mana of the specified player
|
||||||
function mana.get(playername)
|
function mana.get(playername)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user