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

build battle help

Discussion in 'Development' started by amirTBM, Mar 3, 2020.

  1. amirTBM

    amirTBM Spider Jockey

    Messages:
    27
    GitHub:
    we
    hi i am making a build battle plugin but i don't know how to make some files for main
    1. i need a vote file with functions that when my $s (time) has finished all of players can vote and votes claim and choose 1st player
    2. is it right for timing file?
    PHP:
    <?php
     
     
     
    namespace src\Build_Battle\timing;
     
     
     use 
    pocketmine\event\entity\EntityLevelChangeEvent;
     use 
    pocketmine\event\Listener;
     use 
    pocketmine\event\player\PlayerDeathEvent;
     use 
    pocketmine\event\player\PlayerQuitEvent;
     use 
    pocketmine\Player;
     use 
    pocketmine\timings\timings;
     use 
    pocketmine\timings\TimingsHandler;
     

     
     class 
    timing extends Pluginbase{
        
        
         
    /*
         * $time -> time to finish game;
         */
         
    private $time
        
         
    /*
         * set time using -> time(5)
         */
         
    public function __construct($s){
             
    $this -> time $s;
             return 
    $s;
         }
        
         public function 
    on_rest_time(){
             if ( 
    time =< ){
             
    time null;
             }
         }
         while { 
    time >= }
         do {
             
    time int;
         }
        
         while ( 
    $s 0){
         do {
          
    sleep(1);
           
    $s--;
         }       
         }
     }
     
    3. and ow can i teleport players to randomly positions?
    4. how can i give random topic in the title?
     
  2. Bavfalcon9

    Bavfalcon9 Creeper

    Messages:
    2
    GitHub:
    olybear9
    First off, it's very bad habit to use while loops while on the main thread, as it freezes it. Secondly you need to call your time property with $this->time in your second method on_rest_time(). Lastly, I would use a task instead of what you're doing, I would use a scheduled repeating task, which you can read about here: https://jenkins.pmmp.io/job/PocketM...cketmine_1_1scheduler_1_1_task_scheduler.html. So basically, no what you're doing doesn't look like it would work at all, a possible solution to this would be:
    PHP:
    class MyTask extends \pocketmine\scheduler\Task {
        
    /** @var BuildBattle */
        
    private $plugin;
        
    /** @var int */
        
    private $time 15;

        public function 
    __construct(BuildBattle $plugin) {
            
    $this->plugin $plugin;
        }

        public function 
    onRun(int $tick) {
            
    $this->time--;

            if (
    $this->time <= 0) {
                
    $this->plugin->getLogger()->info('Game time ended!');
                
    $this->plugin->task->remove();
            }
        }
    }

    class 
    BuildBattle extends PluginBase {

        
    /** @var MyTask */
        
    public $task;

        public function 
    onEnable(): void {
            
    $this->task = new MyTask($this);
            
    $this->task $this->getScheduler()->scheduleRepeatingTask($this->task20);
        }

        public function 
    onDisable(): void {
            if (
    $this->task) {
                
    // remove the task.
                
    $this->task->remove();
            }
        }
    }
     
    Last edited: Mar 3, 2020
  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.