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

Checking if within coordinates

Discussion in 'Development' started by BouncyJeffer, May 9, 2017.

  1. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Hello, I'm curious to know if it's possible to check if a player is within two sets of coordinates, if so, please give an example, thanks.
     
  2. AnkitM252

    AnkitM252 Spider Jockey

    Messages:
    29
    GitHub:
    AnkitM252
  3. gsdgamer

    gsdgamer Spider Jockey

    Messages:
    28
    I like Iprotect, but what I have noticed if you choose a large area for it to protect, it doesn't protect everything that I have selected. I can have it where half my area is fine, but as soon as you go into the other half it lets players destroy blocks.
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You probably know this already, but anyway: Cartesian Plane with logic.
    PHP:
    /**
     * Assuming the region to be a cuboid, you will need
     * to take the coordinates of two opposite vertices.
     *
     * For example (X-coordinate, Y-coordinate, Z-coordinate):
     * First Vertex: (100, 20, 100)
     * Second Vertex: (200, 50, 200)
     */
    //$x = [x-coordinate of vertex 1, x-coordinate of vertex 2]; same for $y and $z.
    $x = [100200];
    $y = [2050];
    $z = [100200];

    //min($array) outputs the smallest value stored in $array.
    //max($array) outputs the largest value stored in $array.
    $minX min($x);
    $minY min($y);
    $minZ min($z);
    $maxX max($x);
    $maxY max($y);
    $maxZ max($z);
    //To check whether (Player) $player is in the region.
    $pos $player->getPosition();
    if(
        
    $pos->>= $minX and $pos-><= $maxX and
        
    $pos->>= $minY and $pos-><= $maxY and
        
    $pos->>= $minZ and $pos-><= $maxZ
    ){
        
    //$player is inside the region
    }
     
    corytortoise and SavionLegendZzz like this.
  5. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    You know, you just made it more complicated by introducing the term "Cartesian plane" :p (while the coordinates system is pretty much common sense, few people know the technical term for it :p)
     
  6. BouncyJeffer

    BouncyJeffer Spider Jockey

    Messages:
    39
    GitHub:
    bouncyjeffer
    Could you explain how to do it using the "coordinates system"?
     
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    :facepalm: look at @Muqsit post
     
    Muqsit and HimbeersaftLP like 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.