diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/constants.h | 2 | ||||
-rw-r--r-- | src/content_sao.cpp | 8 | ||||
-rw-r--r-- | src/remoteplayer.cpp | 2 | ||||
-rw-r--r-- | src/script/common/c_content.cpp | 4 | ||||
-rw-r--r-- | src/script/lua_api/l_object.cpp | 5 | ||||
-rw-r--r-- | src/server.cpp | 2 |
6 files changed, 15 insertions, 8 deletions
diff --git a/src/constants.h b/src/constants.h index 4da66cc53..ddf7218e2 100644 --- a/src/constants.h +++ b/src/constants.h @@ -90,7 +90,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #define PLAYER_INVENTORY_SIZE (8 * 4) // Maximum hit points of a player -#define PLAYER_MAX_HP 20 +#define PLAYER_MAX_HP_DEFAULT 20 // Maximal breath of a player #define PLAYER_MAX_BREATH 11 diff --git a/src/content_sao.cpp b/src/content_sao.cpp index 621a64de0..bc5fb164b 100644 --- a/src/content_sao.cpp +++ b/src/content_sao.cpp @@ -782,7 +782,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id { assert(m_peer_id != 0); // pre-condition - m_prop.hp_max = PLAYER_MAX_HP; + m_prop.hp_max = PLAYER_MAX_HP_DEFAULT; m_prop.physical = false; m_prop.weight = 75; m_prop.collisionbox = aabb3f(-0.3f, 0.0f, -0.3f, 0.3f, 1.77f, 0.3f); @@ -799,7 +799,7 @@ PlayerSAO::PlayerSAO(ServerEnvironment *env_, RemotePlayer *player_, u16 peer_id m_prop.is_visible = true; m_prop.makes_footstep_sound = true; m_prop.stepheight = PLAYER_DEFAULT_STEPHEIGHT * BS; - m_hp = PLAYER_MAX_HP; + m_hp = m_prop.hp_max; } PlayerSAO::~PlayerSAO() @@ -1235,8 +1235,8 @@ void PlayerSAO::setHP(s16 hp) if (hp < 0) hp = 0; - else if (hp > PLAYER_MAX_HP) - hp = PLAYER_MAX_HP; + else if (hp > m_prop.hp_max) + hp = m_prop.hp_max; if (hp < oldhp && !g_settings->getBool("enable_damage")) { return; diff --git a/src/remoteplayer.cpp b/src/remoteplayer.cpp index 20c18ee15..c108ad3f1 100644 --- a/src/remoteplayer.cpp +++ b/src/remoteplayer.cpp @@ -100,7 +100,7 @@ void RemotePlayer::deSerialize(std::istream &is, const std::string &playername, try { sao->setHPRaw(args.getS32("hp")); } catch(SettingNotFoundException &e) { - sao->setHPRaw(PLAYER_MAX_HP); + sao->setHPRaw(PLAYER_MAX_HP_DEFAULT); } try { 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; } diff --git a/src/server.cpp b/src/server.cpp index f48066fad..7d9cfbf59 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -2588,7 +2588,7 @@ void Server::RespawnPlayer(u16 peer_id) << playersao->getPlayer()->getName() << " respawns" << std::endl; - playersao->setHP(PLAYER_MAX_HP); + playersao->setHP(playersao->accessObjectProperties()->hp_max); playersao->setBreath(PLAYER_MAX_BREATH); bool repositioned = m_script->on_respawnplayer(playersao); |