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

Check player position

Discussion in 'Development' started by #A6543, Feb 1, 2017.

  1. #A6543

    #A6543 Zombie

    Messages:
    267
    How can I check if a players walks through two block? And if the player walks around these blocks he should get a message
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Through two blocks? As in moves by two blocks??
     
  3. #A6543

    #A6543 Zombie

    Messages:
    267
    There is a wall with some empty blocks. I want to check if the players walks though the empty blocks. And if he walks around it, he gets a message
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Okay, I'm not sure what I am visualizing is right. It would be nice if you can provide an image of what you are meaning. :)
     
    #A6543 likes this.
  5. #A6543

    #A6543 Zombie

    Messages:
    267
    This
     

    Attached Files:

    Muqsit likes this.
  6. InspectorGadget

    InspectorGadget Zombie Pigman

    Messages:
    462
    GitHub:
    InspectorGadget
    I swear to god that I don't know how to attach images here :p
     
    Muqsit likes this.
  7. #A6543

    #A6543 Zombie

    Messages:
    267
    No.. I want to do it over the hole world.
     
  8. #A6543

    #A6543 Zombie

    Messages:
    267
    I want to make it like an invisible wall along the whole world were the passage is.
     
    Last edited: Feb 1, 2017
  9. #A6543

    #A6543 Zombie

    Messages:
    267
    The players should only fly through this ring: 20170201_143118.png
     
  10. #A6543

    #A6543 Zombie

    Messages:
    267
    But how can I send a message when the player fly's around it? Can I check this?
     
  11. #A6543

    #A6543 Zombie

    Messages:
    267
    I tried this to check if the block on the players right is stone. (Didn't work)
    PHP:
    $yaw $player->yaw;
    $right $yaw 180;
    $x cos($right M_PI 180) * $player->x;
    $z sin($right M_PI 180) * $player->z;
    if(
    $player->getLevel()->getBlock($player->subtract($x,0,0))->getID() === 1) {
     
  12. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    I use this to check if player is in the area
    PHP:
    #$pp is player position, $p1 is first point, $p2 is second point
        
    public function isInside(Vector3 $ppVector3 $p1Vector3 $p2){
           return ((
    min($p1->getX(),$p2->getX()) <= $pp->getX()) &&
                   (
    max($p1->getX(),$p2->getX()) >= $pp->getX()) &&
                   (
    min($p1->getY(),$p2->getY()) <= $pp->getY()) &&
                   (
    max($p1->getY(),$p2->getY()) >= $pp->getY()) &&
                   (
    min($p1->getZ(),$p2->getZ()) <= $pp->getZ()) &&
                   (
    max($p1->getZ(),$p2->getZ()) >= $pp->getZ()));
       }
     
    Marabou likes this.
  13. #A6543

    #A6543 Zombie

    Messages:
    267
    But I want to check the block on the players right
     
  14. #A6543

    #A6543 Zombie

    Messages:
    267
    Does someone know how to check if the right and the left block of a player is stone?
     
  15. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Use $this->getLevel()->getBlock() and the Position left or right of the player
     
  16. #A6543

    #A6543 Zombie

    Messages:
    267
    But my question was how to get left and right...
     
  17. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Get the facing direction and then depending on that x or y + and - 1 maybe?
     
  18. #A6543

    #A6543 Zombie

    Messages:
    267
    I tried this:
    But it isn't working correctly
    PHP:
    foreach($nrs as $nr) {
            if(
    $player->getLevel()->getBlock($player->subtract(0,$nr,0))->getID() == && $player->getLevel()->getBlock($player->subtract(0,-$nr,0))->getID() == 1) {
            
    $player->sendPopup(TextFormat::GREEN "You are in a stone room");
    }
    $nrs ist an Array with the numbers 1 to 10
     
  19. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Most likely both conditions cannot be satisfied at the same time so try using or instead of &&
     
  20. #A6543

    #A6543 Zombie

    Messages:
    267
    I tried this. But it's only true, if the player is in the middle of it. Do u know why?
    PHP:
    $in 0;
    if(
    $player->getLevel()->getBlock(new Vector3($x$y $nr$z))->getId() == 159) {
    $in++;
    }
    if(
    $player->getLevel()->getBlock(new Vector3($x$y $nr$z))->getId() == 159) {
    $in++;
    }
    if(
    $in == 2) {
    $player->sendMessage("§aTRUE");
    } elseif(
    $in == 1) {
    $player->sendMessage("§cFALSE");
    }
    }
     
  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.