ok so i am trying to give $killer a arrow when when they kill a player using a bow but the thing is i set the CAUSE_PROJECTILE to make it be one hit kill how can i do this while still using the one hit kill method?
I also try to make one hit kill bows for OneInTheChamber, if you have any code please post it, then i can have a look at this
PHP: public function onHitByArrow(EntityDamageEvent $event){ if($this->gameStatus===0){ if($event->getCause() === 2){ $event->getEntity()->setHealth(20); } }else{ if($this->gameStatus===3){ if($event->getCause() === 2){ $event->getEntity()->setHealth(0); } } } if($this->gameStatus===1){ if($event->getCause() === 2){ $event->getEntity()->setHealth(20); } } } i need a new method because it i need to give a arrow to the person who shot the bow :/
This looks good, but i think setHealth wouldn't kill a player.. Give me a minute, i'll have a look over it and check it. (by the way.. what do you want to create? xD it really sounds like OITC ^^)
Take a look at my code for this ;P PHP: public function onDamage(EntityDamageEvent $event){ if($event instanceof EntityDamageByChildEntityEvent) { if($event->getChild() instanceof Arrow) { $victim = $event->getEntity(); if($event->getEntity()->getLastDamageCause() instanceof EntityDamageByEntityEvent and $victim->isSurvival() or $victim->isAdventure()) { $killer = $event->getEntity()->getLastDamageCause()->getDamager(); if($killer instanceof Player and $victim instanceof Player) { $this->kill($this->victim); $this->giveItems($this->killer); $this->resetHealth($this->killer); } } } } }public function giveItems(Player $player) { $inv = $player->getInventory(); if($inv instanceof PlayerInventory) { $inv->clearAll(); $inv->addItem(Item::get(272), Item::get(261), Item::get(262), Item::get(378)); } }public function resetHealth(Player $player) { $player->setMaxHealth(20); $player->setHealth($player->getMaxHealth()); }public function kill(Player $player) { $player->setHealth(0); } I put all this in a 2 tick delayed task to give the damager time to update, I'm pretty sure it doesn't need to be in the task but if you get any crashes then you might have to.