aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorSmallJoker <SmallJoker@users.noreply.github.com>2017-08-23 22:32:10 +0200
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-08-23 22:32:10 +0200
commitf7d50a80782376d2e1c068e4d0a7ce9632f28bda (patch)
tree1235977bb6ce8639c24a5315f094364a39e34ee0 /src/script
parentd01b65abebf3b2e86d076c6b69996fd3a205a960 (diff)
downloadminetest-f7d50a80782376d2e1c068e4d0a7ce9632f28bda.tar.gz
minetest-f7d50a80782376d2e1c068e4d0a7ce9632f28bda.tar.bz2
minetest-f7d50a80782376d2e1c068e4d0a7ce9632f28bda.zip
Respect object property hp_max field for players (#6287)
* Respect object property hp_max field for players This allows modders to configure the maximal HP per player * Statbars: Downscale bar to full 20 HP when exceeding this value Add default max HP for players and breath constants to builtin Document the constants * Rename PLAYER_MAX_HP -> PLAYER_MAX_HP_DEFAULT
Diffstat (limited to 'src/script')
-rw-r--r--src/script/common/c_content.cpp4
-rw-r--r--src/script/lua_api/l_object.cpp5
2 files changed, 8 insertions, 1 deletions
diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp
index ddcdd803d..47443493b 100644
--- a/src/script/common/c_content.cpp
+++ b/src/script/common/c_content.cpp
@@ -183,7 +183,9 @@ void read_object_properties(lua_State *L, int index,
if(!lua_istable(L, index))
return;
- prop->hp_max = getintfield_default(L, -1, "hp_max", 10);
+ int hp_max = 0;
+ if (getintfield(L, -1, "hp_max", hp_max))
+ prop->hp_max = (s16)rangelim(hp_max, 0, S16_MAX);
getboolfield(L, -1, "physical", prop->physical);
getboolfield(L, -1, "collide_with_objects", prop->collideWithObjects);
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 46ac61f27..24fdeca4b 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -751,6 +751,11 @@ int ObjectRef::l_set_properties(lua_State *L)
if (!prop)
return 0;
read_object_properties(L, 2, prop, getServer(L)->idef());
+ if (prop->hp_max < co->getHP()) {
+ co->setHP(prop->hp_max);
+ if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co);
+ }
co->notifyObjectPropertiesModified();
return 0;
}