Hello, I could use some help figuring out how a timer would work for pocketmine, I know of time commander but that expands what I want to do, Could anyone supply me with a few lines of code,
Add this to your main: PHP: $this->getServer()->getScheduler()->scheduleRepeatingTask(new TaskName($this, $player), 20); This will create a task that will run every second. Then create a new file and call it TaskName And add this to the the file: PHP: <?phpnamespace yournamespace;use pocketmine\scheduler\PluginTask;class TaskName extends PluginTask { public function __construct($plugin, $player) { parent::__construct($plugin) ; } public function onRun($tick) { //Code here} Hope it helps Don't screw up the namespaces!
Is it possible to freeze player movement for a certain time limit,if so could anyone please help me with this
In your main declare two public variables: PHP: public $time = 0;public $canmove = true; Now add this code in the player move event: PHP: public function onMove(PlayerMoveEvent, $event){ if($this->canmove === false){ $event->setCancelled(); }} Now in your task in the //Code here section, add this: PHP: $this->plugin = $this->getOwner();if($this->plugin->time > 59){ $this->plugin->canmove = true;}else{ $this->plugin->canmove = false; $this->plugin->time++;} This will disable the players movement until a minute is up. This gives you an idea of turning things off and on using Booleans (true and false). Hope this helps!
How do u cancel the time ? https://forums.pocketmine.net/threa...er-function-cancel-on-null.10090/#post-103509
Why count it yourself? Just save the start freeze time with time(), and if time() - $savedStartTime < $timeout, cancel event.