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

Player hit by Particle

Discussion in 'Development' started by armagadon159753, Oct 14, 2017.

  1. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    how to check if a particle (Duster) and presents in a player
     
  2. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    $bool = $player->asPosition()->equals($particle->asPosition());
     
    armagadon159753 likes this.
  3. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    I can use if i want player die?

    PHP:
    if($player->asPosition()->equals($particle->asPosition()));
    $player->setHealt(0);
     
  4. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    PHP:
    if($player->asPosition()->equals($particle->asPosition()))
        
    $player->kill();
     
    armagadon159753 likes this.
  5. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    It is very unlikely Position->equals(Position) will return true, as it has to be precisely the same position (float precisely). You could first round the Vector3 to even make it possible for this to work.
     
    Muqsit and Jack Noordhuis like this.
  6. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    PHP:
    public function onIneract(PlayerInteractEvent $ev) {
                
    $player $ev->getPlayer();
                if (
    $ev->getItem()->getId() === 369) {
                   
                    
    $directonVector $player->getDirectionVector();
                   
                    for (
    $i 3$i 20$i++) {
                        
    $pos $directonVector->multiply($i)->add($player);
                       
                        if (
    $player->getLevel()->getBlockIdAt($pos->x$pos->y$pos->z) !== 0) {
                            return;
                        }
                       
                        
    $particle = new DustParticle($pos000);
                        
    $player->getLevel()->addParticle($particle);
                       
                        foreach (
    $player->getLevel()->getEntities() as $ent) {
                            if (
    $ent === $player) {
                                continue;
                            }
                            if (!isset(
    $temp)) {
                                
    $temp $ent;
                            }else{
                                if (
    $ent->distance($pos) < $temp->distance($pos)) {
                                    
    $temp $ent;
                                }
                            }
                        }
                        if (!isset(
    $temp)){
                        }elseif (
    $temp->distance($pos) < 2) {
                            for (
    $a=4$a<5$a++) {
                                
    $par = new FlameParticle($pos);
                                
    $par->setComponents(
                                    
    $pos->+ (self::random() * 1) * 3
                                    
    $pos->0.3
                                    
    $pos->+ (self::random() * 1) * 3
                                
    );
                                
    $player->getLevel()->addParticle($par);
                                if(
    $player->asPosition()->equals($particle->asPosition())){
                                    
    $player->kill();
                                }
                            }
                            return;
                        }
                    }
                }
            }
        }
     
  7. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You can't move a particle in Bedrock Edition, nor can you listen to any packets that hold particles' position. But you can do assumption physics and figure out the position of a moving particle. Particle->asVector3() or Particle->asPosition() will return the initial position of the particle. The position doesn't update like it does in entities. Because unlike entities, position of particles cannot be found through packets.
     
    jasonwynn10 and Sandertv like this.
  8. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    As I previously mentioned, checking for equality without rounding the 2 vectors is not going to work out for you.
     
  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.