Last active
January 3, 2016 02:39
-
-
Save Omattyao/8396978 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function init() { | |
$this->api->addHandler("entity.health.change", array($this, "handle")); //entity.health.changeをキャッチしたらhandle()メソッドを実行する | |
} | |
public function handle(&$data, $event) { | |
if ($data["entity"]->class === ENTITY_PLAYER) { //ダメージを受けた奴がプレイヤーの場合 | |
if ($this->api->player->getByEID($data["cause"]) !== false) { //ダメージを与えた奴がプレイヤーの場合 | |
$puncher = $this->api->player->getByEID($data["casuse"]); //ダメージを与えた奴のPlayerオブジェクトを取得 | |
if ($puncher->getSlot($puncher->slot)->getID() === AIR) { //ダメージを与えた奴の手に持ってるものが空気だった場合 | |
$damage = 1; //与えたいダメージ | |
$this->api->entity->harm($data["eid"], $damage, $puncher->entity); //ダメージを与える | |
return flase; //元々送られてきていたイベントを無かったことにする | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment