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(35, 14)if($under->getId == $redwool) please respond asap
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}
PHP: $player = $event->getPlayer();$block = $player->getLevel()->getBlock($event->getPlayer()->subtract(0, 1, 0));if($block->getId() == $redwool) {//Code}
Thanks, but how about the redwool id, $redwool = Block::get(35, 14) does not work, nor $redwool = Block::get(35:14)
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 . P.S. $redwool = Block::get(Block::WOOL, 14) is the right one.
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
I haven't touched PocketMine in forever but pretty sure its getDamage() Which Returns the meta if the item is a Block
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
You could try PHP: $under = $player->getLevel()->getBlock($player->add(0, -1, 0));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