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

Teleport every player in arena to another game?

Discussion in 'Facepalm' started by Kyd, Jun 29, 2017.

  1. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I am working on SkyWars plugin for my minigame server , but I have not idea how to do this. I have lots of tries to do this I saved spawns to array etc, but not sucesfull. Can everyone give me example for this?
     
  2. Eduardo

    Eduardo Baby Zombie

    Messages:
    100
    GitHub:
    xBeastMode
    There must be a hidden message here.
    2.jpg
     
    falk, Teamblocket, Muqsit and 2 others like this.
  3. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
  4. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    And we don't even know how you define an "arena" in code.
     
  5. Teamblocket

    Teamblocket Zombie

    Messages:
    301
    GitHub:
    teamblocket
    lol, off topic sorry buts thats funny
     
  6. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I have Arena.php Object which has stored players in array in it
     
  7. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    So show how the Arena class is defined (the prototype).
     
  8. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PHP:
    /** @var  Arena $areny */
    public $areny = [];

    public function 
    getNewArena($name){
    $a = new Arena($name$this);
    $this->areny[$name] = $a;
     
    Last edited: Jun 30, 2017
  9. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    What does Arena class contain?
     
  10. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    The active players in the arena class is probably an array, just foreach them and Add them to the queue again?
     
  11. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I want teleport every player in arena to another spawn in map...
     
  12. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Under the condition that ____?
     
  13. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Uh, use Player::teleport()
     
  14. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    But How to select another spawn position for every player?
     
  15. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    That is entirely your own game logic, right?
     
  16. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
  17. Zayd

    Zayd Witch

    Messages:
    55
    GitHub:
    ZaydPE
    Ah... Well you could do something like putting the spawns in an array...
     
  18. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    I have stored spawns now how to teleport every player to another spawn??
    PHP:
    $this->arenas["sw-1"] = ['lobby" => new Vector3(124, 20, 78),
        '
    1sign' => new Vector3(488, 21, 493),
        '
    1spawn' => new Vector3(0, 10, 5),
        '
    2spawn' => new Vector3(0, 10, -1) ];
     
  19. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    You are insecure about sharing your relevant code, how can we help you when we don't even know your Arena class's structure?
     
  20. Kyd

    Kyd Zombie Pigman

    Messages:
    678
    GitHub:
    boi1216
    PHP:
    <?php

    namespace SkyWars\Game;

    use 
    pocketmine\Player;

    use 
    pocketmine\Server;

    use 
    pocketmine\event\Listener;

    use 
    pocketmine\utils\Config;

    use 
    pocketmine\math\Vector3;

    use 
    pocketmine\event\player\PlayerInteractEvent;

    use 
    pocketmine\event\player\PlayerQuitEvent;

    use 
    SkyWars\Scheduler\GameTask;

    use 
    SkyWars\SkyWars;

    class 
    Arena implements Listener{

        
    /** @var Player[] */
        
    public $players = [];

        
    /** @var Player[] */
        
    public $spectators = [];

        public 
    $starting false;

        public 
    $game 0;

        public 
    $ending false;
        
    /** @var  GameTask $task */
        
    public $task;

        public 
    $winnerName;

        public 
    $mainData;

        public 
    $joinable true;

        public 
    $plugin;

        public 
    $id;

        public function 
    __construct($idSkyWars $plugin){
            
    $this->id $id;
            
    $this->plugin $plugin;
            
    $this->mainData $plugin->arenas[$id];
            
    $this->enableScheduler();
        }

        public function 
    enableScheduler(){
            
    $this->plugin->getServer()->getScheduler()->scheduleRepeatingTask($this->task = new GameTask($this), 20);
     }

     

        public function 
    stopGame(){
            foreach(
    array_merge($this->players$this->spectators) as $p){
                
    $p->teleport(Server::getInstance()->getDefaultLevel()->getSafeSpawn());
                
    $p->getInventory()->clearAll();
                
    $p->setHealth(20);
                
    $p->setFood(20);
            }
            
    $this->unsetAll();
        }

        public function 
    unsetAll(){
            
    $this->spectators = [];
            
    $this->players = [];
            
    $this->joinable true;
            
    $this->starting false;
            
    $this->task->startTime 60;
            
    $this->game 0;
            
    $this->winnerName null;
            
    $this->ending false;
        }

        public function 
    onInteract(PlayerInteractEvent $e){
            
    $b $e->getBlock();
           
    // if($b->x == $this->mainData["sign"]->x and $b->z == $this->mainData["sign"]->z and $y =  $this->mainData["sign"]->y){
                
    $this->joinToArena($e->getPlayer());
           
    // }
        
    }

        public function 
    getAllPlayers(){
            foreach(
    $this->players as $p){
                return 
    $p;
            }
        }

        public function 
    onQuit(PlayerQuitEvent $e){
            
    $p $e->getPlayer();
            
    $this->onPlayerQuit($p); 
        }

        public function 
    checkAlive(){
            if(
    $this->ending == false){
                if(
    count($this->players) == 1){
                    if(
    $this->ending == false) {
                        
    $this->winnerName $this->getAllPlayers()->getName();
                        foreach (
    $this->players as $p){
                            
    $p->addTitle("§l§6VICTORY!""§7You were the last man standing!");
                    }
                    
    $this->ending true;
                    foreach(
    array_merge($this->spectators$this->players) as $p){
                        
    $p->sendMessage("§l§a-----------------------------§r\n§l§7              SkyWars       Â§r\n              Â§eWinner - " $this->winnerName);
                    }}
                }
            }
        }

        public function 
    onPlayerQuit(Player $p){
            if(isset(
    $this->players[strtolower($p->getName())])){
                unset(
    $this->players[strtolower($p->getName())]);
            }
            if(isset(
    $this->spectators[strtolower($p->getName())])){
                unset(
    $this->spectators[strtolower($p->getName())]);
            }
        }

        public function 
    startGame(){
            
    $this->starting false;
            
    $this->joinable false;
            
    $this->game 1;
           foreach(
    $this->players as $p){
         
    $p->addTitle("test");
         
    $p->getInventory()->clearAll();
    }
        }

        public function 
    joinToArena(Player $p){
            if(
    $this->joinable == false){
                
    $this->spectators[strtolower($p->getName())] = $p;
                
    $p->sendMessage("Joining as spectator");
                return 
    false;
            }
            if(
    count($this->players) >= 12){
                
    $p->sendMessage("Arena full / Check task");
            }
            
    $this->players[strtolower($p->getName())] = $p;
            
    $p->getInventory()->clearAll();
            
    $p->sendMessage("Joining arena $this->id test");
            
    $this->checkAll();
        }

        public function 
    checkAll(){
            if(
    count($this->players) > and $this->game == 0){
                
    $this->starting true;
            }
            if(
    count($this->players) >= 12 and $this->game == 0/*TODO Check for time*/){
                
    //Short time
            
    }
        }

    }
     
  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.