hello, I’m trying to do two things I want whenever a player uses a dye to make them invisible they don’t see there armor or anything unless someone hits them and there visible. However I’m having two problems. > The player cannot hit a hidden player using $players->hidePlayer($player) > When player uses the item it doesn’t count down and used $this->seconds to count 60 to 0 for invisible last. Any idea how to fix it? My code PHP: <?phpnamespace WC;use pocketmine\event\entity\EntityDamageEvent;use pocketmine\event\entity\EntityDamageByEntityEvent;use pocketmine\block\utils\SignText;use pocketmine\entity\{Entity, Effect, EffectInstance};use pocketmine\event\player\PlayerJoinEvent;use pocketmine\item\Item;use pocketmine\event\player\PlayerInteractEvent;use pocketmine\level\Level;use libs\muqsit\invmenu\InvMenu;use libs\muqsit\invmenu\InvMenuHandler;use pocketmine\Player;use pocketmine\scheduler\Task;use pocketmine\Server;use pocketmine\tile\Sign;use pocketmine\utils\TextFormat;use pocketmine\math\Vector3;use pocketmine\plugin\Plugin;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;class Main extends PluginBase implements Listener { public function onEnable(){ $this->getLogger()->info("Manrun created by @WC TEAM and more!"); $this->getServer()->getPluginManager()->registerEvents($this ,$this); $this->seconds = 60; } public function onPlayerInteractOn(PlayerInteractEvent $event) { $item = $event->getPlayer()->getInventory()->getItemInHand()->getName(); $player = $event->getPlayer(); $level = $player->getLevel(); if($item == "Invisible Dye") { $player->getInventory()->removeItem(Item::get(Item::DYE,0,8)); foreach($level->getPlayers() as $players){ $this->seconds--; $players->hidePlayer($player); } } } public function onDam(EntityDamageEvent $event) { if($event instanceof EntityDamageByEntityEvent){ $player = $event->getEntity(); $level = $player->getLevel(); $damager = $event->getDamager(); if ($damager instanceof Player) { if ($player instanceof Player) { foreach($level->getPlayers() as $players){ $players->showPlayer($player); } } } } } public function tick() : void{ switch($this->seconds) { case 60; $player->sendMessage("Your invisi runs out in 60 seconds"); break; case 30; $player->sendMessage("Your invisi runs out in 30 seconds"); break; case 10; $player->sendMessage("Your invisi runs out in 10 seconds"); break; case 0; $player->showPlayer($players); $this->seconds = 15; break; } }}
It is not possible to hit a player that is in the hidePlayer because the player that is in it is removed from the game of the other (his entity), what you can do is apply an invisibility and remove the armor, then when you receive a hit you can make it visible again, and the question of armor can modify the damage to what the damage would be if you had armor (if I am wrong excuse me!)
Sure makes sense about the hidePlayer. What is the event for drinking an potion in pmmp and about the armor maybe he will receive his armor whenever the players hits him which that I can do. Ov
Lemme make it a bit clearer. When a player drinks a invisible potion (not splash potions but the other ones) it gives out the effect to the player with invisibility and takes out armor. I don’t know however if the event to drink an potion is PlayerDrinkPotionEvent or PlayerItemConsumeEvent