PHP: private $time = 4; public function __construct(Plugin $owner) { parent::__construct($owner); } public function onRun(int $currentTick) { $this->time--;foreach($this->getOwner()->getServer()->getOnlinePlayers() as $player){$player->sendMessage("This is when going 3 ticks");} if($this->time == 1){## change ticks to 5? it was 3 btw }} main PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(new MyTask, 3);
I'm not sure what you asked, maybe explain better. If you want to change the task period you can't, once you schedule the task that's how it stays unless you cancel it and schedule a new one with higher ticks.
How do others does it? The archon crates spinning goes fast first and then slower and slower until stopped
Set the task delay to 1 tick and internally delay the task more after a certain amount of ticks. PHP: $this->time++;if($currentTick < $this->delay){ return;}if($this->time < 100){ $this->delay = 3 + $currentTick;}elseif(time < 200){ $this->delay = 10 + $currentTick;}//do stuff
because it wont work PHP: if ($this->time < 50) { $this->delay = 20 + $currentTick; Crate::$player->sendMessage("20 tick"); $rand = Main::getInstance()->crates->get("Items"); $random1 = explode(":", $rand[mt_rand(0, count($rand) - 2)]); $randomAmount = mt_rand(1, $random[2]); $menu = InvMenu::create(InvMenu::TYPE_CHEST); $menu->getInventory()->setContents([ Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), ]); $menu->readonly(); $menu->send($player); } elseif ($this->time < 100) { $this->delay = 100 + $currentTick; Crater::$player->sendMessage("100 tick"); $rand = Main::getInstance()->crates->get("Items"); $random1 = explode(":", $rand[mt_rand(0, count($rand) - 2)]); $menu = InvMenu::create(InvMenu::TYPE_CHEST); $menu->getInventory()->setContents([ Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), ]); $menu->readonly(); $menu->send($player); }
I mean like PHP: /** @var int */private $delay = 0;public function onRun(int $currentTick){ $this->time++; if($currentTick < $this->delay){ return; } if($this->time < 100){ $this->delay = 3 + $currentTick; }elseif(time < 200){ $this->delay = 10 + $currentTick; } //set item in chest HERE. //you're supposed to execute the code here //the code above is solely to handle the delaying} Spoiler: Performance improvements It'll be more performant if you create one InvMenu instance and use it throughout. PHP: /** @var InvMenu */private $menu;public function __construct(){ $this->menu = InvMenu::create(InvMenu::TYPE_CHEST); $this->menu->readonly();} About these PHP: $menu->getInventory()->setContents([ Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), Item::get($random1[0], $random1[1], $random1[2]), ]); You could use array_fill() to make your code look better. PHP: $this->menu->getInventory()->setContents( array_fill(0, 6, Item::get($random1[0], $random1[1], $random1[2]))//6 copies of Item, array indexed from 0);