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

SlapperTrait newbie coding

Discussion in 'Help' started by princeace, Feb 26, 2020.

  1. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    hoe i solve this problem?

    [06:48:37] [Server thread/CRITICAL]: ParseError: "syntax error, unexpected '=', expecting ')'" (EXCEPTION) in "plugins/Slapper-Prince.phar/src/slapper/SlapperTrait" at line 90

    and this is my code of line 89,90

    public function updateVars() {
    $vars = [
    "{players}" => $online = count($this->getServer()->getOnlinePlayers(),
    "{maxplayers}" = $this->getServer()->getMaxPlayers());
    ];
    }

    please help me thanks!
     
  2. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    There's an unnecessary variable in the array: $online =

    Change your array to:
    PHP:
    $vars = [
        
    "{players}" => count($this->getServer()->getOnlinePlayers()),
        
    "{maxplayers}" => $this->getServer()->getMaxPlayers()
    ];
    "{players}" points to getOnlinePlayers()
    {maxplayers} points to getMaxPlayers()

    If you wanted to keep your $online var, just define it beforehand, then point your placeholder to it:
    PHP:
    $online count($this->getServer()->getOnlinePlayers());
    $vars = [
        
    "{players}" => $online,
        
    "{maxplayers}" => $this->getServer()->getMaxPlayers()
    ];
     
    Last edited: Feb 26, 2020
  3. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    The first code doesn't seem right. There is it fixed.
    PHP:
    $vars = [
        
    "{players}" => count($this->getServer()->getOnlinePlayers()),
        
    "{maxplayers}" => $this->getServer()->getMaxPlayers()
    ];
     
    princeace likes this.
  4. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah

    i already have this but thanks i need player count in other world can you help me?
     
  5. GamakCZ

    GamakCZ Zombie Pigman

    Messages:
    598
    GitHub:
    GamakCZ
    count(Level->getPlayers());
     
    princeace likes this.
  6. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah

    where i input this code?
     
  7. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    First, please format your code and put it in a code block next time.

    You already have the necessary code to grab the world's player count here:
    PHP:
    "{world_player_count}" => count($player->getLevel()->getPlayers())
     
  8. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah

    how can i upload my code into block? im new here sorry
     
  9. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    You can add a code block by clicking the plus sign:
    SmartSelect_20200226-101323_Chrome.jpg
    And then add your code after you select PHP as the language:
    SmartSelect_20200226-101354_Chrome.jpg
     
    princeace likes this.
  10. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    PHP:
    <?php

    declare(strict_types=1);

    namespace 
    slapper;

    use 
    pocketmine\entity\DataPropertyManager;
    use 
    pocketmine\entity\Entity;
    use 
    pocketmine\nbt\tag\CompoundTag;
    use 
    pocketmine\nbt\tag\FloatTag;
    use 
    pocketmine\nbt\tag\IntTag;
    use 
    pocketmine\network\mcpe\protocol\SetActorDataPacket as SetEntityDataPacket;
    use 
    pocketmine\Player;

    /**
     * Trait containing methods used in various Slappers.
     */
    trait SlapperTrait {
        
    /** @var CompoundTag */
        
    public $namedtag;

        
    /**
         * @return DataPropertyManager
         */
        
    abstract public function getDataPropertyManager(): DataPropertyManager;

        
    /**
         * @return string
         */
        
    abstract public function getNameTag(): string;

        abstract public function 
    sendNameTag(Player $player): void;

        abstract public function 
    setGenericFlag(int $flagbool $value true): void;

        public function 
    prepareMetadata(): void {
            
    $this->setGenericFlag(Entity::DATA_FLAG_IMMOBILEtrue);
            if (!
    $this->namedtag->hasTag("Scale"FloatTag::class)) {
                
    $this->namedtag->setFloat("Scale"1.0true);
            }
            
    $this->getDataPropertyManager()->setFloat(Entity::DATA_SCALE$this->namedtag->getFloat("Scale"));
        }

        public function 
    tryChangeMovement(): void {

        }

        public function 
    sendData($playerList, array $data null): void {
            if(!
    is_array($playerList)){
                
    $playerList = [$playerList];
            }

            foreach(
    $playerList as $p){
                
    $playerData $data ?? $this->getDataPropertyManager()->getAll();
                unset(
    $playerData[self::DATA_NAMETAG]);
                
    $pk = new SetEntityDataPacket();
                
    $pk->entityRuntimeId $this->getId();
                
    $pk->metadata $playerData;
                
    $p->dataPacket($pk);

                
    $this->sendNameTag($p);
            }
        }

        public function 
    saveSlapperNbt(): void {
            
    $visibility 0;
            if (
    $this->isNameTagVisible()) {
                
    $visibility 1;
                if (
    $this->isNameTagAlwaysVisible()) {
                    
    $visibility 2;
                }
            }
            
    $scale $this->getDataPropertyManager()->getFloat(Entity::DATA_SCALE);
            
    $this->namedtag->setInt("NameVisibility"$visibilitytrue);
            
    $this->namedtag->setFloat("Scale"$scaletrue);
        }

        public function 
    getDisplayName(Player $player): string {
            
    $vars = [
                
    "{name}" => $player->getName(),
                
    "{display_name}" => $player->getName(),
                
    "{nametag}" => $player->getNameTag(),
                
    "{online}" => count($player->getServer()->getOnlinePlayers()),
                
    "{world_player_count}" => count($player->getLevel()->getPlayers()),
                
    "{max_online}" => $player->getServer()->getMaxPlayers()
            ];
            return 
    str_replace(array_keys($vars), array_values($vars), $this->getNameTag());
        }
    }

    ok thanks

    how can i add the player after joining in another world like prison,pvp,etc? to see player playing in this world?
     
  11. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    Not sure what you're asking, can you word it differently?
     
  12. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    i mean when other player click the slapper automatic teleport into prison world then the slapper prison show player how many people in prison

    like

    PRISON
    JOIN: 0
     
  13. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
  14. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    i cant find youre code in my code
    and i search this
    $this->getServer()->getLevelByName($levelName)
    no one can see this
     
  15. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    That code isn't in my plugin, that was simply an example of what you could do in order to complete your goal. The part you need is around lines 254-284.
     
  16. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    PHP:
    else{
                    
    $subtext $this->config->getNested("UI.World-Button-Subtext");
                    
    $worldPlayerCount 0;
                    foreach(
    $this->getServer()->getLevelByName($value[2])->getPlayers() as $p){
                        
    $worldPlayerCount += 1;
                    }
                    
    $subtext str_replace("{current-players}"$worldPlayerCount$subtext);
                    if(isset(
    $value[3])){
                        
    $search $value[3];
                        
    $file $value[4];
                    }
    this is i found in youre code where i input this my code?
     
  17. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    Well I'm not going to spoon feed you, that's just how I managed to do it in my plugin. I'm leaving it to you to implement it in your plugin :)
     
  18. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    :( but i dont know where i input the code in my code :(
     
  19. Xenophilicy

    Xenophilicy Spider Jockey

    Messages:
    31
    GitHub:
    xenophilicy
    Lol are you saying you don't understand your own code?
     
  20. princeace

    princeace Slime

    Messages:
    78
    GitHub:
    PrincessSeah
    this is not my code this slapper from poggit i dont know where line put your code
     
  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.