hi! Is there any way someone can send me a code for when the player put a stone start a task, and in that task dps of 5 seconds the block turns cobblestone and after +5 seconds it disappears? Please I'm new to pocketmine and php, so i study taking examples...
Welcome to php! PHP: // Main.php<?phpnamespace test;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\Player;class test extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function blockplace(BlockPlaceEvent $event) { if(($event->getBlock()->getId() == 1) && ($event->getBlock()->getDamage() == 0)) { $this->getScheduler()->scheduleDelayedTask(new MyTask($this, $event, 1, 0), 100); } }}// MyTask.php<?phpnamespace test;use pocketmine\scheduler\Task;use pocketmine\math\Vector3;class TaskMotd extends Task { private $plugin; private $event; private $id; private $meta; public function __construct(Main $plugin, $event, $id, $meta){ $this->plugin = $plugin; $this->event = $event; $this->id = $id; $this->meta = $meta; } public function onRun($tick){ $event = $this->event; $block = $event->getPlayer(); $block = $event->getBlock(); $level = $block->getLevel(); $pos = [$block->getX(), $block->getY(), $block->getZ()]; $id = $this->id; $meta = $this->meta; $plugin = $this->plugin; $level->setBlock(new Vector3($pos[0], $pos[1], $pos[2]), new Block($id, $meta)); $player->sendMessage("Block changed !?"); if($id == 1) { $plugin->getScheduler()->scheduleDelayedTask(new self::($this, $event, 0, 0), 100); } } public function getPlugin(){ return $this->plugin; }}
PHP: <?phpdeclare(strict_types=1);namespace me\project;use pocketmine\block\Block;use pocketmine\block\BlockIds;use pocketmine\event\block\BlockPlaceEvent;use pocketmine\event\Listener;use pocketmine\plugin\PluginBase;use pocketmine\scheduler\ClosureTask;/** * Class test * @package me\project */class test extends PluginBase implements Listener { public function onEnable() { $this->getServer()->getPluginManager()->registerEvents($this, $this); } public function onBlockPlace(BlockPlaceEvent $event) { $block = $event->getBlock(); if($block->getId() == BlockIds::STONE and $block->getDamage() == 0) { // Without damage check, it would work with for example andesite too $this->getScheduler()->scheduleDelayedTask(new ClosureTask(function (int $currentTick) use ($block): void { $block->getLevel()->setBlock($block, Block::get(BlockIds::COBBLESTONE)); }), 5 * 20); // It should be in ticks, 20 ticks = 1 second $this->getScheduler()->scheduleDelayedTask(new ClosureTask(function (int $currentTick) use ($block): void { $block->getLevel()->setBlock($block, Block::get(BlockIds::AIR)); }), 10 * 20); } }} Another way to solve your task