Updated player deaths

This commit is contained in:
Shoghi Cervantes Pueyo
2012-12-18 21:51:28 +01:00
parent d9c39ca816
commit 4a46fde483
7 changed files with 57 additions and 45 deletions

View File

@ -29,6 +29,7 @@ class PlayerAPI{
private $server;
function __construct($server){
$this->server = $server;
$this->server->event("onHealthRegeneration", array($this, "handle"));
}
public function init(){
@ -38,6 +39,19 @@ class PlayerAPI{
$this->server->api->console->register("tp", "Teleports a player to another player", array($this, "commandHandler"));
}
public function handle($data, $event){
switch($event){
case "onHealthRegeneration":
$result = $this->server->query("SELECT ip,port FROM players WHERE EID = (SELECT EID FROM entities WHERE health < 20);", true);
if($result !== true and $result !== false){
while($player = $result->fetchArray()){
$player->entity->setHealth(min(20, $player->entity->getHealth() + $data), "regeneration");
}
}
break;
}
}
public function commandHandler($cmd, $params){
switch($cmd){
case "tp":
@ -71,7 +85,7 @@ class PlayerAPI{
case "kill":
$player = $this->get(implode(" ", $params));
if($player !== false){
$this->server->trigger("onHealthChange", array("eid" => $player->eid, "health" => -1, "cause" => "console"));
$this->server->api->entity->harm($player->eid, 20, "console");
}else{
console("[INFO] Usage: /kill <player>");
}