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

Send a message broadcast message, during hunger game?

Comments in 'Plugin Development' started by Dougle_1, Feb 28, 2014.

  1. Dougle_1
    Offline

    Dougle_1 Ban Evader

    Joined:
    Dec 12, 2013
    Posts:
    26
    Minecraft User:
    Dougle_1
    Hi All,

    I am hoping someone can help.

    I run a hunger game server using pocket hungergames by omattyao,.
    When the game starts it begins counting down and say every minute who long left.
    Ie. it broadcasts
    15 minutes remaining
    14 minutes remaining etc.

    What I want to do is when it reaches say 7 mins remaining to broadcast a message.
    The when reaches say 5 minutes remaining says a different message and the when it reaches say 1 minutes say another message.

    I can do this broadcast but it goes with the times of server uptime rather than game time.

    I also want it do this when game restarts so start again and withe 7 minutes say message again at 5 and then 1 again.


    Any ideas on how to query the game time remaining would be greatly appreciated.

    Kind regards
    Dougle_1
  2. Kripto
    Offline

    Kripto New Member

    Joined:
    Mar 2, 2014
    Posts:
    15
    Minecraft User:
    Kripto96
    You can use a schedule that broadcast a message every x second/minute.

    Add this in the public function init():
    PHP:
    $this->api->schedule($time, array($this"timingSchedule"), array(), true);
    and replace $time with your time (1200 will display your message(s) every minute, 300 every 15 second...).

    Then create the function timingSchedule (or what did you call it):
    PHP:
    public function timingSchedule() { //remember to set it to public!
      
    $this->api->chat->broadcast("Your message.");
      
    $this->api->chat->broadcast("Another message.");
    }
    If you want to display a random message you can use:
    PHP:
    public function timingSchedule() {
     
    $message rand(1$maxMsg); //replace $maxMsg with the numer of your messages
     
    if($this->message == 1) { //first message
      
    $this->api->chat->broadcast("First message!");
     }
     elseif(
    $this->message == 2) { //second message
      
    $this->api->chat->broadcast("Second message!");
     }
    }
    And add more elseif for all $maxMsg
  3. Dougle_1
    Offline

    Dougle_1 Ban Evader

    Joined:
    Dec 12, 2013
    Posts:
    26
    Minecraft User:
    Dougle_1
    Many Thanks for you help, am not that clued up on php scripting, command line is more my thing, although didnt use your exact code your explanation of the if clause really helped.

    Thanks Dougle_1
  4. iksaku
    Offline

    iksaku Notable Member Plugin Developer

    Joined:
    Sep 2, 2013
    Posts:
    1,130
    Plugins:
    4
    Minecraft User:
    iksaku
    That was I wanted to ask xD this the better explanation of how to use the "schedule" function :D

Share This Page

Advertisement