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. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Like i said, the player can only be at 1 position, so when you check it like that only 1 of the if wil be true unless they are checking the same position, use or instead
     
  2. #A6543

    #A6543 Zombie

    Messages:
    267
    How would I do it? Pls with example
     
  3. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    $inside=false;
    foreach(
    $nrs as $nr) {
        if(
    $player->getLevel()->getBlock($player->subtract(0,$nr,0))->getID() == or $player->getLevel()->getBlock($player->subtract(0,-$nr,0))->getID() == 1) {
            
    $inside=true;
            break;
        }
    }
    if(
    $inside$player->sendPopup(TextFormat::GREEN "You are in a stone room");
     
  4. #A6543

    #A6543 Zombie

    Messages:
    267
    But I need to check if the block oder AND under the player is stone. And if I use && it doesn't work
     
  5. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    You mean above and under?
    000000000
    P
    P
    000000000
    Like this? 0 as stone and P as player
     
  6. #A6543

    #A6543 Zombie

    Messages:
    267
    Yes
     
  7. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    PHP:
    $up false;
    $down false;
    for(
    $i=1;$i <= 5;$i++){
        if(
    $player->getLevel()->getBlock($player->subtract(0,$i,0))->getID() == 1$down=true;
        if(
    $player->getLevel()->getBlock($player->add(0,$i,0))->getID() == 1$up true;
    }
    if(
    $up and $down$player->sendPopup(TextFormat::GREEN "You are in a stone room");
     
  8. #A6543

    #A6543 Zombie

    Messages:
    267
    That's that worked! And how can I now check it for the left and right site of the player?
     
  9. #A6543

    #A6543 Zombie

    Messages:
    267
    And can I check if the block under $down is stone and if the block above $up is stone?
     
  10. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Depends on how you want to identify where is left and right side of the player
    Just add these 4 lines
    Before for loop:
    PHP:
    $upup false;
    $downdown false;
    Inside for loop:
    PHP:
    if($player->getLevel()->getBlock($player->subtract(0,$i+1,0))->getID() == 1$downdown=true;
    if(
    $player->getLevel()->getBlock($player->add(0,$i+1,0))->getID() == 1$upup true;
    #if block under down is stone, $downdown is true, same goes for $upup
     
  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.