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

Help me with task

Discussion in 'Help' started by AbelGamerC, Jan 28, 2017.

  1. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    Hi, I have a doubt:
    How can I make a tip for each second, for example

    >> Example <<
    >> a§Example <<

    Sorry for my bad English
     
  2. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Schedule a repeating task which repeats every 20 ticks and sends all $players the $tip.
    PHP:
    $tip = [
        
    ">> Example <<",
        
    ">> a§Example <<"
    ];
    foreach (
    $players as $player)
        
    $player->sendTip(implode("\n"$tip));
     
  3. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    look,
    That in 1 second send this tip "Example"
    And in the second 2 send this tip "Example2"
    And let it be repeated
     
  4. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    Send your task class, that will help.
     
  5. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    PHP:
    <?php

    namespace HDA;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    class 
    Task extends PluginTask{

      public 
    $player;
      public 
    $plugin;
     
        public function 
    __construct(main $plugin) {
          
    $this->plugin $plugin;
          
    parent::__construct($plugin);
        }
       
        public function 
    onRun($tick){
          foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $p){
            
    $p->sendTip("§aYou are in Miners PE");
            
    $p->sendTip("§bYou are in Miners PE");
            
    $p->sendTip("§dYou are in Miners PE");
            
    $p->sendTip("§1You are in §bMiners PE");
          }
        }
    }
     
  6. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    PHP:
    public function onRun($tick){
      if(!isset(
    $this->num))
        
    $this->num 0;
      
    $msgs = ["§aYou are in Miners PE""§bYou are in Miners PE""§dYou are in Miners PE""§1You are in §bMiners PE"];
      if(
    $this->num >= count($msgs))
        
    $this->num 0;
      foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $p){
        
    $p->sendTip($msgs[$this->num]);
      }
      ++
    $this->num;
    }
    This should work
     
    Last edited: Jan 28, 2017
  7. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    [Server thread/CRITICAL]: ParseError: "syntax error, unexpected ',', expecting ']'" (EXCEPTION) in "/plugins/HudDeAbel/src/HDA/Task" at line 20
     
  8. HimbeersaftLP

    HimbeersaftLP Fish

    Messages:
    2,402
    GitHub:
    HimbeersaftLP
    Hmmm, updated my post, Try it again
     
  9. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    it does not work :/
     
  10. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    PHP:
    <?php

    namespace HDA;

    use 
    pocketmine\scheduler\PluginTask;
    use 
    pocketmine\Server;
    use 
    pocketmine\Player;

    class 
    Task extends PluginTask{

      private 
    $currMsg 0;
      const 
    MSGS = [
          
    "§aYou are in Miners PE",
          
    "§bYou are in Miners PE",
          
    "§dYou are in Miners PE",
          
    "§1You are in §bMiners PE",
      ]
      private 
    $plugin;

      public function 
    __construct(main $plugin) {
         
    $this->plugin $plugin;
         
    parent::__construct($plugin);
      }
       
      public function 
    onRun($tick){
         if(!isset(
    self::MSGS[$this->currMsg]){
             
    $this->currMsg 0;
         }
         
    $msg self::MSGS[$this->currMsg];
         foreach(
    $this->plugin->getServer()->getOnlinePlayers() as $p){
             
    $p->sendMessage($msg);
         }
         ++
    $this->currMsg;
      }
    }

    This should work
     
  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.