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

code help

Discussion in 'Development' started by Kabluinc, Jan 4, 2017.

  1. Kabluinc

    Kabluinc Baby Zombie

    Messages:
    129
    Hi,

    I was wanting to know how I could achieve this where I want to broadcast every players name that are online except specific player defined by players name.

    e.g. steve. so I would do
    foreach $this->getServer->getOnlinePlayers as $p
    then $players = $p->getName();
    I could then broadcast this $players to show all online player names but how could I make it so it broadcasts every name except the player name steve?
     
  2. robske_110 (Tim)

    robske_110 (Tim) Wither Skeleton Poggit Reviewer

    Messages:
    1,342
    GitHub:
    robske110
    Please learn PHP. Seriously. Do you know what an array is? If not I recommend to start from http://php.net/manual/en/language.types.array.php.

    Just because others will do it anyways:
    code, but please don't just copy+paste
    PHP:
    foreach($this->getServer->getOnlinePlayers as $player){ #iterate through all objects in array
        
    if($player->getName() !== "Steve"){ #check if $player doesn't have the name Steve
            #send message to $player
        
    }
    }
     
  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.