Hi, I'm developing a minigame where I want to give a player money if he kills another player by TNT. My question: How to get the player who fired the TNT at EntityDamageEvent?
There is an stupid and way (that will not work all time) Get the PlaceBlock event, check if the block is tnt save the player to an variable, use that variable on EntityDamageEvent... But that would only work if there are two players on that server. More advanced: You would have to some Vector3 fuc# i mean fun (If ANYONE does understand that stupid Vector3 and how to make areas with that tell me pls)
I think you meant PlayerInteractEvent instead of BlockPlaceEvent. And Vector3 merely means three numbers that represent a 3-D vector. It is not stupid, and if you understand OOP, https://github.com/PocketMine/PocketMine-MP/blob/master/src/pocketmine/math/Vector3.php And yes, Vector3 is very simple. It is slightly more complicated if you want to understand its implementation, but how to use it is extremely simple, no offense.
I tried a way I imagine to work well, if anyone has ideas or codes to improve it, just work on the code an please post it PHP: public function onTap(PlayerInteractEvent $event){$player = $event->getPlayer();if($event->getBlock()->getId() == Block::TNT && $player->getHeldItem()->getId() == Item::FLINT_AND_STEEL){now here needs to be a code to get the entity in which the tnt turned in (PrimedTNT), $tnt is the entity$this->tntshooter([$tnt->getId()] = $player->getName();}}public function getTNTShooter($tnt){if(in_array($tnt->getId(), $this->tntshooter)){$playername = $this->tntshooter[$tnt->getId()];$player = $this->getServer()->getPlayer($playername);return $player;// now we got the player who ignited the tnt}}// You can add $this->getTNTShooter($tnt); in EntityDamageEvent, the tnt entity is $event->getDamager();
*tnt id* = Block::TNT; *flint and steel id* = Item::FLINT_AND_STEEL; Because if the id's may change in future, it will still work.