health regeneration cancelled when dead

This commit is contained in:
Shoghi Cervantes Pueyo 2013-01-26 12:12:59 +01:00
parent a0cb4d2698
commit 26da585889
2 changed files with 9 additions and 6 deletions

View File

@ -46,8 +46,11 @@ class PlayerAPI{
$result = $this->server->query("SELECT EID FROM players WHERE EID = (SELECT EID FROM entities WHERE health < 20);"); $result = $this->server->query("SELECT EID FROM players WHERE EID = (SELECT EID FROM entities WHERE health < 20);");
if($result !== true and $result !== false){ if($result !== true and $result !== false){
while(false !== ($player = $result->fetchArray())){ while(false !== ($player = $result->fetchArray())){
if(($player = $this->server->api->player->getByEID($player["EID"])) !== false){ if(($player = $this->server->api->entity->get($player["EID"])) !== false){
$player->entity->setHealth(min(20, $player->entity->getHealth() + $data), "regeneration"); if($player->dead === true){
continue;
}
$player->setHealth(min(20, $player->entity->getHealth() + $data), "regeneration");
} }
} }
} }

View File

@ -300,10 +300,10 @@ class Entity extends stdClass{
} }
public function setHealth($health, $cause = ""){ public function setHealth($health, $cause = ""){
$health = min(127, max(-128, (int) $health)); $health = (int) $health;
if($health < $this->health){ if($health < $this->health){
$dmg = $this->health - $health; $dmg = $this->health - $health;
if($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg and !$this->dead){ if(($this->dmgcounter[0] < microtime(true) or $this->dmgcounter[1] < $dmg) and !$this->dead){
$this->dmgcounter = array(microtime(true) + 0.5, $dmg); $this->dmgcounter = array(microtime(true) + 0.5, $dmg);
}else{ }else{
return false; //Entity inmunity return false; //Entity inmunity
@ -312,9 +312,9 @@ class Entity extends stdClass{
return false; return false;
} }
if($this->server->api->dhandle("entity.health.change", array("entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause)) !== false){ if($this->server->api->dhandle("entity.health.change", array("entity" => $this, "eid" => $this->eid, "health" => $health, "cause" => $cause)) !== false){
$this->health = $health; $this->health = min(127, max(-127, $health));
$this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";"); $this->server->query("UPDATE entities SET health = ".$this->health." WHERE EID = ".$this->eid.";");
if($this->player !== false){ if($this->player instanceof Player){
$this->player->dataPacket(MC_SET_HEALTH, array( $this->player->dataPacket(MC_SET_HEALTH, array(
"health" => $this->health, "health" => $this->health,
)); ));