Solved Area Protect

Discussion in 'Development' started by BlawoHD, Jul 16, 2018.

  1. BlawoHD

    BlawoHD Silverfish

    Messages:
    21
    GitHub:
    BlawoHD
    How can I protect an area? (No PvP and no blocks to place)

    Could someone give me a code?
     
  2. Primus

    Primus Zombie Pigman

    Messages:
    703
    Define area. If point is inside the area, cancel damage and block place/break event.

    You might be interested in this: Falkirks/MineReset (Cuboid Area (Just a box))
     
  3. BlawoHD

    BlawoHD Silverfish

    Messages:
    21
    GitHub:
    BlawoHD
    How do I define the area and with which code?
     
  4. Primus

    Primus Zombie Pigman

    Messages:
    703
    corytortoise likes this.
  5. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Say, You have an area with coordinates;
    Minimum Z: 1
    Maximum Z: 5
    Minimum X: 10
    Maximum X: 50

    Create a class, named as you like, containing the coordinates information. In this case:
    PHP:
    <?php

    namespace test;

    use 
    pocketmine\Player;

    class 
    Areas {

        public function 
    inArea(Player $player) : bool {
            
    // Get player X and Y coordinates.
            
    $x $player->x;
            
    $z $player->z;

            
    // Define Minimum and Maximum X and Z.
            
    $x_min 10;
            
    $x_max 50;

            
    $z_min 1;
            
    $z_max 5;
            
    // Check if Player is within the Area.
        
    if ($x $x_min && $x $x_max && $z $z_min && $z $z_max) return true;
        return 
    false;
        }
    }
    Now that we have Areas.php ready, Let's try and call it:
    PHP:
    <?php

    namespace test;

    use 
    pocketmine\event\Listener;
    use 
    pocketmine\event\player\PlayerMoveEvent;
    use 
    pocketmine\plugin\PluginBase;

    class 
    main extends PluginBase implements Listener {
        public function 
    onMove(PlayerMoveEvent $event) {
            if (
    Areas::class->inArea($event->getPlayer())) {
                
    // Do stuff
            
    }
        }
    }
     
    Diduhless likes this.
  6. Phqzing

    Phqzing Spider

    Messages:
    8
    GitHub:
    phqzing
    Does this still work?
     
  7. minijaham

    minijaham Zombie Pigman

    Messages:
    737
    GitHub:
    minijaham
    This thread is already solved. Try it and see it yourself. Quit bumping old threads
     
    Axon likes this.

Share This Page

  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.