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

SW get next Play

Comments in 'Plugin Development' started by Artide, Jun 15, 2015.

  1. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    How to make my skywars plugin get next play?; like in lifeboat skywars.
  2. xiaoq
    Offline

    xiaoq Active Member

    Joined:
    Dec 23, 2014
    Posts:
    232
    Minecraft User:
    xiaoq
    get next play?
  3. PixelGuy75
    Offline

    PixelGuy75 Notable Member Plugin Developer

    Joined:
    Feb 9, 2014
    Posts:
    316
    Plugins:
    2
    Minecraft User:
    PixelGuy75
    Get next player?
  4. TonyDroide
    Offline

    TonyDroide Active Member Plugin Developer

    Joined:
    Jun 5, 2015
    Posts:
    122
    Plugins:
    1
    Minecraft User:
    TonyDroidd
    Get next play?
  5. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Get next play. When you press on a sign it teleports you to a play that is not taken, or that is open.
  6. Legoboy0215
    Offline

    Legoboy0215 Notable Member

    Joined:
    Nov 1, 2014
    Posts:
    1,747
    Minecraft User:
    Legoboy0215
    Like on sg too! 24 slots and no one on the same one.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    What is a "play"? How do you know that in terms of code?
    Tethered_ likes this.
  8. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    What I mean for "play" is game like in skywars or HG.
  9. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That depends on how your SkyWars plugin works.
  10. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Basically, it teleports a player to a space that is made using the /addslot command. Don't worry, I've the code already, but what I want it to do is pick a random one of those slots and teleport the player that touches the play sign into an open slot.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    That totally depends on how the other parts of your code work. For example, what mechanism do you use to handle the slots? How do you even remember the slots?
  12. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Well, you create a slot with "/addslot <slotName>" then it makes a new arena yaml config on the data folder "arenas" with the x, y, and z.
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Then how did you join a slot?
  14. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    What?
  15. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    I use this to get available games :
    PHP:
     public function getAvailableGame(){
        
    $openGames = [];
            
    $i 0;
            
    $k 1;
           while (
    $i !=8){
               
    $i++;
                if (
    $this->game[$i."-open"] == true){
                    
    $openGames[$k] = $i;
                    
    $k++;
                }
           }
            return 
    $openGames;
        }
    At the beginning of the code, I set my games like this :
    PHP:
     $this->game = [
                
    "1-players" => 0,"1-open"=>true,"1-started"=>false,"1-player-1"=>false,"1-player-2"=>false,"1-player-3"=>false,"1-player-4"=>false
                
    ,"2-players" => 0,"2-open"=>true,"2-started"=>false,"2-player-1"=>false,"2-player-2"=>false,"2-player-3"=>false,"2-player-4"=>false
                
    ,"3-players" => 0,"3-open"=>true,"3-started"=>false,"3-player-1"=>false,"3-player-2"=>false,"3-player-3"=>false,"3-player-4"=>false
                
    ,"4-players" => 0,"4-open"=>true,"4-started"=>false,"4-player-1"=>false,"4-player-2"=>false,"4-player-3"=>false,"4-player-4"=>false
                
    ,"5-players" => 0,"5-open"=>true,"5-started"=>false,"5-player-1"=>false,"5-player-2"=>false,"5-player-3"=>false,"5-player-4"=>false
                
    ,"6-players" => 0,"6-open"=>true,"6-started"=>false,"6-player-1"=>false,"6-player-2"=>false,"6-player-3"=>false,"6-player-4"=>false
                
    ,"7-players" => 0,"7-open"=>true,"7-started"=>false,"7-player-1"=>false,"7-player-2"=>false,"7-player-3"=>false,"7-player-4"=>false
                
    ,"8-players" => 0,"8-open"=>true,"8-started"=>false,"8-player-1"=>false,"8-player-2"=>false,"8-player-3"=>false,"8-player-4"=>false];
    However, I'm not sure it's the most efficient way to do this.
    When a game start, $game[$gameNumber-"open"] is set to false

    To join a game :
    PHP:
                        $gameAvailable $this->getAvailableGame();

    if(isset(
    $gameAvailable[1])){
                            
    $this->playerJoinGame($event->getPlayer(),$gameAvailable[1]);
                        }else{
                            
    $event->getPlayer()->sendMessage(TextFormat::RED."No game available. Please try again later");
                            
    $event->getPlayer()->knockBack($event->getPlayer(),0,0,-16,1);
                        }
    The function that teleport player, distribute kit and place in the game :
    PHP:
     public function playerJoinGame (Player $player,$gameNumber){
            
    $levelName "game-".$gameNumber;
            
    $e 0;
                while (
    $e 4){
                    
    $e++;
                    if(
    $this->game[$gameNumber."-player-".$e] == false){
                        
    $place $e;
                    }
                }
                if(isset(
    $place)){
                if(
    $place 5){
                    
    $player->teleport($this->getServer()->getLevelByName($levelName)->getSafeSpawn());
                    
    $pos $this->pedestrals["$gameNumber-$place"];
                    if(isset(
    $pos) and count($this->getServer()->getLevelByName($levelName)->getPlayers())<=4){
                        
    $player->teleport($pos);
                    }else{
                        
    $player->sendMessage(TextFormat::RED."[Error 2] No place available");
                        
    $player->teleport($this->getServer()->getDefaultLevel()->getSpawnLocation());
                    }
                
    $numberOfPlayers count($this->getServer()->getLevelByName($levelName)->getPlayers());
                foreach(
    $this->getServer()->getLevelByName($levelName)->getPlayers() as $p){
                    
    $p->sendMessage(TextFormat::BLUE."[Skywars][".$gameNumber."] Number of player(s) : ".$numberOfPlayers."/4");
                }
            }
                if (isset(
    $numberOfPlayers) and $numberOfPlayers == 4){
                    
    $this->getServer()->getScheduler()->scheduleDelayedTask(new startGame($this,$gameNumber,3),0);
                    
    $this->getServer()->getScheduler()->scheduleDelayedTask(new startGame($this,$gameNumber,2),20);
                    
    $this->getServer()->getScheduler()->scheduleDelayedTask(new startGame($this,$gameNumber,1),40);
                    
    $this->getServer()->getScheduler()->scheduleDelayedTask(new startGame($this,$gameNumber,0),60);
                    
    $this->game[$gameNumber."-open"] = false;
                }
                    
    $player->getInventory()->clearAll();
                    
    $player->setHealth(20);
                    
    $item Item::get(297);
                    
    $item->setCount(6);
                    
    $player->getInventory()->addItem($item);
                    
    $item Item::get(1);
                    
    $item->setCount(64);
                    
    $player->getInventory()->addItem($item);
                    if(isset(
    $this->playerKits[$player->getName()]) == false){
                        
    $this->playerKits[$player->getName()] = "default";
                    }
                    switch(
    $this->playerKits[$player->getName()]){
                        case 
    "default":
                            if(isset(
    $this->vips[$player->getName()]) and $this->vips[$player->getName()] == true){
                                
    $player->getInventory()->setArmorContents([Item::get(302),Item::get(303),Item::get(304),Item::get(305)]);
                                
    $player->getInventory()->addItem(Item::get(267));
                            }else{
                                
    $player->getInventory()->setArmorContents([Item::get(298),Item::get(299),Item::get(300),Item::get(301)]);

                                
    $player->getInventory()->addItem(Item::get(268));
                            }
                            break;
                        case 
    "vip":
                            
    $player->getInventory()->setArmorContents([Item::get(302),Item::get(303),Item::get(304),Item::get(305)]);

                            
    $player->getInventory()->addItem(Item::get(267));
                            break;
                        case 
    "archer":
                            
    $player->getInventory()->setArmorContents([Item::get(298),Item::get(299),Item::get(300),Item::get(301)]);
                            
    $player->getInventory()->addItem(Item::get(261));
                            
    $item Item::get(262);
                            
    $item->setCount(32);
                            
    $player->getInventory()->addItem($item);

                            break;
                        case 
    "barbarian":
                            
    $player->getInventory()->setArmorContents([Item::get(298),Item::get(299),Item::get(300),Item::get(301)]);
                            
    $player->getInventory()->addItem(Item::get(268));
                            break;

                        case 
    "miner":
                            
    $player->getInventory()->addItem(Item::get(303));
                            
    $player->getInventory()->addItem(Item::get(257));
                    }
            
    $this->game[$gameNumber."-player-".$place] = true;
            
    $this->playersInGame[$player->getName()] = true;
            
    $this->playersInGame[$player->getName()."-gameNumber"] = $gameNumber;
            
    $this->playersInGame[$player->getName()."-place"] = $place;

            }
            else{
                
    $player->sendMessage(TextFormat::RED."[Error 1] No game available. Please try again later");
            }
        
        }
    My games level names are game-$gameNumber (game-1,game-2...game-8)

    The task that start the game :

    PHP:
    <?php
    namespace Server;

    use 
    pocketmine\Player;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\utils\TextFormat;
    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\block\Block;


    class 
    startGame extends PluginTask{
        public 
    $plugin;
        public 
    $time;
        public 
    $gameNumber;
        public function 
    __construct(Main $plugin$gameNumber,$time){
            
    $this->plugin $plugin;
            
    parent::__construct($plugin);
            
    $this->gameNumber $gameNumber;
            
    $this->time $time;


        }



        
    /**
         * Actions to execute when run
         *
         * @return void
         */
        
    public function onRun($currentTick){
            
    $levelName "game-$this->gameNumber";
            
    $time $this->time;
            if(
    $time == 0){
                
    $this->plugin->game[$this->gameNumber."-started"] = true;
                
    $this->plugin->game[$this->gameNumber."-open"] = false;
                foreach(
    Server::getInstance()->getLevelByName($levelName)->getPlayers() as $p){
                    
    Server::getInstance()->getLevelByName("game-".$this->gameNumber)->setBlock(new Vector3($p->getX(),$p->getY()-1,$p->getZ()),Block::get(0,0));
                    
    $p->sendMessage(TextFormat::GREEN."[SkyWars] Game ".$this->gameNumber." started !");
                }
            }else{
                foreach(
    Server::getInstance()->getLevelByName($levelName)->getPlayers() as $p) {
                    
    $p->sendPopup(TextFormat::BLUE "[SkyWars] Game " $this->gameNumber " starting in " TextFormat::GREEN $this->time);
                }
            }

        }

    }
    Last edited: Jun 23, 2015
  16. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    You have a different way to do it, its very confusing for me.
  17. Guillaume351
    Offline

    Guillaume351 Active Member Plugin Developer

    Joined:
    Oct 11, 2013
    Posts:
    150
    Plugins:
    1
    Minecraft User:
    Guillaume351
    Maybe show us what you already have it would be easier to help you then
    PEMapModder likes this.
  18. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    I started yesterday and I'm barely in the beginning. My old code dispeared, and I haven't done the commands yet.
  19. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    No! Use objects. Using all those indices in your array is ineffective.
    Guillaume351 likes this.
  20. Artide
    Offline

    Artide Active Member

    Joined:
    Apr 20, 2015
    Posts:
    214
    Minecraft User:
    Artide5
    Look
    PHP:
            $cmd strtolower($cmd->getName());

            switch(
    $cmd) {

                case 
    'addslot':

                    if(isset(
    $args[0])){
                      
                    
    $slotname $args[0];  

                    
    $x $sender->getFloorX();
                    
    $y $sender->getFloorY();
                    
    $z $sender->getFloorZ();

                    @
    mkdir($this->getDataFolder());

                    
    $slot = new Config($this->getDataFolder() . "slots/" $slotname ".yml"Config::YAML);
                      
                        
    $slot->set(array("SlotX" => $x"SlotY" => $y"SlotZ" => $z));
                        
    $slot->save();

                }      

            }

Share This Page

Advertisement