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

teleport every player to another position

Comments in 'Plugin Development' started by PaulchenHD, Jul 23, 2016.

  1. PaulchenHD
    Offline

    PaulchenHD Active Member

    Joined:
    Jan 17, 2016
    Posts:
    111
    Minecraft User:
    Paulchen_HD
    Hello i like to teleport 4-8 players to another position like skywars or sg?
  2. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Save the positions, foreach the players and teleport to one of the saved positions?
    Survingo likes this.
  3. Survingo
    Offline

    Survingo Active Member

    Joined:
    Dec 6, 2015
    Posts:
    221
    PHP:
    $level $this->getServer()->getLevelByName("/*SkyWars world name*/");
    $positions = array(
       (
    $xOne$yOne$zOne$level),
       (
    $xTwo$yTwo$zTwo$level),
       (
    $xThree$yThree$zThree$level),
       (
    $xFour$yFour$zFour$level)
    );
    foreach(
    $players as $player){
      
    $player->teleport(new Position(array_rand($postions1)));
    }
    But that would be randomly and maybe two players at one position
    Last edited by a moderator: Jul 24, 2016
  4. Gamecrafter
    Offline

    Gamecrafter

    Joined:
    Nov 20, 2014
    Posts:
    978
    Plugins:
    9
    Your code syntax is incorrect. PHP doesn't use the tuple syntax from Python. Also, that is not how array_rand is used. array_rand returns the key for the value in an array, not the actual value itself. @PaulchenHD I've corrected most of the errors, but some might linger:
    PHP:
    $level $this->getServer()->getLevelByName("name here"); //Get the level by its name
    $positions = [
        [
    123],
        [
    456],
        [
    789],
        [
    123],
        [
    456],
        [
    789],
        [
    123],
        [
    456//These can be any numbers, integers are just to show, format: [x, y, z], assuming everyone will be in the same level
    ];
    $count 0;
    foreach(
    $players as $player){ //Assuming $players returns an array of players
        
    if($count++ > 8){ //Only eight players, if $count is greater than eight, we can stop teleporting players
            
    break;
        }
        
    $v $positions[$count];
        
    $player->teleport(new Position($v[0], $v[1], $v[2], $level));
    }
    array() is the same as [], but I would recommend using the latter when you're initializing an array, it's shorter. But that's just a matter of coding style. And also, the user who created this thread was not asking how to teleport players to random positions.
    Survingo likes this.

Share This Page

Advertisement