1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

Solved Hitting hidden players and make them visible.

Discussion in 'Plugin Help' started by WEATHERCRAFTYT1, Apr 12, 2021.

  1. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    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:
     <?php

    namespace WC;

    use 
    pocketmine\event\entity\EntityDamageEvent;
    use 
    pocketmine\event\entity\EntityDamageByEntityEvent;
    use 
    pocketmine\block\utils\SignText;
    use 
    pocketmine\entity\{EntityEffectEffectInstance};
    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;
                    
            }     
        }
    }
     
  2. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    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!)
     
    minijaham, WEATHERCRAFTYT1 and Primus like this.
  3. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    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
     
  4. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    PHP:
    $eff = new EffectInstance(Effect::getEffect(Effect::INVISIBILITY));
    $player->addEffect($eff);

     
  5. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    I mean like drink potion event otherwise
    public function onDrink()
     
  6. HeyDeniis_

    HeyDeniis_ Baby Zombie

    Messages:
    137
    I don't understand...
    PlayerEffectAddEvent and PlayerEffectRemoveEvent ?
     
  7. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    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
     
  8. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PlayerDrinkPotionEvent doesn't exist. Use PlayerItemConsumeEvent and have a check for the id
     
    Primus and WEATHERCRAFTYT1 like this.
  9. WEATHERCRAFTYT1

    WEATHERCRAFTYT1 Baby Zombie

    Messages:
    121
    Thank you! I think this will be marked solved
     
    minijaham likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.