Hey there! I am currently developing a Survival Games Plugin. Everything works fine, but when i try to make a Countdown like: 10 9 8 7 ... I did the code like this: $this->api->chat->broadcast("10"); sleep(1); $this->api->chat->broadcast("9"); sleep(1); and so on. But when i test it ingame it says "Starting Game..." and waits for ten seconds. Then it posts erverthing at the same time. Everything else is working! Also, i have got another question. I already have a "spawn" listener. This listens for when a player spawns, right? How can i get the name of the person who spawned? I hope some of you can help me with my problems! Thanks!
You cannot use sleep() in PocketMine. If you use sleep(), you will put the whole PocketMine to hibernate. And because PM uses an event system, the broadcast doesn't happen right away, it just puts the broadcast in a queue. Which is why you get 10 seconds of sleep, and the queue flushes. I suggest you have a look at $this->api->schedule() function.
He also needs to make a public variable to store the number. I suggest PocketMine Team to make a schedule remove API or I made it by myself.
It should work fine, but the only problem is the id. You can't use the traditional $this->api->schedule() because you can't get the id then. you need to insert it in the actions table from the database manualy
Oh the schedule function returns the id. so it's easy: PHP: $id = $this->api->schedule(); // to make a scheduled task$server->query("DELETE FROM actions WHERE ID = ".$id.";"); // to remove it