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

please help

Discussion in 'Development' started by Harviy11, Nov 19, 2016.

Thread Status:
Not open for further replies.
  1. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    why this dont work in 0.16?
    PHP:
    public function onItemUse(DataPacketReceiveEvent $event){
    $br C::RESET C::WHITE "\n";
    $pk $event->getPacket();
    $player $event->getPlayer();
    $level $event->getPlayer()->getLevel();
    if(
    $pk instanceof UseItemPacket and $pk->face === 0xff) {
    $item $player->getInventory()->getItemInHand();
    if(
    $item->getName() == C::GREEN ."Help"){
    $this->Help($player);
    }
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Last edited: Nov 19, 2016
  3. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    please code
     
    Primus likes this.
  4. Primus

    Primus Zombie Pigman

    Messages:
    749
    Don't dare to call your self a programmer, or anything on that line!
    PHP:
    use pocketmine\event\player\PlayerInteractEvent;

    /**
     * Super simple code.
     *
     * @param PlayerInteractEvent $event
     * @priority NORMAL
     * @ignoreCancelled false
     */
    public function onPlayerInteract(PlayerInteractEvent $event) {
       if(
    $event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR) {
          
    // ... code
       
    }
    }
     
  5. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Please at least explain to him what what does, to help him make his way onto getting a programmer. Don't just bake code for him, and if he wants to change the ingredient salt to sugar, he is unable to do it because he has no recipe.
    PHP:
    if($event->getAction() === PlayerInteractEvent::RIGHT_CLICK_AIR) {
    checks if the action of the InteractEvent is equal to RIGHT_CLICK_AIR, that means if the player did just click in the air, and didn't break a block or sth similar.
    PHP:
     @param PlayerInteractEvent $event //Just documentation
     
    @priority NORMAL //Will run at normal priority.
     
    @ignoreCancelled false //Will not fire the function, if other plugins cancelled the event.
     
  6. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
    thanks and why this give me syntax error?

    PHP:
    if($item->getName() == C::GREEN ."Help"){
    here it running without error:

    PHP:
    public function onItemUse(DataPacketReceiveEvent $event){
    $br C::RESET C::WHITE "\n";
    $pk $event->getPacket();
    $player $event->getPlayer();
    $level $event->getPlayer()->getLevel();
    if(
    $pk instanceof UseItemPacket and $pk->face === 0xff) {
    $item $player->getInventory()->getItemInHand();
    if(
    $item->getName() == C::GREEN ."Help"){
    $this->Help($player);
    }
     
    Last edited by a moderator: Nov 20, 2016
  7. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Because you messed up the syntax!
     
    Primus likes this.
  8. Reid

    Reid Spider Jockey

    Messages:
    43
    Make sure any time that there is a { there is a }
     
  9. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
  10. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Use $item->getCustomName(), not $item->getName(). And give everyone a like here in the thread, especially these, who have pasted code...
     
    Last edited: Nov 19, 2016
    HimbeersaftLP and Reid like this.
  11. imYannic

    imYannic Baby Zombie

    Messages:
    113
    Ehh no?
     
  12. Reid

    Reid Spider Jockey

    Messages:
    43
    Oh 0.0 I didn't read that right at all I'm sorry
     
  13. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Wrong, pocketmine\item\Item::getName() checks if the item has a custom name and returns it if there is one. https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/item/Item.php#L638

    And, don't ask for likes (for anybody) unless you're asking to get banned.
     
  14. Harviy11

    Harviy11 Baby Zombie

    Messages:
    100
  15. imYannic

    imYannic Baby Zombie

    Messages:
    113
    I just recommended him to give the people who helped him a like, because he just takes the code... Hard to understand?
     
    Primus likes this.
  16. Jack Noordhuis

    Jack Noordhuis Zombie Pigman Poggit Reviewer

    Messages:
    618
    GitHub:
    JackNoordhuis
    Is it hard to understand that people can press the like button when they feel like and not when you or anyone else tells them too?
     
Thread Status:
Not open for further replies.
  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.