I want to use timer in my plugin. When I type command, it'll start 30s timer and after 30s "something" will happen. How do this?
I don't know what delayed task is... I want use this in my minigame -> i type command /start and it starts in 30 seconds
Create a plugin task (extends pocketmine\scheduler\PluginTask and schedule it with ServerScheduler->scheduleDelayedTask for 600 ticks. One tick = 1/20 second.
I need some example... so can anybody send here p.e. script: when you type command /msgtime it'll send you message "Message" in 30s after typing it.
To start the timer: PHP: $this->getServer()->getScheduler()->scheduleDelayedTask(new SendMessageTask($this, $player), 30*20); In SendMessageTask.php: PHP: <?phpnamespace your\name\space;use pocketmine\scheduler\PluginTask;class SendMessageTask extends PluginTask { private $player; public function __construct($plugin, $player) { parent::__construct($plugin) ; $this->player = $player; } public function onRun($t) { if($this->player->isOnline()) $this->player->sendMessage("Message") ;}
You could create a repeating task that repeats every second (20 ticks) when you run the command and use if statements or case's to check the time so you can do things like broadcast messages every so many seconds.