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

keep experience

Discussion in 'Development' started by Levi, Jun 23, 2018.

  1. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i tried:
    PHP:
    public function onDeath(PlayerDeathEvent $event)
        {
            
    $player $event->getPlayer();
            
    $name $player->getName();
            
    $xp $player->getXpDropAmount();
            
    $this->xp[$name] = $xp;
            if (
    $event->getDrops() instanceof ExperienceOrb) {
                
    $event->setDrops([]);
            }
        }

        public function 
    onRespawn(PlayerRespawnEvent $event)
        {
            
    $player $event->getPlayer();
            
    $player->setXpLevel($this->xp[$player->getName()]);
            unset(
    $this->xp[$player->getName()]);
        }
    but dont work it does not give my xp back
     
  2. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    You can enable keep XP from pocketmine.yml
     
    Levi likes this.
  3. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    praise the lord
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    nvm theres none
     
  5. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    Umm i don't know i think maybe PocketMine removed it
     
  6. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Save xp in array when die
    And send xp back to player when respawn
     
  7. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    i did
     
  8. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    Should work
     
  9. dktapps

    dktapps Administrator Staff Member PMMP Team

    Messages:
    774
    GitHub:
    dktapps
    It never existed. Check your facts before spreading false information.
     
  10. KHAV

    KHAV Baby Zombie

    Messages:
    152
    GitHub:
    xkhhv
    All people make mistakes :p
     
  11. corytortoise

    corytortoise Skeleton

    Messages:
    825
    GitHub:
    corytortoise
    I know this issue was brought up a while back, but there are a few weird issues with PlayerRespawnEvent. It's called before attributes are reset, so the xp you set is immediately set back to default, as you can see here: https://github.com/pmmp/PocketMine-MP/blob/master/src/pocketmine/Player.php#L3657-L3685. XP is an attribute, which is handled by the AttributeMap. In these lines, all attributes are reset. If you were to try to set different health, hunger, etc. to a player on RespawnEvent, it wouldn't seem to work. It does work, it just gets negated. One workaround would be to delay setting the experience with a task, or possibly, PlayerSpawnEvent could be helpful? This issue is similar, and may need reopened since it's relevant now.
     
    Levi likes this.
  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.