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

How count height of blocks that the player has dropped.

Discussion in 'Development' started by Brendp, May 12, 2017.

  1. Brendp

    Brendp Creeper

    Messages:
    4
    GitHub:
    Brendobtu
    Hello, I'm learning php
    I would like to know how to count height of blocks that the player has dropped.
    this is not working
    PHP:
    public function onDamage(EntityDamageEvent $event){
            
    $player $event->getEntity();
            
    $this->jump[$player->getY()] = new Position(round($player->getY()));
          
      if(
    $event->getCause() === EntityDamageEvent::CAUSE_FALL){
        
    $this->fall[$player->getY()] = new Position(round($player->getY()));
                  
        
    $result $this->fall[$player->getY()] -  $this->jump[$player->getY()];
      
        
    $player->sendMessage("You fell out of ".$result." blocks");
    }}
     
    Last edited by a moderator: May 12, 2017
  2. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
  3. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
  4. Brendp

    Brendp Creeper

    Messages:
    4
    GitHub:
    Brendobtu
    sorry I don't understand what to do, I'm trying, but I'm not getting results
     
  5. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    I would use PlayerMoveEvent to find the starting point of the fall.
     
  6. Brendp

    Brendp Creeper

    Messages:
    4
    GitHub:
    Brendobtu
    I tried that but it doesn't work
    PHP:
        public function onMove(PlayerMoveEvent $event){
        
    $player $event->getPlayer();
            
    $this->fall[$player->getFloorY()] = new Position(round($player->getFloorY()));
            }


       
    public function 
    onDamage(EntityDamageEvent $event){
            
    $player $event->getEntity();
             if(
    $event->getCause() === EntityDamageEvent::CAUSE_FALL){
                 
    $result $player->getY() - $this->fall[$player->getFloorY()];
                    
    $player->sendMessage("§8[§cBritz§8] ".$result." .");  }}
    the following error:
    object of class pocketmine\level\Position could not be converted to int in /plugins/hab/src/brendo/EventListener.php on line 85




    :
     
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    Firstly, you clearly have no idea what you are doing because you don't know the proper parameters for the Position class.
    Secondly, you are trying to set an invalid position(as stated firstly) to an array by it's Y level which is incorrect logic due to more than one player being able to have the same y level.
    Thirdly, you will not need to use the EntityDamageEvent for what you are trying to do. Have you though through exactly how you want to calculate the player's falling height? How will you set their damage cause through an event that only triggers after they take damage which won't occur?
     
  8. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    Why measure it twice? It's already measured internally. Why make an extra handler and waste CPU? Just use the fallDistance.
     
    Last edited: May 13, 2017
    jasonwynn10 and HimbeersaftLP like this.
  9. TheDiamondYT

    TheDiamondYT Zombie

    Messages:
    298
    GitHub:
    TheDiamondYT1
    Also you should check if $event->getEntity() is an instance of a Player.
     
  10. Brendp

    Brendp Creeper

    Messages:
    4
    GitHub:
    Brendobtu
    Thank you all, I am getting better results, I will keep trying
     
  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.