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

How can i create and delete a floating text at tick delay?

Discussion in 'Development' started by Ayush, Jun 17, 2021.

  1. Ayush

    Ayush Witch

    Messages:
    62
    I need in help with floating text !
    I am making a plugin in which when you hit a entity ir player it shows a floating text damage on it . So, I need to have it removed within 2 seconds . How can i do it anyone can help ! If you can can not then thanks for seeing this!
     
  2. Ayush

    Ayush Witch

    Messages:
    62
  3. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    PHP:
    $second 20;
    $this->plugin->getScheduler()->scheduleDelayedTask(new ClosureTask(function (int $currentTick) use ($sender) : void {
    // CODE
    }), $second);
    This code will execute whatever you put in // CODE after x amount of ticks
     
    Ayush likes this.
  4. Taco

    Taco Spider Jockey

    Messages:
    41
    GitHub:
    taconoburrito
    so you want something like when you hit a player, it displays the damage in a little text, floats up, and dissapears?
     
  5. Taco

    Taco Spider Jockey

    Messages:
    41
    GitHub:
    taconoburrito
  6. BestCodrEcer

    BestCodrEcer Spider

    Messages:
    11
    GitHub:
    bestcodrever
    Breh
    There are better people than me out there
     
  7. Ayush

    Ayush Witch

    Messages:
    62
  8. Ayush

    Ayush Witch

    Messages:
    62
    But doesn't float up
     
  9. Ayush

    Ayush Witch

    Messages:
    62
    Like this?
    PHP:
         $position = new Position($entity->getPosition());
         
    $fd = new FloatingTextParticle($position"""§r§c" $text);
         
    $position->level->addParticle($fd);
        
         
    $task $this->getScheduler()->scheduleRepeatingTask(new ClosureTask(function() use ($a) : void{
             
    $fd->setInvisible(true);
          
    //Line 111   $position->level->addParticle($fd);
                
    }), 20 2);
                
         if(
    $event->isCancelled()){
             return 
    true;
            }
    When I try like this it show
    Error: "Undefined Variable: '$position' on line 111"
     
  10. Ayush

    Ayush Witch

    Messages:
    62
  11. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
  12. Taco

    Taco Spider Jockey

    Messages:
    41
    GitHub:
    taconoburrito
    minjahams plugin will work fine. It just doesnt move up like mine does in the video. if you want help making a plugin like i did my discord is Taco!#1305 i can walk you through it
     
    Ayush likes this.
  13. xXNiceAssassinlo YT

    xXNiceAssassinlo YT Zombie Pigman

    Messages:
    499
    GitHub:
    xXNiceYT
    replace ur use($a) with use($position, $fd) that should fix it and add $a if you need it from the looks of it, you don’t need it rn
     
    Ayush likes this.
  14. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    try $position = $entity->getPosition();
    $fd = new FloatingTextParticle($position, "", "§r§c" . $text);
    $position->level->addParticle($fd);

    $task = $this->getScheduler()->scheduleRepeatingTask(new ClosureTask(function() use ($a) : void{
    $fd->setInvisible(true);
    //Line 111 $position->level->addParticle($fd);
    }), 20 * 2);

    if($event->isCancelled()){
    return true;
    }
     
  15. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    That's the same thing from what Ayush said?
    First of all, the task wouldn't work because you need to use the var $fd and $position like NiceAssassin said.
    Second, I don't see the point of the return true in the check at the end. It doesn't even do anything.
     
  16. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    I changed $position bruh
     
  17. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    They both will return the position. What's the point?
     
  18. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    the previous code is missing the ;
     
  19. Superomarking

    Superomarking Spider Jockey

    Messages:
    34
    GitHub:
    Superomarking
    previous Code of $position not $position it self
     
  20. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    I don't see a missing semicolon
     
    Agent and Axon like 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.