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

Solved Need help | problème with m'y code

Discussion in 'Development' started by armagadon159753, Aug 24, 2017.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I have a problème with m'y code and console dont display error

    Already thank


    Code:
    https://pastebin.com/zy565y9n

    What I am trying to do:

    If a player is OP and in the world "world" then the player can break or place blocks

    The default player can not break blocks or place

    If there are players in world "world" then they may not be able to strike even if this one is OP
     
  2. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    This should work:
    PHP:
    <?php

    public function onPlace(BlockPlaceEvent $event) {
      if ((
    $player $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) {
        
    $player->sendMessage("You aren't allowed to place blocks here!");
        
    $player->getLevel()->addSound( new FizzSound$player->getLocation()));
        
    $event->setCancelled();
      }
    }

    public function 
    onBreak(BlockPlaceEvent $event) {
      if ((
    $player $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) {
        
    $player->sendMessage("You aren't allowed to break blocks here!");
        
    $player->getLevel()->addSound( new FizzSound$player->getLocation()));
        
    $event->setCancelled();
      }
    }

    public function 
    onDamage(EntityDamageEvent $event) {
      if (
    $event->getEntity()->getLevel()->getName() === "world") {
        
    $event->setCancelled();
      }
    }
    ?>
     
    armagadon159753 likes this.
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    But with this code:
    https://pastebin.com/NBC2fpKp

    Only the default players can place and break blocks while the OP can not
     
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Because setCancelled(true) means you set it cancelled, while using setCancelled(false) means you explicitely uncancel it.
     
  5. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753

    OP players can break or set blocks but they receive the message to the non-OP player.
    $player->sendMessage("You aren't allowed to break blocks here!");
    $player->getLevel()->addSound( new FizzSound( $player->getLocation()));
     
  6. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    1. PHP:
      public function onPlace(BlockPlaceEvent $event) {
               if((
      $player $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) { // Checks if player is in level "world" and if player is NOT OP.
             
      $event->setCancel(true); // Cancel it because the player is NOT OP.
                  
      $player->sendMessage(TextFormat::RED"Vous ne pouvez rien placer!");

                 }else{ 
      // Checks if player is in Level "world" and if the player IS OP.
              //  $event->setCancelled(true); don't cancel the event as the player IS OP!
                 
      }
          }

          public function 
      onBreak(BlockBreakEvent $event) {
              if((
      $player $event->getPlayer())->getLevel()->getName() === "world" && !$player->isOp()) {
                  
      $event->setCancelled(true);
                  
      $player->sendMessage(TextFormat::RED"Vous ne pouvez rien casser!");

                 }else{
            
      //   $event->setCancelled(true);
             
      }
         }
     
    armagadon159753 likes this.
  7. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    2017-08-24 [11:56:57] [Server thread/CRITICAL]: "Could not pass event 'pocketmine\event\block\BlockPlaceEvent' to 'HenoriaCore v1': Call to undefined method pocketmine\event\block\BlockPlaceEvent::setCancel() on armagadon\C
    2017-08-24 [11:56:57] [Server thread/CRITICAL]: Error: "Call to undefined method pocketmine\event\block\BlockPlaceEvent::setCancel()" (EXCEPTION) in "/plugins/HenoriaCoreSAVE/src/armagadon/C" at line 72

    Fonction:

    }else{ // Checks if player is in Level "world" and if the player IS OP.
    // $event->setCancelled(true); don't cancel the event as the player IS OP!
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Read the error and fix it yourself!
     
  9. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Typo error, check your spelling at line 72
    It's
    PHP:
    $event->setCancelled();
    and not
    PHP:
    $event->setCancel();
     
    sharletsings123 likes this.
  10. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Development isn't magic. You can't just call any function you want and think it will work. Google could've easily answered that specific non-pocketmine issue you are facing. Why wait for someone to help you out when you can instantly get your answers from Google?

    I'm not targeting anyone specifically. I've come across many who think PHP errors can only be solved by posting them on the PocketMine forums. Just read the error. The solution is reading the error. It's not an error code. PHP is helping you by telling you whats wrong.

    What do you understand from the error?
    Call to undefined method pocketmine\event\block\BlockPlaceEvent::setCancel()
     
  11. Awzaw

    Awzaw Zombie Pigman Poggit Admin

    Messages:
    726
    GitHub:
    awzaw
    Also, you should use an IDE with the pocketmine src included so it will tell you about this kind of error and others as you type, or copy/paste...
     
  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.