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

TextParticle help

Discussion in 'Development' started by AbelGamerC, Mar 8, 2018.

  1. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    How to create FloatingTextParticle with multiline content? This is my code but not work.
    <?php

    namespace topkills\events;

    use pocketmine\math\Vector3;
    use pocketmine\level\particle\FloatingTextParticle;
    use pocketmine\scheduler\PluginTask;
    use topkills\EventListener;
    use pocketmine\utils\TextFormat;

    class ParticleTask extends PluginTask{

    private $plugin;
    private $text;

    public function __construct(EventListener $plugin)
    {
    $this->plugin = $plugin;
    parent::__construct($plugin);
    $this->text = new FloatingTextParticle(new Vector3(8, 15, -15), "", "§eTop Killers");
    }

    public function onRun($currentTick)
    {
    $data = $this->plugin->getTopList();
    $i = 1;
    foreach ($data as $player => $points) {
    $level = $this->plugin->getServer()->getLevelByName("world");
    $this->text->
    $this->text->setText(TextFormat::GREEN . "[" . $i . "] " . TextFormat::YELLOW . ucfirst($player) . " : " . TextFormat::RED . TextFormat::BOLD . $points);
    $i++;
    $level->addParticle($this->text);
    }
    }
     
  2. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    Plssss I need help.
     
    Last edited: Mar 8, 2018
  3. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
  4. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    PHP_EOL ?
    PHP:
    $text  "First line" PHP_EOL "Second line";
     
    armagadon159753 likes this.
  5. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    But how add that to my code?
     
  6. armagadon159753

    armagadon159753 Zombie

    Messages:
    217
    GitHub:
    armagadon159753
    We can use too
    PHP:
    $text  "First line" "\n" "Second line";
    $text  "First line\nSecond line";
     
  7. AbelGamerC

    AbelGamerC Spider Jockey

    Messages:
    29
    GitHub:
    abelgamerc
    This is my code
    PHP:
    <?php

    namespace topkills\events;

    use 
    pocketmine\math\Vector3;
    use 
    pocketmine\level\particle\FloatingTextParticle;
    use 
    pocketmine\scheduler\PluginTask;
    use 
    topkills\EventListener;
    use 
    pocketmine\utils\TextFormat;

    class 
    ParticleTask extends PluginTask{

    private 
    $plugin;
    private 
    $text;

    public function 
    __construct(EventListener $plugin)
    {
    $this->plugin $plugin;
    parent::__construct($plugin);
    $this->text = new FloatingTextParticle(new Vector3(815, -15), """§eTop Killers");
    }

    public function 
    onRun($currentTick)
    {
    $data $this->plugin->getTopList();
    $i 1;
    foreach (
    $data as $player => $points) {
    $level $this->plugin->getServer()->getLevelByName("world"); 
    $this->text->setText(TextFormat::GREEN "[" $i "] " TextFormat::YELLOW ucfirst($player) . " : " TextFormat::RED TextFormat::BOLD $points);
    $i++;
    $level->addParticle($this->text);
    }
    }
    [
     
  8. di2134876

    di2134876 Spider Jockey

    Messages:
    29
    GitHub:
    dk1234987
    PHP:
    $this->text->setText(TextFormat::GREEN "[" $i "] " TextFormat::YELLOW ucfirst($player) . " : " TextFormat::RED TextFormat::BOLD $points "\n");
     
  9. SleepSpace9

    SleepSpace9 Slime

    Messages:
    78
    GitHub:
    sleepspace9
    This would create a new particle for every line. Better append the lines and move $level->addParticle() out of the loop.
     
    iCirgio likes this.
  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.