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

How to detect if player is standing in red wool

Discussion in 'Development' started by Garanokk, Sep 17, 2017.

  1. Garanokk

    Garanokk Creeper

    Messages:
    4
    I want to know how to detect if a player is standing on red wool, i tried
    PHP:
    if($under->getId == 35:14)
    Does not work, nor does
    PHP:
    $redwool Block::get(35:14) or Block::get(3514)
    if(
    $under->getId == $redwool)
    please respond asap
     
  2. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    You can use:
    PHP:
    /*
     * @var Player $player
     */
    $block = new Vector3($player->getFloorX(), $player->getFloorY() - 1$player->getFloorZ()); // gets the block the player is standing on
    $ifOnRedWool $player->getLevel()->getBlock($blockStandingOn);
    if(
    $block->getId() === 34 && $block->getDamage() === 14) { // if block's ID and meta are 34 and 14
        // do something
    }
     
    Last edited: Sep 23, 2017
    Garanokk likes this.
  3. Rysieku

    Rysieku Spider Jockey

    Messages:
    34
    GitHub:
    rysieku
    PHP:
    $player $event->getPlayer();
    $block $player->getLevel()->getBlock($event->getPlayer()->subtract(010));
    if(
    $block->getId() == $redwool) {
    //Code
    }
     
    Garanokk likes this.
  4. Garanokk

    Garanokk Creeper

    Messages:
    4
    How can i get red wool id?
     
  5. Garanokk

    Garanokk Creeper

    Messages:
    4
    Thanks, but how about the redwool id, $redwool = Block::get(35, 14) does not work, nor $redwool = Block::get(35:14)
     
  6. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    1. Block::getId() returns an integer.
    2. (35:14) Last time I checked, PHP doesn't support ratios. You'll be given an error either ways. It's obvious that didn't work but the error would have made you not mention that to us.
    3. $redwool = Block::get(35:14) or Block::get(35, 14). Even if PHP supported ratios, $redwool would be a boolean value.
    4. Even if $redwool was a Block instance, if($under->getId == $redwool) would give out an error because the property Block::$getId does not exist. You probably meant calling $under->getId() function. If you did test the code, you'd be given an error so I don't think you haven't tried solving the issue yourself or did any contributions in fixing the issue before creating a thread.
    5. Even if $under->getId returned $under->getId(), the statement in if() would return false because $redwool is a Block instance and not an integer.

    Moral: Do not include code that you haven't tested. Do not try "assuming" your code to work either. Programming is not magic where you can call any class property or function without confirming it's existence in the first place.

    It's going to be hard if you try assuming your code to work. Look up tutorials and examples or look up projects on GitHub that do what you are trying to do. Also do try the search bar, your question has probably been questioned before ;).
    xxe.PNG

    P.S. $redwool = Block::get(Block::WOOL, 14) is the right one.
     
  7. Garanokk

    Garanokk Creeper

    Messages:
    4
    I did test it several times, i have been trying to fix it for 1 whole day, it is just that i forgot to put () because i was in a rush, i tried the search bar, i don't see a question like mine before
     
    Last edited: Sep 17, 2017
  8. MioTaku

    MioTaku Witch

    Messages:
    69
    GitHub:
    uselesswaifu
    I haven't touched PocketMine in forever but pretty sure its getDamage() Which Returns the meta if the item is a Block
     
    jasonwynn10 likes this.
  9. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    I'm seeing things this days or your making things complicated? There is no reason to do $this->getServer()->getLevelByName($player->getLevel()->getName());

    YOU HAVE ALREADY GOT THE LEVEL THEN WHY GETTING IT AGAIN BY SERVER?
    $player->getLevel(); returns the level the player is in, no need extra thingy majigys
     
  10. Az928

    Az928 Baby Zombie

    Messages:
    140
    GitHub:
    theaz928
    You could try
    PHP:
    $under $player->getLevel()->getBlock($player->add(0, -10));
    if(
    $under->getId() == Block::WOOL && $under->getDamage() == 14){
      return 
    true// or do whatever u want
    }
    NOTE:
    1. You can do $player->add($x, $y, $z);
    it basically adds the number to $x, y or z;
    I did $player->add(0, -1, 0); this returns a vector3 with $player->x, $player->y - 1, $player->z; so you can get the block under player

    2. How adding -1 to $y gives a block under?!
    Well, learn math.... 2-1 = 1
    or -1 + 2 = 1;
    -1 -> 0 -> 1 -> 2


    Hope you get it
     
  11. WinterBuild7074

    WinterBuild7074 Zombie Pigman

    Messages:
    693
    GitHub:
    winterbuild7074
    Sorry, I was just totally confused. :confused:
    It's all fixed now.
     
    Last edited: Sep 23, 2017
    jasonwynn10 likes 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.