Skip to content

Instantly share code, notes, and snippets.

@Omattyao
Last active January 3, 2016 02:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Omattyao/8396978 to your computer and use it in GitHub Desktop.
Save Omattyao/8396978 to your computer and use it in GitHub Desktop.
<?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