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

I got a question about the scheduleDelayedTask !

Comments in 'Plugin Development' started by PlayCubePE, Mar 22, 2015.

  1. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    What you'll see will burn your eyes because this is bad engliiiiiish ! (Cause i'm french)



    I have With the scheduleDelayedTask
    How i'm supposed to use it ???
    I want to make a thing that 30 seconds after schedule start "" things happened !

    Heres a exemple of what i want to do (because i don't know how Schedule works for the new API) : (Numbers = Order that happened)

    1 -> 30seconds

    0/1 seconds -> Send a message ("[Insert game name] Match start in 30 seconds.");
    15th seconds -> Send a message ("[Insert game name] Match start in 15 seconds.");
    20th seconds -> Send a message ("[Insert game name] Match start in 10 seconds.");
    21st seconds -> Send a message ("[Insert game name] Match start in 9 seconds.");
    22nd seconds -> Send a message ("[Insert game name] Match start in 8 seconds.");
    23rd seconds -> Send a message ("[Insert game name] Match start in 7 seconds.");
    24th seconds -> Send a message ("[Insert game name] Match start in 6 seconds.");
    25th seconds -> Send a message ("[Insert game name] Match start in 5 seconds.");
    26th seconds -> Send a message ("[Insert game name] Match start in 4 seconds.");
    27th seconds -> Send a message ("[Insert game name] Match start in 3 seconds.");
    28th seconds -> Send a message ("[Insert game name] Match start in 2 seconds.");
    29th seconds -> Send a message ("[Insert game name] Match start in 1 seconds.");
    30th seconds -> Send a message ("[Insert game name] Match has started !");
    30th seconds -> $this->matchstarted = true;

    Then for the rest i already done it !
    So, thanks you if you can help me!
    Falk likes this.
  2. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    Oh god, thank you man ! PocketMine Community is really helpful !
    But the file ; i can name it like i want?
    And how the main plugin will read it the second class (timer)
  3. Falk
    Offline

    Falk Staff Member Global Moderator

    Joined:
    Sep 2, 2013
    Posts:
    1,707
    Plugins:
    22
    Minecraft User:
    Falkirknh
    The second class should be named Timer.php and it should be in the same namespace as the main class (same folder and same namespace at the top).
  4. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    No nothing thanks you for helping
  5. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    Ok i'll see if it works !
  6. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    I got two questions for you and others :

    - After the 30 seconds (600 ticks) how to stop the timer ?

    -And if for 10 seconds i want than nothing happen ? How did i do ?
  7. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    Does it works if do this

    PHP:
    public function onRun($tick)
    if (
    $tick 0) {
    $this->getServer()->broadcastMessage("Match will start in 30 seconds !");
    } else {
    return 
    false;
    }
    }
  8. PlayCubePE
    Offline

    PlayCubePE New Member

    Joined:
    Mar 19, 2015
    Posts:
    29
    Minecraft User:
    PlayCubePE
    Ok thanks you, i think i don't need more help anymore thanks you luca28pet again again and again !
    You are really helpful !
  9. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    my Main code:
    PHP:
    public function onEnable() {
                
    $time 1;
                
    $this->taskId $this->getServer()->getScheduler()->scheduleRepeatingTask(new Timer($this), $time)->getTaskId();
            
    $this->initConfigFile ();            
            
    $this->enabled true;
            
    $this->getServer ()->getPluginManager ()->registerEvents ( new CTFListener $this ), $this );
            
    $this->getLogger ()->info (TextFormat::RED."Bed".TextFormat::WHITE."wars"." ".TextFormat::GREEN."Enabled");
            
    $this->getLogger ()->info (TextFormat::GREEN "-------------------------------------------------" );
            
    $this->initMessageTests();
        
            
    //check if everything initializared
            
    if ($this->ctfManager==null) {
                
    $this->getLogger()->info(" manager not initialized properly");
            }    
            if (
    $this->ctfSetup==null) {
                
    $this->getLogger()->info(" setup not initialized properly");
            }
            if (
    $this->ctfMessages==null) {
                
    $this->getLogger()->info(" messages not initialized properly");
            }
            if (
    $this->ctfBuilder==null) {
                
    $this->getLogger()->info(" builder not initialized properly");
            }
            if (
    $this->ctfGameKit==null) {
                
    $this->getLogger()->info(" gamekit not initialized properly");
            }
        }
    my Timer.php code:
    PHP:
    <?php

    namespace mcg76\game\ctf;

    use 
    pocketmine\scheduler\PluginTask;

    class 
    Timer extends PluginTask{

        public function 
    __construct(CTFPlugIn $plugin){
        
    $this->plugin $plugin;
        
    parent::__construct($plugin);
      }
        
      public function 
    onRun($tick){
          
    $inGamePlayers array_merge($this->getPlugIn()->blueTeamPlayers$this->getPlugIn()->redTeamPlayers$this->getPlugIn()->yellowTeamPlayers$this->getPlugIn()->greenTeamPlayers);
          
    $cas0 0;
          
    $cas1 0;
        if(
    $this->getPlugIn()->inGame == 1){
            
    $cas0++;
            
    $cas1++;
            if(
    $cas1 == 10){
                foreach(
    $inGamePlayers as $p){
                    
    $p->sendPopup(TextFormat::BLUE."TEST");
                }
            }
            if(
    $cas1 == 20){        
                
    $this->getBuilder()->dropBrickItems($this->getPlugIn()->bwLevel);
                foreach(
    $inGamePlayers as $p){
                    
    $p->sendPopup(TextFormat::BLUE."TEST");
                }
                
    $cas1 0;
            }
        
            if (
    $cas0 == 600){
                
    $this->getBuilder()->dropIronItems($this->getPlugIn()->bwLevel);
            }
        
            if (
    $cas0 == 1200){
                
    $this->getBuilder()->dropGoldItems($this->getPlugIn()->bwLevel);
                
    $cas 0;
            }
        
        }
      }

    }

    error message:
    Fatal error: Call to undefined method mcg76\game\ctf\Timer::getPlugIn() in C:\Users\Honza\Documents\PocketMine-MP\plugins\BedwarsPE\src\mcg76\game\ctf\Timer.php on line 15

    Call Stack:
    0.0275 368336 1. {main}() C:\Users\Honza\Documents\PocketMine-MP\PocketMine-MP.phar:0
    0.0322 363344 2. require('phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php') C:\Users\Honza\Documents\PocketMine-MP\PocketMine-MP.phar:1
    0.4299 498904 3. pocketmine\Server->__construct() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/PocketMine.php:463
    7.1513 14314192 4. pocketmine\Server->start() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:1748
    7.1680 14340768 5. pocketmine\Server->tickProcessor() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2070
    7.1680 14341160 6. pocketmine\Server->tick() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2188
    7.1682 14342024 7. pocketmine\scheduler\ServerScheduler->mainThreadHeartbeat() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/Server.php:2392
    7.1683 14341928 8. pocketmine\scheduler\TaskHandler->run() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/scheduler/ServerScheduler.php:247
    7.1683 14342072 9. mcg76\game\ctf\Timer->onRun() phar://C:/Users/Honza/Documents/PocketMine-MP/PocketMine-MP.phar/src/pocketmine/scheduler/TaskHandler.php:150

    so please what can i do? :(
  10. Anton Magsino
    Offline

    Anton Magsino Active Member

    Joined:
    Jan 17, 2014
    Posts:
    58
    Minecraft User:
    MinecrafterPH
    That's not your code.
  11. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    I know but i have permission to use it. so can you help me please?
  12. Creeperface
    Offline

    Creeperface Notable Member Plugin Developer

    Joined:
    Nov 8, 2014
    Posts:
    1,346
    Plugins:
    4
    Minecraft User:
    CreeperFace
    i need something like extend from more classes, so i created instance of the second class in class Timer but it doesn´t work :/

    15:57:57 [NOTICE] InvalidArgumentException: "Argument 1 passed to mcg76\game\ctf\MiniGameBase::__construct() must be an instance of mcg76\game\ctf\CTFPlugIn, none given, called in C:\Users\Honza\Documents\PocketMine-MP\plugins\BedwarsPE\src\mcg76\game\ctf\Timer.php on line 13 and defined" (E_RECOVERABLE_ERROR) in "/BedwarsPE/src/mcg76/game/ctf/MiniGameBase" at line 17

    line 17 in minigamebase:
    PHP:
    public function __construct(CTFPlugIn $plugin) {
  13. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,306
    Plugins:
    11
    Minecraft User:
    PEMapModder
    @Creeperface please create another thread. We are not taking about mcg76 here. And yes, they break because mcg76 sucks, and that's because he makes money from plugin development.
    applqpak, KubixQ and PocketKiller like this.

Share This Page

Advertisement