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

Broadcast a message.

Discussion in 'Facepalm' started by ZakousseMC, Dec 20, 2016.

  1. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Hi,

    I would like to know what's the code to broadcast a general message that everyone can see, but, with the variable "player" in front, that change in function of the player executing the command. Eg :

    ZakousseMC : /afk

    "player" is now AFK.

    This is one of the code I wrote, but when I execute it, an error message appears.
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args) {
        
    $sender->sendMessage(TextFormat::GREEN "Vous etes desormais AFK.");
        
    $this->api->console->run("broadcast est desormais AFK.");
        return 
    false;
     
  2. SOFe

    SOFe Administrator Staff Member PMMP Team Poggit Admin

    Messages:
    1,968
    GitHub:
    sof3
    :facepalm:
     
  3. kaliiks

    kaliiks Zombie

    Messages:
    250
    PHP:
    $this->getServer()->broadcastMessage("Message");
     
  4. [deleted]

    [deleted] Guest

    No just no....
    I just fixed your Code but please learn the API.
    PHP:
    public function onCommand(CommandSender $senderCommand $cmd$label, array $args)
        {
            switch (
    $cmd->getName()) {
                case 
    "afk":
                    if (
    $sender instanceof Player) {
                        
    $pn $sender->getName();
                        
    $sender->getServer()->broadcastMessage("$pn is now AFK for $args[0] Minutes!");
                    }
            }
        }

    So I made that the command usage is: /afk [minutes]
    It will broadcast the Message.
     
    Last edited by a moderator: Dec 23, 2016
  5. ZakousseMC

    ZakousseMC Spider Jockey

    Messages:
    46
    GitHub:
    ZakousseMC
    Read what I said in the other topic, I'm french, not english, and I can't find anything in french, I'm just taking other codes and trying to figure out what it does. So please, before talking, try having my point of view, it's not because it's easy for you, that it is for me huh.
     
  6. [deleted]

    [deleted] Guest

    Lol i am from Germany my English isnt also good but lol php is in english lol.
    Just change the message where $sender->sendMessage () is.
     
  7. [deleted]

    [deleted] Guest

    Je parle un peu français.
     
  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.