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!
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
so you want something like when you hit a player, it displays the damage in a little text, floats up, and dissapears?
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"
https://github.com/Flug-in-Fabrik/DamageTag/blob/master/src/SpaceLuis/Main.php Yeah, your welcome. This is PM3 btw. You will need to tweak some things to make it work with PM4
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
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
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; }
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.