How would I add commands to enable and disable this..? <?php namespace DodgeBall use pocketmine\plugin\PluginBase; use pocketmine\event\Listener; use pocketmine\event\entity\ProjectileHitEvent; use pocketmine\Player; use pocketmine\Server; class Main extends PluginBase implements Listener{ public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this,$this); $this->getLogger()->info(TextFormat::GREEN . "Dodgeball Plugin has been enabled!"); } public function onHurt(ProjectileHitEvent $event) { echo "Someone has been eliminated!" $event->getEntity()->setHealth(0, "none") } }
Make a public variable with a value of "enabled" for example. Make a command to toggle it from "enabled" to "disabled" and vise versa. In the event check whether the variable is "enabled" or "disabled". If it is disabled, cancel the event.
Yes, once installed within the server on projectile hit "bow" or "snowball" your health will be set to 0 and the code will broadcast "Someone has been eliminated" :3 pocketmine\event\entity\ProjectileHitEvent; use pocketmine\Player; use pocketmine\Server; public function onHurt(ProjectileHitEvent $event) { echo "Someone has been eliminated!" $event->getEntity()->setHealth(0, "none") } } I wouldn't paste something I don't understand
What are you trying to enable or disable? Also, ProjectileHitEvent->getEntity() will return the projectile, not the player, you should use EntityDamageEvent instead