<< std::endl;
playersao->setHP(playersao->getHP() - damage);
- SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
+ SendPlayerHPOrDie(playersao);
}
}
// If the object is a player and its HP changed
if (src_original_hp != pointed_object->getHP() &&
pointed_object->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- SendPlayerHPOrDie(((PlayerSAO*)pointed_object)->getPeerID(),
- pointed_object->getHP() == 0);
+ SendPlayerHPOrDie((PlayerSAO *)pointed_object);
}
// If the puncher is a player and its HP changed
- if (dst_origin_hp != playersao->getHP()) {
- SendPlayerHPOrDie(playersao->getPeerID(), playersao->getHP() == 0);
- }
+ if (dst_origin_hp != playersao->getHP())
+ SendPlayerHPOrDie(playersao);
}
} // action == 0
// If the punched is a player, and its HP changed
if (src_original_hp != co->getHP() &&
co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(),
- co->getHP() == 0);
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co);
}
// If the puncher is a player, and its HP changed
if (dst_origin_hp != puncher->getHP() &&
puncher->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)puncher)->getPeerID(),
- puncher->getHP() == 0);
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)puncher);
}
return 0;
}
<<" hp="<<hp<<std::endl;*/
// Do it
co->setHP(hp);
- if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) {
- getServer(L)->SendPlayerHPOrDie(((PlayerSAO*)co)->getPeerID(), co->getHP() == 0);
- }
+ if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER)
+ getServer(L)->SendPlayerHPOrDie((PlayerSAO *)co);
+
// Return
return 0;
}
SendInventory(playersao);
// Send HP
- SendPlayerHPOrDie(peer_id, playersao->getHP() == 0);
+ SendPlayerHPOrDie(playersao);
// Send Breath
SendPlayerBreath(peer_id);
Send(&pkt);
}
+void Server::SendPlayerHPOrDie(PlayerSAO *playersao)
+{
+ if (!g_settings->getBool("enable_damage"))
+ return;
+
+ u16 peer_id = playersao->getPeerID();
+ bool is_alive = playersao->getHP() > 0;
+
+ if (is_alive)
+ SendPlayerHP(peer_id);
+ else
+ DiePlayer(peer_id);
+}
+
void Server::SendHP(u16 peer_id, u8 hp)
{
DSTACK(__FUNCTION_NAME);
u8* ser_vers, u16* prot_vers, u8* major, u8* minor, u8* patch,
std::string* vers_string);
- void SendPlayerHPOrDie(u16 peer_id, bool die) { die ? DiePlayer(peer_id) : SendPlayerHP(peer_id); }
+ void SendPlayerHPOrDie(PlayerSAO *player);
void SendPlayerBreath(u16 peer_id);
void SendInventory(PlayerSAO* playerSAO);
void SendMovePlayer(u16 peer_id);