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

Solved Teleport players to a second lobby in same server

Discussion in 'Development' started by Saxavlax001, Feb 17, 2020.

  1. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Guys,can someone help me pls with something?I want to tp players to a second lobby if first lobby reach max limit of players,I mean if for example there are already 40 players on lobby1, player will be tped to lobby2,which is a different world and I tested many times my codes and I had errors and I fixed them,but tp doesn't work,idk what is wrong,my codes are used on EntityLevelChangeEvent :: (also a player who has a certain permission can join on lobby1):
    PHP:
    if ($ev->getTarget()->getName() === "hypixel1" && count(Server::getInstance()->getLevelByName("hypixel1")->getPlayers()) > 0) {
           if(
    $ev->getEntity()->hasPermission("mvp.perm") == true) {
          
    $ev->setCancelled();
          } else {
       if (
    Server::getInstance()->isLevelLoaded("hypixel1lb2") === false) {
       
    Server::getInstance()->loadLevel("hypixel1lb2");
        }
       
    $player $ev->getEntity();
       
    $player->teleport(Server::getInstance()->getLevelbyName("hypixel1lb2")->getSafeSpawn());
          }
        }
    You may saw those codes on discord too,but I posted it here with the hope I'll get help,because no one on discord helps me with my codes at the most of times.
     
  2. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    What exactly is the problem you're having with the code?
     
  3. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    It seems like my code does not execute,I can't understand why does this happen or if I did something wrong.
     
  4. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I mean it doesn't do anything.
     
  5. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    So, you are a normal player, without the mvp.perm permission in a random world, you use a plugin of choice to warp to the level "hypixel1", one other player is already in that level, right?

    And what you expect to happen is that you're warped to "hypixel1lb2", but what actually happens in that you land in "hypixel1" with the pother player, right?

    (btw, I think using that name is just a little bit trademark infringing)
     
  6. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Look,my codes actually should do this:Lets say there is a normal player joining in the server,if this player goes on "hypixel1" world and its full of a certain amount players,that player should be quickly moved to "hypixel1lb2" world,except in the case that he has the "mvp.perm",then he will stay to "hypixel1",so he won't be teleported.
    About that "but what actually happens in that you land in "hypixel1" with the pother player, right?" hm idk,player will be probably visible to all players for some seconds,until he "goes" to the second world.
    And yes the map I'm using is hypixel styled,so thats the reason,I may change it if something happen,anyway.
     
  7. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Well I think that when I removed $event->setCancelled() it fixed my issue,because it works as I want now.Anyway if someone wants to use it,use this example:
    PHP:
    if ($ev->getTarget()->getName() === "hypixel1" && count(Server::getInstance()->getLevelByName("hypixel1")->getPlayers()) > 0) {
           if(
    $ev->getEntity()->hasPermission("mvp.perm") == true) {
          } else {
       if (
    Server::getInstance()->isLevelLoaded("hypixel1lb2") === false) {
       
    Server::getInstance()->loadLevel("hypixel1lb2");
        }
       
    $player $ev->getEntity();
       
    $player->teleport(Server::getInstance()->getLevelbyName("hypixel1lb2")->getSafeSpawn());
          }
        }
     
  8. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    I just removed $ev->setCancelled();
     
  9. Diduhless

    Diduhless Baby Zombie

    Messages:
    199
    GitHub:
    Diduhless
    I suggest you using this code though, it's the same as yours above but better
    PHP:
    /**
    * @param PlayerLoginEvent $event
    */
    public function onJoin(PlayerLoginEvent $event): void {
        
    $player $event->getPlayer();
        
    $server Server::getInstance();

        
    $firstLobbyName "hypixel1";
        
    $secondLobbyName "hypixel1lb2";

        
    $server->loadLevel($firstLobbyName);
        
    $server->loadLevel($secondLobbyName);

        
    $firstLobby $server->getLevelByName($firstLobbyName);
        if(
    count($firstLobby->getPlayers()) < 40 or $player->hasPermission("mvp.perm")) {
            
    $player->teleport($firstLobby->getSafeSpawn());
            return;
        }

        
    $player->teleport($server->getLevelByName($secondLobbyName));
    }
     
  10. Saxavlax001

    Saxavlax001 Witch

    Messages:
    63
    GitHub:
    Saxavlax001
    Ok thanks,its better I think because of variables,like: $firstLobbyName = "hypixel1";
    $secondLobbyName = "hypixel1lb2";
    I may use it in future but I'm ok for now.
     
  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.