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

\n not working in FloatingTextParticle

Discussion in 'Development' started by Besher, Jun 16, 2021.

  1. Besher

    Besher Witch

    Messages:
    51
    Iam getting the text from a database and then setting it as floating text CODE BELOW:

    PHP:
    public function loadFloatingText()
        {
            foreach (
    $this->getCrates() as $crate){
                
    $loc $this->getLocation($crate);
                
    $level $this->plugin->getServer()->getLevelByName("stop");
                
    $this->plugin->getServer()->loadLevel("stop");
                
    $x $loc["{$crate}x"] + 0.5//+ to center to block
                
    $y $loc["{$crate}y"] + 1//+ to center to block
                
    $z $loc["{$crate}z"] + 0.5//+ to center to block
                
    $display $this->getDisplay($crate); //Display name
                
    $hologram $this->getHologram($crate); //ex. "Right click to open crate\nLeft click to preview rewards"
                
    $level->addParticle(new FloatingTextParticle(new Vector3($x$y$z), $hologram$display));
            }
        }
    PHP:
    public function getHologram(string $crate) : string
        
    {
            
    $array $this->crate->query("SELECT hologram FROM crates WHERE crate = '$crate';");
            
    $result $array->fetchArray(SQLITE3_ASSOC);
            return (string)
    $result['hologram'] ?? "Test";
        }
    crateBug.PNG
     
  2. Taco

    Taco Spider Jockey

    Messages:
    41
    GitHub:
    taconoburrito
    import: pocketmine\utils\TextFormat;

    $hologram = str_replace("\n", TextFormat::EOL, $hologram);
     
  3. Besher

    Besher Witch

    Messages:
    51
    That didnt work but this did

    PHP:
    public function loadFloatingText()
        {
            foreach (
    $this->getCrates() as $crate){
                
    $loc $this->getLocation($crate);
                
    $level $this->plugin->getServer()->getLevelByName("stop");
                
    $this->plugin->getServer()->loadLevel("stop");
                
    $x $loc["{$crate}x"] + 0.5//+ to center to block
                
    $y $loc["{$crate}y"] + 1//+ to center to block
                
    $z $loc["{$crate}z"] + 0.5//+ to center to block
                
    $display $this->getDisplay($crate); //Display name
                
    $hologram $this->getHologram($crate); //ex. "Right click to open crate\nLeft click to preview rewards"
                
    $level->addParticle(new FloatingTextParticle(new Vector3($x$y$z), str_replace("{line}"TextFormat::EOL$hologram), $display));
            }
        }
    thank you for the help!
     
  4. Taco

    Taco Spider Jockey

    Messages:
    41
    GitHub:
    taconoburrito
    ig that works too
     
  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.