Advertisement
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Countdowns and Players

Comments in 'Plugin Development' started by SuperChipsLP, Oct 10, 2013.

  1. SuperChipsLP
    Offline

    SuperChipsLP Active Member Plugin Developer

    Joined:
    Sep 15, 2013
    Posts:
    204
    Plugins:
    5
    Minecraft User:
    Redmol
    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!
  2. sekjun9878
    Offline

    sekjun9878 Staff Member PocketMine Team

    Joined:
    Aug 22, 2013
    Posts:
    108
    Plugins:
    1
    Minecraft User:
    sekjun9878
    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.
  3. VanishedKevin
    Offline

    VanishedKevin Banned

    Joined:
    Aug 27, 2013
    Posts:
    279
    Minecraft User:
    VanishedKevin
    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. :p
  4. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    Yes you can remove it with:
    $server->query("DELETE FROM actions WHERE ID = ".$id.";");
  5. VanishedKevin
    Offline

    VanishedKevin Banned

    Joined:
    Aug 27, 2013
    Posts:
    279
    Minecraft User:
    VanishedKevin
    But I think I also need to remove the schedule from the array in the code.
  6. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    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
  7. VanishedKevin
    Offline

    VanishedKevin Banned

    Joined:
    Aug 27, 2013
    Posts:
    279
    Minecraft User:
    VanishedKevin
    I saw $this->api->schedule() returns the ID in Array, I mean I may need to do unset().
  8. wies
    Offline

    wies Notable Member

    Joined:
    Aug 23, 2013
    Posts:
    390
    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
  9. VanishedKevin
    Offline

    VanishedKevin Banned

    Joined:
    Aug 27, 2013
    Posts:
    279
    Minecraft User:
    VanishedKevin
    Lol, SQL thingy. :p

Share This Page

Advertisement