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

Unable to KnockBack more than 1 player.

Discussion in 'Development' started by RumDaDuMCPE, Aug 22, 2017.

  1. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    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:
    <?php

    namespace Core\Events;

    use 
    pocketmine\{item\Itemevent\player\PlayerInteractEventServerPlayermath\AxisAlignedBBnetwork\mcpe\protocol\LevelEventPacketlevel\Levellevel\particle\HugeExplodeParticlelevel\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($playerfalse);
                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($player3$target->$player->x$target->$player->z1.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
    //                        }
                        
    }
                    }
                }
            }
        }
    }
    ?>

    PLEASE HAAAAALP!!! ;-;
     
  2. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Ummmm.... Does no one know the code to Knockback a player using setMotion()?

    T_T
     
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Sandertv likes this.
  4. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
  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.