1
0
mirror of git://repo.or.cz/minetest_mana.git synced 2024-11-15 23:00:20 +01:00

Add API for Mana regneration

This commit is contained in:
Wuzzy 2015-02-14 02:26:34 +01:00
parent 97f1079852
commit 47c4d35baa
2 changed files with 25 additions and 0 deletions

13
API.md
View File

@ -43,6 +43,12 @@ If the new maximum would become smaller than the current value,
the current value will automatically be set to
the new maximum.
### `mana.setregen(playername, value)`
Sets the mana regeneration per mana tick of the player to `value`.
Negative values are not permitted.
The length of one “mana tick” is specified as the server-wide setting
`mana_default_regen` in seconds.
### `mana.get(playername)`
Returns the current mana of the specified player as number.
@ -52,6 +58,13 @@ Returns the current mana of the specified player as number.
Returns the current maximum mana of the specified player as number.
### `mana.getregen(playername)`
Returns the current mana regneration per mana tick of the specified
player as number.
The length of one “mana tick” is specified as the server-wide setting
`mana_default_regen` in seconds.
### `mana.add(playername, value)`
Adds the specified non-negative amount of mana to the player, but only
if the sum would not be greater than the maximum,

View File

@ -67,6 +67,14 @@ function mana.setmax(playername, value)
end
end
function mana.setregen(playername, value)
if value < 0 then
value = 0
minetest.log("info", "[mana] Warning: mana.setregen was called with negative value!")
end
mana.playerlist[playername].regen = value
end
function mana.get(playername)
return mana.playerlist[playername].mana
end
@ -75,6 +83,10 @@ function mana.getmax(playername)
return mana.playerlist[playername].maxmana
end
function mana.getregen(playername)
return mana.playerlist[playername].regen
end
function mana.add_up_to(playername, value)
local t = mana.playerlist[playername]
if(t ~= nil and value >= 0) then