Hello PMMP Forum i used in my plugin PlayerMoveEvent and i added AnvilBreakSound when you move but AnvilBreakSound repeats every second i want it to run for once and stop or run for once every like 5 minutes. How i can do it? This is the code if you want: PHP: public function onMove(PlayerMoveEvent $event){ $player = $event->getPlayer(); $x1 = $this->getConfig()->get("x1"); $y1 = $this->getConfig()->get("y1"); $z1 = $this->getConfig()->get("z1"); $x2 = $this->getConfig()->get("x2"); $y2 = $this->getConfig()->get("y2"); $z2 = $this->getConfig()->get("z2"); $level = $this->getConfig()->get("level"); if($this->isInside($player,new Vector3($x1,$y1,$z1,$level),new Vector3($x2,$y2,$z2,$level))){ $item = Item::get(302, 0, 1); $item->setCustomName("§9Space §fHelmet"); $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(1)); $hed = $player->getInventory()->getHelmet(); if ($hed->getCustomName() == $item->getCustomName()) { if ($hed->getEnchantment(0)) { if ($hed->getId() == 302) { $player->removeAllEffects(); $player->addEffect(Effect::getEffect(10)->setDuration(5)->setAmplifier(0)->setVisible(true)); $player->addEffect(Effect::getEffect(2)->setDuration(999999999)->setAmplifier(0)->setVisible(true)); $player->addEffect(Effect::getEffect(8)->setDuration(999999999)->setAmplifier(1)->setVisible(true)); } } } else { // Here is the sound $player->addSound(new AnvilBreakSound($player)); $player->sendMessage(TextFormat::RED . "Warning!! You are suffocating, Please wear the §9Space §fHelmet §4to breathe"); $player->removeAllEffects(); $player->addEffect(Effect::getEffect(19)->setDuration(999999999)->setAmplifier(0)->setVisible(true)); $player->addEffect(Effect::getEffect(9)->setDuration(999999999)->setAmplifier(0)->setVisible(true)); } } else { $player->removeAllEffects(); $item = Item::get(302, 0, 1); $item->setCustomName("§9Space §fHelmet"); $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(1)); $player->getInventory()->remove($item); } }
at first: Please use Effect constants https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Effect.php#L36-L59. Thanks! for your problem, i think you basically want to play the sound (and maybe the warning message) on enter. Actually, you may even want to run the whole code only once on enter. You may consider to use a task in general, because onMove is called quite often and depending on how your isInside implementation is it might be time expensive. But that's not important for your question. Finally back to your question,just have an array with the eids of the players that are already in the area. With that you can determine if he is new there and you haven't played the sound for him yet or not. PHP: private $insidePlayers;public function onMove(PlayerMoveEvent $event){ $player = $event->getPlayer(); $x1 = $this->getConfig()->get("x1"); $y1 = $this->getConfig()->get("y1"); $z1 = $this->getConfig()->get("z1"); $x2 = $this->getConfig()->get("x2"); $y2 = $this->getConfig()->get("y2"); $z2 = $this->getConfig()->get("z2"); $level = $this->getConfig()->get("level"); if($this->isInside($player, new Vector3($x1,$y1,$z1,$level), new Vector3($x2,$y2,$z2,$level))){ $item = Item::get(302, 0, 1); $item->setCustomName("§9Space §fHelmet"); $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(1)); $hed = $player->getInventory()->getHelmet(); if($hed->getCustomName() == $item->getCustomName()){ if($hed->getEnchantment(0)){ if($hed->getId() == 302){ $player->removeAllEffects(); $player->addEffect(Effect::getEffect(10)->setDuration(5)->setAmplifier(0)->setVisible(true)); $player->addEffect(Effect::getEffect(2)->setDuration(999999999)->setAmplifier(0)->setVisible(true)); $player->addEffect(Effect::getEffect(8)->setDuration(999999999)->setAmplifier(1)->setVisible(true)); } } }else{ if(!in_array(($playerId = $player->getId()), $this->insidePlayers)){ $this->insidePlayers[] = $playerId; //player just entered the area $player->addSound(new AnvilBreakSound($player)); $player->sendMessage(TextFormat::RED . "Warning!! You are suffocating, Please wear the §9Space §fHelmet §4to breathe"); } $player->removeAllEffects(); $player->addEffect(Effect::getEffect(19)->setDuration(999999999)->setAmplifier(0)->setVisible(true)); $player->addEffect(Effect::getEffect(9)->setDuration(999999999)->setAmplifier(0)->setVisible(true)); } }else{ $player->removeAllEffects(); $item = Item::get(302, 0, 1); $item->setCustomName("§9Space §fHelmet"); $item->addEnchantment(Enchantment::getEnchantment(0)->setLevel(1)); $player->getInventory()->remove($item); }}