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

SendMessage to 4 Random Players in server

Comments in 'Plugin Development' started by PmServer, Oct 1, 2016.

  1. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Hi
    Hey guys I want a simple code.
    code taken from the server 4 players random and sends them a message for each one of them.
  2. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Any Help Please ?
  3. Vaivez66
    Offline

    Vaivez66 Notable Member Plugin Developer

    Joined:
    Jun 10, 2015
    Posts:
    402
    Plugins:
    2
  4. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
  5. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    PHP:
    $array = array($this->getServer()->getOnlinePlayers());
    $player $array[array_rand($array)];
    Why don't you try to search that?
    applqpak likes this.
  6. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    i want sendMessage 4 player random
  7. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Not just one player !
  8. korado531m7
    Offline

    korado531m7 Active Member

    Joined:
    Apr 4, 2015
    Posts:
    158
    Minecraft User:
    korado531m7
    getOnlinePlayers function can get all players

    but it's not 4 players...
  9. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    I want to send me four players just do random for each
  10. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Only 4 players no All Players :)
  11. EntirelyQuartz
    Offline

    EntirelyQuartz New Member

    Joined:
    Aug 9, 2016
    Posts:
    15
    Minecraft User:
    EntirelyQuartz
    Then do it four times.
    A for loop must solve your question.
    PHP:
    for($i 1$i <= 4$i++) {
        
    $players $this->getServer()->getOnlinePlayers();
        
    $player $players[array_rand($players)];
        
    $player->sendMessage("Hello!");
    }
    http://php.net/manual/en/control-structures.for.php
    applqpak likes this.
  12. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    No. You would just copy it. Please do it by yourself, you don't learn anything by copying. He sent ypu everything you need.
  13. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Thats 5 players only ?
  14. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    Simply use array_rand($array, $amount) and foreach it.
    applqpak and EntirelyQuartz like this.
  15. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    ok but I do not know a lot
  16. MyNameIsTriXz
    Offline

    MyNameIsTriXz Notable Member

    Joined:
    Aug 17, 2015
    Posts:
    538
    Minecraft User:
    MyNameIsTriXz
    "$i < 5"
    applqpak likes this.
  17. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    thank you i am test it now wait
  18. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    That's why you need to learn it. Did you learn PHP?
    applqpak likes this.
  19. CraftYourBukkit
    Offline

    CraftYourBukkit Notable Member Plugin Developer

    Joined:
    Jan 20, 2015
    Posts:
    1,022
    Plugins:
    2
    Minecraft User:
    CraftYourBukkit
    "$i = 0"
    0,1,2,3,4 = 5
    applqpak likes this.
  20. PmServer
    Offline

    PmServer New Member

    Joined:
    May 7, 2015
    Posts:
    53
    Minecraft User:
    PmServer
    Thank you man :) i am now test this code

Share This Page

Advertisement