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

Get last player position

Discussion in 'Development' started by BEcraft, Jan 28, 2017.

  1. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
    Hi I'm here again xD
    I would like to know how to get last player position, for example if a player die don't teleport to lobby just teleport to same position that player was before die :D
     
  2. xBeastMode

    xBeastMode Shog Chips

    Messages:
    0
    Have you even attempted something instead of just asking?
     
  3. BEcraft

    BEcraft Slime

    Messages:
    79
    GitHub:
    BEcraft
  4. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Try looking at the session code of EssentialsPE. On teleporting, it stores the position, allowing you to do /back to return to that point.
     
    Muqsit likes this.
  5. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    PHP:
    /** @var $level */
    private $level;

    /** @var $position */
    private $position;

    /**
    * @param PlayerDeathEvent $event
    */
    public function onDeath(PlayerDeathEvent $event) {
        
    $player $event->getPlayer();
        
    $this->level $player->getLevel()->getName();
        
    $this->position = new Vector3($player->getX(), $player->getY(), $player->getZ());
    }

    /**
    * @param PlayerRespawnEvent $event
    */
    public function onRespawn(PlayerRespawnEvent $event) {
        
    $player $event->getPlayer();
        if(
    $player->getLevel() != $this->level) {
            
    $player->teleport($this->level);
        }
        
    $player->teleport($this->position);
    }
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    Note that you could simply store $player->getPosition() in a variable. Position contains the xyz and the level, so that the level variable would not have to be made.
     
    Thunder33345 likes this.
  7. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    I'll try next time.
     
  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.