Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Multiple Spawning points

Comments in 'Plugin Development' started by zombie_Power, Nov 22, 2015.

  1. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Greetings,

    I have been searching for a way to develop multiple spawn points for a minigame. So, basically, as you may have played or/and seen HungerGames before ( I am not creating Hunger/SurvivalGames), I want the players to be teleported to different locations, while not being teleported to the same point, where the other player has been located. I will work out a way, if the player leaves (PlayerQuitEvent), so a new player can join at that previous player's location. I am a little confused, as how may I do it.

    P.S. I do know how to teleport a player, I am just unsure, that how may I find, if the player is located at that position and then teleport the next joining player to the new spawn point. (the minigame and the lobby and located in two different worlds, due to Transferring issues in 0.13)

    Any assistance appreciated :)
    Last edited: Nov 22, 2015
  2. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Create an array of arrays, like this:
    PHP:
    $this->worlds = new Config($this->getDataFolder()."worlds.yml"Config::YAML, array(
                
    "lobby" => "Lobby",
                
    "lobbySpawn" => [
                    
    => 128,
                    
    => 70,
                    
    => 128
                    
    ],
                
    "mapName" => [
                  
    "neededPlayers" => 8,
                  
    "minplayers" => 6,
                  
    "maxSlots" => 11,
                  
    => [
                    
    128,
                    
    5,
                    
    128,
                    
    open
                  
    ],
                  
    => [
                    
    128,
                    
    5,
                    
    128,
                    
    open
                  
    ]
    //add more here
                
    ]
            ));

    Then change one to "taken" when a player joins and "open" when a player leaves

    PHP:
    $this->cords $this->plugin->worlds->getNested($worldName.".".$this->plugin->nextSpawnNumber);
    You will need to figure out the code for checking if a slot is taken by yourself, but here is an idea:
    1. Get the slot at nextSpawnNumber, check if it is open, if not then add 1 to nextSpawnNumber and go to step 2
    2. Do it again with nextSpawnNumber and got to step 1
    zombie_Power likes this.
  3. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Don't be so quick to judge help man, I wrote it, and it works flawlessly.
  4. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    Omg.. sorry. Wrong thread XD
  5. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Sure I forgive you man...
    zombie_Power likes this.
  6. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Just put the players as specific Players with specific spawns when the game starts, not when they join. That makes it a loy easier
  7. zombie_Power
    Offline

    zombie_Power Active Member

    Joined:
    Sep 7, 2015
    Posts:
    239
    Minecraft User:
    Zombie_Power
    specific players?
  8. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    Same thing, just depends on where you put it.
  9. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Yes, like
    Player1(spawn: 4, 4, 4);
    Player 2(spaen: 5, 5, 5); etc
  10. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    Try this:
    PHP:
    public $x;
    public 
    $z;
    public 
    $y;

    public function 
    onLevelChange(EntityLevelChangeEvent $event) {
      
    $player $event->getEntity();
      
    $level $event->getTarget();

      if(
    $player instanceof pocketmine\Player) {

      if(
    $player->getLevel()->getName() == /*Target level Name*/) { //Checks if player is leaving the minigame level and sets the spawn to their location
         
    $this->$player->x;
         
    $this->$player->y;
         
    $this->$player->z;
    }

      if(
    $level->getName() == "/*Target level Name*/") {
      if(
    count($level->getPlayers()) == 1) {
        
    $this->$x;
        
    $this->$y;
        
    $this->$z;
      }

      if(
    count($level->getPlayers()) == 2) {
        
    $this->$x;
        
    $this->$y;
        
    $this->$z;
      }

      if(
    count($level->getPlayers()) == 3) {
        
    $this->$x;
        
    $this->$y;
        
    $this->$z;
      }
      
    // etc...
      
    $player->teleport(new Vector3($this->x$this->y$this->z);
       }
      }

      public function 
    onQuit(PlayerQuitEvent $event) { // I dont think this would be needed
       
    $player $event->getPlayer();
      if(
    $player->getLevel()->getName() == /*Target level Name*/) { //Checks if player is leaving the minigame level and sets the spawn to their location
         
    $this->$player->x;
         
    $this->$player->y;
         
    $this->$player->z;
    }
      }
    }
    I havent tested this, so if something doesnt work just use ur brain and modify it.
    Last edited: Nov 22, 2015
    zombie_Power likes this.
  11. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    How is that different spawn points?
  12. Hotshot_9930
    Offline

    Hotshot_9930 Notable Member Plugin Developer

    Joined:
    May 26, 2014
    Posts:
    665
    Plugins:
    2
    Minecraft User:
    HotshotHD
    It isnt. It teleports each player that joins the world to a new loacation, and if a player leaves the next player that joins will spawn to that location.
    This is perfect for minigames like HungerGames & SkyWars.
  13. Andrey Nazarchuk
    Offline

    Andrey Nazarchuk Active Member

    Joined:
    Dec 30, 2013
    Posts:
    332
    Minecraft User:
    digita1eclipse
    My way works better if your spawn code is not in the main file.

Share This Page

Advertisement