summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--API.md4
-rw-r--r--init.lua18
2 files changed, 19 insertions, 3 deletions
diff --git a/API.md b/API.md
index ca668e8..b0a12b0 100644
--- a/API.md
+++ b/API.md
@@ -104,7 +104,9 @@ After a HUD bar has been added, you can change the current and maximum value on
You use the function `hud.change_hudbar` for this.
### `hud.change_hudbar(player, identifier, new_value, new_max_value)`
-Changes the values of. If
+Changes the values of an initialized HUD bar for a certain player. `new_value` and `new_max_value`
+can be `nil`; if one of them is `nil`, that means the value is unchanged. If both values
+are `nil`, this function is a no-op.
#### Parameters
* `player`: `ObjectRef` of the player to which the HUD bar belongs to
diff --git a/init.lua b/init.lua
index c6ac921..32ac1bf 100644
--- a/init.lua
+++ b/init.lua
@@ -156,10 +156,24 @@ function hud.init_hudbar(player, identifier, start_value, start_max)
end
function hud.change_hudbar(player, identifier, new_value, new_max_value)
+ if new_value == nil and new_max_value == nil then
+ return
+ end
+
local name = player:get_player_name()
local hudtable = hud.get_hudtable(identifier)
- hudtable.hudstate[name].value = new_value
- hudtable.hudstate[name].max = new_max_value
+
+ if new_value ~= nil then
+ hudtable.hudstate[name].value = new_value
+ else
+ new_value = hudtable.hudstate[name].value
+ end
+ if new_max_value ~= nil then
+ hudtable.hudstate[name].max = new_max_value
+ else
+ new_max_value = hudtable.hudstate[name].max
+ end
+
if hudtable.hudstate[name].hidden == false then
if hudtable.hudstate[name].max == 0 then
player:hud_change(hudtable.hudids[name].bg, "scale", {x=0,y=0})