currently trying to create a koth plugin. I'm using player move event and getting their vectors, but I need a way as to go round the tasks... The player walks into Koth. Task scheduled. Player walks out, task cancelled. Any help? Confused as to what I'm supposed to do.
So what are you asking here? Asking how to design your plugin in terms what to use etc. Or are you asking how to code/actually implement task scheduling and cancelling?
Well, since the task is scheduled like such. 2 players, of the same team walk into Koth. Task is scheduled, if at least one of them stay in that region for 30 seconds the Koth is won and code is executed. So, how would I go about this?
code wise? So basically, for that you don't need to use a Repeating task and cancel it. Just check if they're still in the area after 30 secs. let's get some pieces of code here then: PHP: /** @var \pocketmine\scheduler\ServerScheduler */$serverScheduler;/** @var \pocketmine\Player */$player1;/** @var \pocketmine\Player */$player2;//You obviously want a delayedTask not a repeating one.$serverScheduler->scheduleDelayedTask(new CaptureSequence($this, $player1, $player2), 20*30);class CaptureSequence extends \pocketmine\scheduler\PluginTask{ /** @var \pocketmine\Player */ private $player1; /** @var \pocketmine\Player */ private $player2; /** @var \pocketmine\Server */ private $server; /** @var YourPluginMainClass */ private $main; public function __construct(YourPluginMainClass $main, \pocketmine\Player $player1, \pocketmine\Player $player2){ parent::__construct($main); $this->main = $main; $this->server = $main->getServer(); $this->player1 = $player1; $this->player2 = $player2; } public function onRun($currentTick){ if(/* $player1 and $player2 are still in region */){ //I assume you already have your region checking code $main->onWin($player1, $player2); //Your win code } }}
i dont think that will work well since i could gone off and gone back in 30 seconds, there would be 1 task repeating task ticks every 2 or 1 tick the repeated task would check for players inside the region and if they are new set their time to current time, if there's a player that's not in the region while having time setted, unset it, you could also unset all if there's opposing teams inside the region or just declare winner if the current time - past time over the needed time