1. The forums will be archived and moved to a read only mode in about 2 weeks (mid march).

How to broadcast to specific players

Discussion in 'General discussion' started by Taewon Kim, Dec 1, 2020.

  1. Taewon Kim

    Taewon Kim Spider

    Messages:
    9
    GitHub:
    twk1024
    Hi.

    I want to broadcast a message to specific players not all players.
    Or using sendMessage to specific players, not one player.

    Is there any way to do that?
     
  2. minijaham

    minijaham Skeleton

    Messages:
    801
    GitHub:
    minijaham
    Use foreach() function
    That should solve it
     
  3. Doxestic

    Doxestic Spider Jockey

    Messages:
    41
    use this code:


    PHP:
    $players = [] //player you want to send packet/message
    foreach($players as $player){
        
    // your code like $player->sendMessage("hey there");
    }
     
  4. wolfdale

    wolfdale Zombie Pigman

    Messages:
    535
    GitHub:
    diamond-gold
    Or simply $server->broadcastMessage($msg,$players);
     
    Primus and minijaham like this.
  5. Taewon Kim

    Taewon Kim Spider

    Messages:
    9
    GitHub:
    twk1024
    Thanks for your reply
    And, I tried to like this

    PHP:
    $online $this->getServer()->getOnlinePlayers();
    $players = array($online);
    $english = array($this->lang->db [$players] ["language"] == "eng");
    $korea = array($this->lang->db [$players] ["language"] == "kor");

    foreach(
    $english as $englang) {
       
    $this->getServer()->broadcastMessage("Broadcast Test in English"$englang);
    }
    foreach(
    $korea as $korealang) {
       
    $this->getServer()->broadcastMessage("Broadcast Test in Korean Language"$korealang);
    }
    *In this code, $this->lang is to get config from my own plugin for a multi-language system.

    So.. I should send different messages to each language.
    But in this code, I got
    Code:
    'ErrorException: "Illegal offset type" (EXCEPTION)'
    I have no idea what 'Illegal offset type' means.
     
    Primus likes this.
  6. Doxestic

    Doxestic Spider Jockey

    Messages:
    41
    1. $this->getServer()->getOnlinePlayers() is array no nee to put in into other array the result will be [[/*players array*/]]
    2.what is $this->lang->db [$players] ["language"]? and what == "eng" or second one?
    i recommend you first learn php basics
     
    Primus and minijaham like this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.