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

onInteract won't work

Discussion in 'Development' started by ExplodingSquad, Nov 19, 2017.

  1. ExplodingSquad

    ExplodingSquad Spider

    Messages:
    13
    GitHub:
    CreeperAsGaming
    Error
    RING), expecting function (T_FUNCTION) or const (T_CONST)" (EXCEPTION) in "commandexecuter
    src/Command/Main" at line 27

    Code
    <?php
    namespace Command;

    use pocketmine\Player;
    use pocketmine\Server;
    use pocketmine\item\Item;
    use pocketmine\event\PlayerJoinEvent;
    use pocketmine\event\Listener;
    use pocketmine\event\player\PlayerInteractEvent;
    use pocketmine\plugin\PluginBase;

    class Main extends PluginBase implements Listener {

    public function onEnable() {
    $this->getServer()->getPluginManager()->registerEvents($this, $this);
    $this->getLogger()->sendMessage("Command executer is now Enabled");
    }
    public function onDisable() {
    $this->getLogger()->sendMessage("Command executer is now disabled");
    }
    public function onJoin(PlayerJoinEvent $event){
    $custom == Item::get(340, 0, 1);
    $customName =$custom->setCustomName("§l§4SHOP");
    $player->getInventory()->getItem($custom);
    }

    public function onInteract(PlayerInteractEvent $event) {

    $player = $event->getPlayer();
    $item = $event->getItem();

    if($item->getId() == 340) {
    $event->setCancelled();
    $command = "shop";
    $this->getServer()->dispatchCommand($player, $command);
    }

    ?>
     
  2. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    $custom == Item::get(340,0,1); to $custom = Item::get(340,0,1); your forgot a = if you use an condition you can use this operator == etc.. when you defined a variable use "=" please.

    Please Read the Line it's easy....
     
    jasonwynn10 and OnTheVerge like this.
  3. ExplodingSquad

    ExplodingSquad Spider

    Messages:
    13
    GitHub:
    CreeperAsGaming
  4. ExplodingSquad

    ExplodingSquad Spider

    Messages:
    13
    GitHub:
    CreeperAsGaming
    Not even working
     
  5. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    It's not getItem(), it's addItem()
     
  6. ExplodingSquad

    ExplodingSquad Spider

    Messages:
    13
    GitHub:
    CreeperAsGaming
    I need to get the item Id
     
  7. ItzAribie

    ItzAribie Spider Jockey

    Messages:
    41
    No that ....
    PHP:
    $player->getInventory()->getItem($custom);

    //To

    $player->getInventory()->addItem($custom);
     
  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.