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

How to properly use scoreboards (and especially updates)

Discussion in 'Development' started by dadodasyra, Jul 18, 2020.

  1. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    Hello it's been 2 days I'm struggling to make sure to update a scoreboard, it really does not want and I do not understand why, I was therefore inspired by the poggit plugin but the method does not work either, I must surely do something wrong. Here are my functions and how I use them:

    Create, first time
    PHP:
        public static function createScoreboard($order 0) : void
        
    {
           
    //Imagine $players is already set with a list of player, I tested it it works (I cut the part where I create $ players)
            
    foreach ($players as $player) {
                
    $packet = new SetDisplayObjectivePacket();
                
    $packet->displaySlot "sidebar";
                
    $packet->objectiveName "jumpleague";
                
    $packet->displayName JumpLeague::getMessage("namescoreboard", [], 1);
                
    $packet->criteriaName "dummy";
                
    $packet->sortOrder $order;
                
    var_dump($player->sendDataPacket($packet));
            }
        }
    Create works well the problem is the 2nd time I want to enter the information in the table.

    Update, and set the first time :
    PHP:
        public static function setScoreboardEntry(string $msgint $score) : void
        
    {
           
    //Imagine $players is already set with a list of player, I tested it it works (I cut the part where I create $ players)
            
    foreach ($players as $player) {
                
    $entry = new ScorePacketEntry();
                
    $entry->objectiveName "jumpleague";
                
    $entry->type 3;
                
    $entry->customName $msg";
                
    $entry->score $score;
                
    $entry->scoreboardId $score;
                
    $packet = new SetScorePacket();
                
    $packet->type 0;
                
    $packet->entries[$score] = $entry;
                
    $player->sendDataPacket($packet); //By ayzrix the haxor
            
    }
        }
    No error, the packet is sent because it returns true, the scoreboard has been created, etc.
    Besides, to wonder why pocketmine does not contain an API for scoreboard
     
  2. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    use a task
     
  3. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    In your opinion I do how ... It is already the case, this function is called in a task
     
  4. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    is it repeating task
     
  5. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    yes
     
  6. Levi

    Levi Skeleton

    Messages:
    955
    GitHub:
    captainleviftw
    does the scoreboard not show or what’s the problem
     
  7. dadodasyra

    dadodasyra Witch

    Messages:
    68
    GitHub:
    dadodasyra
    As written in my first post, the scoreboard is created, the lines are put correctly, but when I want to update it nothing changes
     
  8. nexTRushh

    nexTRushh Creeper

    Messages:
    3
    GitHub:
    itzahmaddev
    I don't know if you allready done it but here is how i make my scoreboard.

    First I create the scoreboard the code looks like this

    PHP:
     public function setScoreboardEntry(Player $playerint $scorestring $msgstring $objName)    {
            
    $entry = new ScorePacketEntry();
            
    $entry->objectiveName $objName;
            
    $entry->type 3;
            
    $entry->customName $msg   ";
            
    $entry->score $score;
            
    $entry->scoreboardId $score;
            
    $pk = new SetScorePacket();
            
    $pk->type 0;
            
    $pk->entries[$score] = $entry;
            
    $player->sendDataPacket($pk);
        }

        public function 
    rmScoreboardEntry(Player $playerint $score)
        {
            
    $pk = new SetScorePacket();
            if (isset(
    $pk->entries[$score])) {
                unset(
    $pk->entries[$score]);
                
    $player->sendDataPacket($pk);
            }
        }

        public function 
    createScoreboard(Player $playerstring $titlestring $objNamestring $slot "sidebar"$order 0)
        {
            
    $pk = new SetDisplayObjectivePacket();
            
    $pk->displaySlot $slot;
            
    $pk->objectiveName $objName;
            
    $pk->displayName $title;
            
    $pk->criteriaName "dummy";
            
    $pk->sortOrder $order;
            
    $player->sendDataPacket($pk);
        }

        public function 
    rmScoreboard(Player $playerstring $objName)
        {
            
    $pk = new RemoveObjectivePacket();
            
    $pk->objectiveName $objName;
            
    $player->sendDataPacket($pk);
        }

        public function 
    onScore()
        {
                
    $this->rmScoreboard($player"objektName");
           
    //Scoreboard Title
                
    $this->createScoreboard($player"ScoreBoard Lol""objektName");
        
    //Lines
                
    $this->setScoreboardEntry($player1" ""objektName");
                
    $this->setScoreboardEntry($player2" ""objektName");
            }
        }
    After this actually at first tbh I start the Task like this in onEnable
    PHP:
    $this->getScheduler()->scheduleRepeatingTask(new ScoreBoard($this), 20);
    The content of the task is basicly very short
    PHP:
    <?php

    namespace ahmad\Tasks;

    use 
    ahmad\buildFFA;
    use 
    pocketmine\scheduler\Task;

    class 
    ScoreBoard extends Task{

        
    /**
         * @var buildFFA
         */
        
    private $main;

        public function 
    __construct(buildFFA $main)
        {
            
    $this->main $main;
        }

        public function 
    onRun(int $currentTick)
        {
            
    $this->main->onScore();
        }
    }
     
    GodWeedZao likes 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.