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

Protection help

Discussion in 'Development' started by Junkdude, Jan 7, 2017.

  1. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Hello, I'm trying to to stop certian events from being triggered if a player is inside a certian area. I just dont know how to define/make/check the region, is there any chance someone could show me? Thank you
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    do you need some logic that returns if the player is inside an area?
    PHP:
    <?php
    $object 
    Position of object; (Vector3/Position/Location/PlayerObject)
    $area = new Area($vec3startPos$vec3endPos);
    unset(
    $vec3startPos);
    unset(
    $vec3endPos);

    class 
    Area{
        use 
    pocketmine\math\Vector3;
        
        private 
    $min = [0,0,0];
        private 
    $max = [0,0,0];
        
        public function 
    __construct(Vector3 $vec3startPosVector3 $vec3endPos){
            
    $this->min = [$vec3startPos->x$vec3startPos->y$vec3startPos->z];
            
    $this->max = [$vec3endPos->x$vec3endPos->y$vec3endPos->z];
        }
        
        public function 
    setStart(Vector3 $vec3startPos){
            
    $this->min = [$vec3startPos->x$vec3startPos->y$vec3startPos->z];
            return 
    $this;
        }
        
        public function 
    setStop(Vector3 $vec3endpos){
            
    $this->max = [$vec3endPos->x$vec3endPos->y$vec3endPos->z];
            return 
    $this;
        }
        
        public function 
    isInsideArea(Vector3 $object) : bool{
            return (
    $object->>= $this->min[0] && $object-><= $this->max[0]
                    && 
    $object->>= $this->min[1] && $object-><= $this->max[1]
                    && 
    $object->>= $this->min[2] && $object-><= $this->max[2]);
        }
    }
     
    corytortoise likes this.
  3. Junkdude

    Junkdude Zombie

    Messages:
    346
    GitHub:
    JunkDaCoder
    Sorta, i just need to check the coords of player and see if they are in the region but ill try 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.