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

code to get player count from world in a sign

Comments in 'Plugin Development' started by Driesboy1, Jan 31, 2016.

  1. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
    hello

    can i get a code to getplayer count from world in a sign
  2. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    PHP:
    $signTile->setText(count($world->getPlayers()));
  3. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
  4. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
    and the update from 5 sec
  5. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    make a repeating task.
  6. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
    can you give me a code to do it
    on a sign with update time 5 sec
    Code:
    
    
  7. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
  8. Driesboy1
    Offline

    Driesboy1 Active Member

    Joined:
    Oct 28, 2015
    Posts:
    102
    Minecraft User:
    Driesboy
    but how to use sign update
  9. PocketKiller
    Offline

    PocketKiller Notable Member

    Joined:
    Jul 20, 2015
    Posts:
    741
    put that on onRun()
  10. AndrewBit
    Offline

    AndrewBit Notable Member

    Joined:
    Jun 18, 2015
    Posts:
    435
    Minecraft User:
    AndrewBit4
    You should use a schedule repeating task.
    PHP:

    class SignUpdater extends PluginTask{

    private 
    $owner;

    public function 
    __construct(Owner $owner)
    {
    $this->owner $owner;
    parent::__construct($owner);
    }

    public function 
    OnRun($currentTick)
    {
    # In what level is your sign?
    $level $this->owner->getServer()->getLevelByName("level name");
    foreach(
    $level->getTiles() as $tile){
    if(
    $tile instanceof Sign){
    $sign $tile->getText();
    if(
    $sign[0] === "First line of your sign"){
    $sign->setText("Line1","Line2",/* Line 3*/ "Players: " count($level->getPlayers()),"Line4");
    }
    }
    }
    }
    # Coded in a Wii U. #MaybeHasErrors
    You can call it with:
    PHP:
    $this->getServer()->getScheduler()->scheduleRepeatingTask(new SignUpdater($this), /*ticks, I suggest you 10 ~ 15*/ 15);
    Tim // robske Büba likes this.
  11. PEMapModder
    Offline

    PEMapModder Notable Member Plugin Developer

    Joined:
    Oct 9, 2013
    Posts:
    7,294
    Plugins:
    11
    Minecraft User:
    PEMapModder
    parent::__construct($owner) already defines $this->owner as $owner...

Share This Page

Advertisement