I have a code that (should) set all the players in a given area to be knocked back, if one of the players interact with a clay item (ID: 337). It works, but doesn't work. It only knocks back one player per use. I need to make it knock back all the players (except the one using it) in the given area. Suggestion: It's probably something with the knockBack() function. Im messing up somewhere. Please give me a way to do the same thing, but with the setMotion() function. Thanks <3 Da Code: PHP: <?phpnamespace Core\Events;use pocketmine\{item\Item, event\player\PlayerInteractEvent, Server, Player, math\AxisAlignedBB, network\mcpe\protocol\LevelEventPacket, level\Level, level\particle\HugeExplodeParticle, level\sound\LaunchSound};class SpecialItems extends \Core\BaseFiles\BaseEvent { /** * @priority HIGH */ public function onInteract(PlayerInteractEvent $event) { $player = $event->getPlayer(); $inv = $player->getInventory(); $item = $inv->getItemInHand(); $iname = $item->getName(); $ak = Server::getInstance()->getPluginManager()->getPlugin("AdvancedKits"); if ($item->getId() === 337) { $kit = $ak->getPlayerKit($player, false); if (isset($ak->hasKit[strtolower($player->getName())])) {// if (Loader::getInstance()->getAreas()->isInAnyArena($player)) { $targets = ($lvl = $player->getLevel())->getNearByEntities(new AxisAlignedBB($player->getX() - 8, $player->getY() - 8, $player->getZ() - 8, $player->getX() + 8, $player->getY() + 8, $player->getZ() + 8)); foreach ($targets as $target) { if ($target instanceof Player && $target->getName() !== $player->getName()) { $target->knockBack($player, 3, $target->x - $player->x, $target->z - $player->z, 1.4); foreach ([ $player->getY() + 3, $player->getY() + 4, $player->getY() + 5, $player->getY() + 6 ] as $y) { foreach ([ $player->getX() - 1, $player->getX() - 2, $player->getX() - 3, $player->getX() + 1, $player->getX() +2, $player->getX() + 3 ] as $x) { foreach ([ $player->getZ() - 1, $player->getZ() - 2, $player->getZ() - 3, $player->getZ() + 1, $player->getZ() + 2, $player->getZ() + 3 ] as $z) { $lvl->addParticle(new HugeExplodeParticle(new \pocketmine\math\Vector3($x, $y, $z))); } } } $lvl->addSound(new LaunchSound($player->getLocation()), [$player, $target]); // $inv->removeItem(Item::CLAYBLAHBLAHBLAH WILL DO LATER// } } } } } }}?> Spoiler PLEASE HAAAAALP!!! ;-;
Cuz knockBack() eventually redirects to setMotion(). https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/entity/Living.php#L401