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

Solved Player level Detection

Discussion in 'Development' started by CupidonSauce173, Aug 27, 2018.

  1. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Hi, basically, I try to make my plugin to force to send items to a player when the player change of level..I tried the PlayerMoveEvent but it was kinda stupid..
    Example the player get in the level "lobby", it will clear the inventory and send a couple of items, when he enter in level "combo" it will clearAll and send other items...with PlayerMoveEvent it was KINDA working but lets say that the server didn't like that way lol. I checked a little into pocketmine and I found EntityLevelChangeEvent...I have no idea on how to use it but I am pretty sure that its there..
    It would only send one time items.
    Thank you
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Listen to EntityLevelChangeEvent
     
    OnTheVerge likes this.
  3. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Yes it's just that I have no clue on how to use this event, I never used it
     
  4. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    and I want each of my worlds to have specific items
    example
    Diamond = item
    Combo = item1
    Lobby = item2

    and if the entity change level to Combo from Diamond, it will clear inventory and send item1, Diamond to Combo = clear inventory and send item, Diamond to Lobby = clear inventory and send item2 and etc
     
  5. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    Have you tried to do that yourself? If so send us code. This is "Development" not "Help"
     
    OnTheVerge and RyanShaw like this.
  6. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    PHP:
    class YourClass implements Listener {
        public function 
    levelChange(EntityLevelChangeEvent $event) {
            
    $entity $event->getEntity();
            if (
    $entity instanceof Player) {
                
    $level $event->getTarget()->getName();
                
    $levels = ['lobby' => [Item::get(Item::DIAMOND), Item::get(Item::EMERALD)], 'combo' => [Item::get(Item::DIRT), Item::get(Item::GRASS)]]
                foreach (
    $levels[$level] as $item) {
                    
    $entity->getInventory()->clearAll();
                    
    $entity->getInventory()->addItem($item);
                }
            }
        }
    }
     
    Last edited: Aug 27, 2018
  7. Primus

    Primus Zombie Pigman

    Messages:
    749
    PHP:
    $entity instanceof Player
     
  8. RumDaDuMCPE

    RumDaDuMCPE Witch

    Messages:
    67
    GitHub:
    RumDaDuMCPE
    Most probably no cows changing levels.
    But just in case, I've edited. Thanks.
    :3
     
    Last edited: Aug 27, 2018
  9. Primus

    Primus Zombie Pigman

    Messages:
    749
    Technically it's possibe, but
    [​IMG]
     
    RumDaDuMCPE likes this.
  10. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    I tried and nothing happen
     
  11. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Nvm. Thank you a lot!
     
  12. MalakasPlayzMCPE

    MalakasPlayzMCPE Zombie Pigman

    Messages:
    667
    add:
    PHP:
        public function onEnable() : void{
            
    $this->getServer()->getPluginManager()->registerEvents($this$this);
        }
     
  13. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Just a little thing example if I put
    PHP:
    'Combo' => [Item::get(Item::DIRT), Item::get(Item::GRASS), Item::get(Item::DIAMOND_SWORD)],
    It will only add the Diamond Sword (always the last item), how can I fix that ?
     
  14. DaPigGuy

    DaPigGuy Slime

    Messages:
    86
    GitHub:
    DaPigGuy
    For each item, the inventory is cleared, causing this issue. You should move the line clearing the inventory out of the foreach loop.
     
    RumDaDuMCPE likes this.
  15. CupidonSauce173

    CupidonSauce173 Zombie

    Messages:
    298
    GitHub:
    cupidonsauce173
    Worked thx
     
  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.