No, use time() function in PHP. Then learn the API, I'm not trying to be mean but this is for help with plugin bugs or issues and question about the API, not help with learning the API.
You can see the basics of creating a task here. You obviously have some knowledge of programming or you would be in the plugin request section so have a go at making that example work for a delayed task. Spoiler: Hint PHP: pocketmine\Server::getScheduler()->scheduleDelayedTask(20 /* time in ticks to be delayed */, PluginTask /* Your pocketmine\scheduler\PluginTask instance */);
I have code but I get an error, PHP: <?phpnamespace Core;use pocketmine\Player;use pocketmine\plugin\PluginBase;use pocketmine\utils\TextFormat as c;use pocketmine\Server;use pocketmine\event\Cancellable;use pocketmine\event\Listener;use pocketmine\event\block\BlockBreakEvent;use pocketmine\utils\Config;class Mining implements Listener { public function __construct(Loader $plugin){ $this->plugin = $plugin; } public function OnBreak(BlockBreakEvent $event){ ###VARIABLES### $name = $event->getPlayer(); $this->array = array(); $this->array[$name] = time(); ##$this->miningskills = new Config($this->getDataFolder() . "/miningskills.yml", Config::YAML); ##$inventory = $event->getPlayer()->getInventory(); FOR FUTURE USE! ##$breaks = $this->miningskills->get($name); ##$this->miningskills->set($name,$breaks+1); ##$this->miningskills->save(); $last_usage_time = $this->array[$name]; ###/VARIABLES### if(isset($this->array[$name])){ if((time() - $last_usage_time) <= 5){ if($event->getBlock()->GetId() == 1 or 2 or 3){ $event->getPlayer()->sendMessage("TEST"); }}else if((time() - $last_usage_time) >= 5){ $name->sendMessage("THIS SKILL IS CURRENTLY IN COOLDOWN!"); }}}} ERROR: illegal offset type in isset or empty
time() does not automatically call a function or execute code once a certain amount of time has passed, it simply returns a timestamp.
It's PHP: $name = $event->getPlayer()->getName(); The getPlayer() method returns a player object, not a string.
It works and sends the first message now except, if its lower then 5 seconds it doesnt trigger the message
Time is a function for retrieving a timestamp based on the machines Timezone configuration. If you want to store and compare a time value then you're better off using microtime() unless of course you plan on using the value to compare more than just hours, minutes and seconds.
PHP: // store the micro seconds timestamp in a variable or property$storedTime = microtime(true);// difference in seconds between the stored time and current time$differance = floor(microtime(true) - $storedTime);// compare the time difference to however many seconds you want the cooldown to lastif(!$differance >= 5) { echo "The cool down is still in progress";}
Microseconds is basically seconds*1 million. PHP: if((microtime(false) - $last_time_used) >= 1.8e+8){//your code here}