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

Can i get player in task??

Discussion in 'Development' started by kaliiks, Jan 19, 2017.

  1. kaliiks

    kaliiks Zombie

    Messages:
    250
    I dont know if i cant, but i have one attempt
    <?php

    namespace Core;

    use pocketmine\scheduler\PluginTask;
    use Core\Core;
    use pocketmine\Player;
    use pocketmine\utils\TextFormat as C;

    class ParticleTask extends PluginTask
    {

    private $plugin;
    private $playergg = [];

    public function __construct(Core $plugin)
    {
    $this->plugin = $plugin;
    parent::__construct($plugin);
    }

    public function getPlayer(Player $p)
    {
    $this->playergg[$p->toString] = $p;
    }


    public function onRun($currentTick)
    {
    foreach ($this->playergg as $p) {
    $this->testPlayer($p);
    $this->plugin->getServer()->broadcastMessage("It work");
    }
    }
    }
    oops bad section
     
    Last edited: Jan 19, 2017
  2. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    to do that just server->getplayer(name)
     
  3. Thunder33345

    Thunder33345 Moderator Staff Member

    Messages:
    2,137
    GitHub:
    Thunder33345
    to do that just server->getplayer(name)
     
    Muqsit likes this.
  4. kaliiks

    kaliiks Zombie

    Messages:
    250
    Wtf i dont understand what is (name) how i define it??
    <?php

    namespace Core;

    use pocketmine\scheduler\PluginTask;
    use Core\Core;
    use pocketmine\Player;
    use pocketmine\utils\TextFormat as C;

    class ParticleTask extends PluginTask
    {

    private $plugin;
    private $playergg = [];

    public function __construct(Core $plugin)
    {
    $this->plugin = $plugin;
    parent::__construct($plugin);
    }

    public function getServer()
    {
    return $this->plugin->getServer();
    }

    public function onRun($currentTick)
    {
    $p2 = $this->getServer()->getPlayer();
    $name = $p->getName();
    $p = $this->getServer()->getPlayer($name);
    $this->testPlayer($p);
    }
    }
     
  5. Muqsit

    Muqsit Chicken

    Messages:
    1,548
    GitHub:
    muqsit
    #ReadTheDocs
     
  6. Sandertv

    Sandertv Zombie Pigman Poggit Reviewer

    Messages:
    786
    GitHub:
    Sandertv
    You can pass player objects onto the task when calling it.
     
    corytortoise likes this.
  7. jasonwynn10

    jasonwynn10 Moderator Poggit Reviewer

    Messages:
    1,489
    GitHub:
    jasonwynn10
    This post is in the wrong section. It should be in the development section.
     
  8. MioTaku

    MioTaku Witch

    Messages:
    69
    GitHub:
    uselesswaifu
    Here, Make sure to Define Player when Scheduling the task
    Code:
    <?php
    
    namespace Core;
    
    use pocketmine\scheduler\PluginTask;
    use Core\Core;
    use pocketmine\Player;
    use pocketmine\utils\TextFormat as C;
    
    class ParticleTask extends PluginTask
    {
    
    private $plugin;
    
    public function __construct(Core $plugin, $player)
    {
    $this->plugin = $plugin;
    $this->player = $player;
    parent::__construct($plugin);
    }
    
    
    
    
    public function onRun($currentTick)
    {
    //$this->testPlayer($p); IDK WHAT THIS IS SUPPOSE TO DO
    $this->player->sendMessage("Hi");
    $this->plugin->getServer()->broadcastMessage("It 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.