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

PlayerInteractEvent unknowm issue

Discussion in 'Development' started by Vaxrp, Oct 30, 2017.

  1. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    So I made this plugin straight from scratch it enables no errors but the actual interactions dont work. When I click netherstar it doesnt give me the other wools when I click a wool it does do the dispatchCommand. Please help thanks.

    PHP:
    <?php

    namespace havtic;

    use 
    pocketmine\Player;
    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\PlayerInteractEvent;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat as c;
    use 
    pocketmine\plugin\PluginBase;
    use 
    pocketmine\event\EntityDamageEvent;
    use 
    pocketmine\event\EntityDamageByEntityEvent;

    class 
    Main extends PluginBase implements Listener{

       public function 
    onEnable() {
          
    $this->getServer()->getPluginManager()->registerEvents($this,$this);
       }
      
       public function 
    onInteract(PlayerInteractEvent $event) { 
        
    $player $event->getPlayer();
        
    $giver $event->getItem();
         if(
    $giver->getId() === Item::NETHER_STAR){//Item that gives the other wools
          
    $player->getInventory()->removeItem($giver);
          
    $player->sendMessage(c::RED."Select a rank to pick a kit");
          
    $player->getInventory()->addItem(Item::get(35,0,1));//Guest
          
    $player->getInventory()->addItem(Item::get(35,13,1));//VIP
          
    $player->getInventory()->addItem(Item::get(35,3,1));//MVP
          
    $player->getInventory()->addItem(Item::get(35,10,1));//Valor
         
    }
        
    $white $event->getItem();
         if(
    $white->getId() === Item::get(35,0,1)){
          
    $player->getInventory()->removeItem($white);
          
    $player->getInventory()->removeItem(Item::get(35,13,1));
          
    $player->getInventory()->removeItem(Item::get(35,3,1));
          
    $player->getInventory()->removeItem(Item::get(35,10,1));
          
    $this->getServer()->dispatchCommand($event->getPlayer(), "kit");
         }
        
    $green $event->getItem();
         if(
    $green->getId() === Item::get(35,13,1)){
          
    $player->getInventory()->removeItem($green);
          
    $player->getInventory()->removeItem(Item::get(35,0,1));
          
    $player->getInventory()->removeItem(Item::get(35,3,1));
          
    $player->getInventory()->removeItem(Item::get(35,10,1));
          
    $this->getServer()->dispatchCommand($event->getPlayer(), "kit");
         }
        
    $blue $event->getItem();
         if(
    $blue->getId() === Item::get(35,3,1)){
          
    $player->getInventory()->removeItem($blue);
          
    $player->getInventory()->removeItem(Item::get(35,13,1));
          
    $player->getInventory()->removeItem(Item::get(35,0,1));
          
    $player->getInventory()->removeItem(Item::get(35,10,1));
          
    $this->getServer()->dispatchCommand($event->getPlayer(), "kit");
         }
         
    $purple $event-> getItem();
         if(
    $purple->getId() === Item::get(35,10,1)){
          
    $player->getInventory()->removeItem($purple);
          
    $player->getInventory()->removeItem(Item::get(35,13,1));
          
    $player->getInventory()->removeItem(Item::get(35,3,1));
          
    $player->getInventory()->removeItem(Item::get(35,0,1));
          
    $this->getServer()->dispatchCommand($event->getPlayer(), "kit");
         }
       }
    }
     
    Last edited: Oct 30, 2017
  2. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    I'm on my phone but..

    PHP:
    onInteract
    $item 
    $player->getInventory()->getItemInHand()->getId();
    if(
    $item == netherstar id){
    $player->getInventory()->addItem(Item::get(wool id);
    }
    eseif($item == wool id){
    // do stuff
    }
     
    Vaxrp likes this.
  3. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Isnt that the same thing im doing basically? Or did I forget something in my code?
     
  4. kazuya

    kazuya Slime

    Messages:
    79
    GitHub:
    xdqrknez
    I don't think it is the same thing because you are getting the item from $event. Not sure though :rolleyes:
     
  5. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
  6. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    You are comparing an id to an Item object... multiple times?
     
    kazuya and Muqsit like this.
  7. Vaxrp

    Vaxrp Witch

    Messages:
    73
    GitHub:
    Vaxrp
    Do I just get the id then? I just thought I had to do that becauss of an old plugin I made I did that but didnt remember I thought it was just for getting the item to interact with. Can you please help me fix and understand it?
     
  8. Yexeed

    Yexeed Slime

    Messages:
    76
    maybe is a bad code, but you can do like that.
    PHP:
    $purple->getId() === Item::get(35,10,1)->getId()
     
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    But what about the item damage?
    PHP:
    $item->equals(Item::get(3510));
     
    jasonwynn10 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.