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

Help with timer plugin

Comments in 'Plugin Development' started by xpyctum, Jun 9, 2014.

  1. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    It is not work, but i don't know where error

    PHP:

    <?php

    /*
    __PocketMine Plugin__
    name=Timer
    description=timer
    version=1.0
    author=xpyctum
    class=timer
    apiversion=12
    */

    class timer implements Plugin {
        private 
    $api;
     
        public function 
    __construct(ServerAPI $api$server false) {
            
    $this->api $api;
        }
     
        public function 
    init() {

         
    $timer 60;
         
    $tcheck false;
          
    $this->interval 20;
            
    $this->api->schedule($this->interval, array($this"handle"), array(), true"server.schedule");
            
    $this->api->console->register("timer""Reload update onlinesign.", array($this"timer")); 
        }
        public function 
    handler($args,$issuer,$cmd$params$alias){
               if(
    $tcheck true){
                         
    $timer--;
                         if(
    $timer 60){
                         
    $this->api->chat->broadcast("60");
                         break;
                         }
                         if(
    $timer 40){
                         
    $this->api->chat->broadcast("40");
                         break;
                         }
                       
               }
        }
        public function 
    timer($cmd$params$alias){
         
    $tcheck true;
        }
        public function 
    __destruct(){
        }
    }
    ?>
  2. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    An error is that you must use "===" or "==" to check if two values are equal.
    xpyctum likes this.
  3. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Okay, i'm try this
  4. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Write this. No errors, but if i use /timer . server do nothing
    PHP:

    <?php

    /*
    __PocketMine Plugin__
    name=Timer
    description=timer
    version=1.0
    author=xpyctum
    class=timer
    apiversion=12
    */

    class timer implements Plugin {
        private 
    $api;
       
        public function 
    __construct(ServerAPI $api$server false) {
            
    $this->api $api;
        }
       
        public function 
    init() {
           
    $this -> path $this -> api -> plugin -> configPath($this);
            
    $this -> Commands = new Config($this -> path "config.yml"CONFIG_YAML, array(
            
    "timer" => 60,
            
    "tcheck" => false
            
    ));
            
    $this->config $this->api->plugin->readYAML($this->path."config.yml");

          
    $timer $this->config['timer'];
         
    $tcheck $this->config['tcheck'];
          
    $this->interval 20;
            
    $this->api->schedule(20, array($this"handler"), array(), true);;
                
    $this->api->console->register("timer""timer", array($this"timer"));
        }
        public function 
    handler(){
        
    $timer $this->config['timer'];
         
    $tcheck $this->config['tcheck'];
               if(
    $this->config['tcheck'] = true){
                         
    $timer--;
                         if(
    $timer === 60){ 
                         
    $this->api->chat->broadcast("60");
                         return 
    false;
                         }
                         if(
    $timer === 40){
                         
    $this->api->chat->broadcast("40");
                         return 
    false;
                         }
                         
               }
        }
        public function 
    timer($cmd$params$alias){
        
    $tcheckt true;
        
    $this->config['tcheck'] = true;
             
    $this->api->plugin->writeYAML($this->path."config.yml"$this->config);
        }
        public function 
    __destruct(){
        }
    }

  5. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Don't use new Config() then readYAML for the same file. This is just a lazy but resource-consuming (well, it spends the server 0.xxxxxxxxxxx to startup) way to initialize. Also, what is the use for defining $timer and $tcheck in init()?
  6. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Also, only use config if you want to save data into files. In the above code, you didn't anyway.

    As I see, the usage above is not suitable for using a Config to save data. So, instead of:
    PHP:
    $this -> Commands = new Config($this -> path "config.yml"CONFIG_YAML, array(
            
    "timer" => 60,
            
    "tcheck" => false
            
    ));
            
    $this->config $this->api->plugin->readYAML($this->path."config.yml");
    use:
    PHP:
            $this->config = array(
            
    "timer" => 60,
            
    "tcheck" => false
            
    );
    Moreover, $this->Commands isn't needed.
    Also, note that spaces and line breaks can be added/removed as long as you like it, as long as it doesn't:
    * affect the line comments
    * split a word/number into two
    * combine two words/numbers into one
    xpyctum and Lambo like this.
  7. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,325
    Plugins:
    11
    Minecraft User:
    PEMapModder
    Also congratulations, you have solved all the problems I have met in the first week of my coding experience in javascript.
  8. Killman2
    Offline

    Killman2 Active Member Plugin Developer

    Joined:
    May 5, 2014
    Posts:
    81
    Plugins:
    1
    Minecraft User:
    Killman2
    Не оч, не сработает.
  9. xpyctum
    Offline

    xpyctum Active Member Plugin Developer

    Joined:
    Jan 13, 2014
    Posts:
    292
    Plugins:
    4
    Minecraft User:
    tylerdisney
    Да. Уже знаю
    Я уже сделал

Share This Page

Advertisement