How would I make it so that when a player collides with a certain block they take damage and die? I've got some code I just need some help with How its possible. I could PM anyone the code
PHP: foreach($player->getBlocksAround() as $block){ if($block->getId() === Block::CACTUS) $player->attack(1, new EntityDamageEvent(...));}
You can do it on timer or on PlayerMoveEvent: PHP: public function onMove(PlayerMoveEvent $event){// @PEMapModder code}
This is my code, Something isn't right namespace SM11\WaterDamage; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDamageByBlockEvent; use pocketmine\Player; use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; class Main extends PluginBase implements Listener{ public function onEnable(){ $this->getServer()->getPluginManager()->registerEvents($this, $this); $this->getLogger()->info("WaterDamage enabled!"); } public function onDisable(){ $this->getLogger()->info("WaterDamage disabled!"); } public function onMove(PlayerMoveEvent $event){ foreach($player->getBlocksAround() as $block){ if($block->getId() === Block::CACTUS) $player->attack(1, new EntityDamageEvent(...)); } } }
I have I just don't understand this, I tried using the Cactus Collision but when I tested it didn't do anything
You know what, Instead of helping your just trying to repeat yourself you ignorant man, I have learned PHP and If something is wrong why not just help me,
I tried it and this came up when I swim in water [CRITICAL] "Could not pass event 'pocketmine\event\player\PlayerMoveEvent' to 'WaterDamage v1.0.0': Undefined variable: player on SM11\WaterDamage\Main 11:08:42[NOTICE] UndefinedVariableException: "Undefined variable: player" (E_NOTICE) in "/WaterDamage/src/SM11/WaterDamage/Main" at line 26
Ok look: attack ($damage, $source=EntityDamageEvent::CAUSE_MAGIC); if you put nothing in second paramater then it will work. But if you do you must do it properly PHP: public function onMove(PlayerMoveEvent $event){$player = $event->getPlayer();foreach($player->getBlocksAround() as $block){if($block->getId() === Block::CACTUS) $player->attack(1, new EntityDamageEvent($player/*ATTACKER*/, 0 /*CAUSE_CONTACT*/, 1/*DAMAGE*/));}}}
It is the victim not the attacker.. And please use the constants instead of their values like 0 and 1. The values can be changed anytime.
It not only makes sense, that's contradictory if you don't. EntityDamageEvent only means an entity gets hurt. If you someone gets hurt, you are only interested in who it is, what type of damage it is and how seriously it hurts. You wouldn't presume there is an attacker. Maybe that person simply tripped himself. EntityDamageByEntityEvent is an extension of EntityDamageEvent. It states that there is some attacker, and therefore you will also know who the attacker is.