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!
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()];
The first code doesn't seem right. There is it fixed. PHP: $vars = [ "{players}" => count($this->getServer()->getOnlinePlayers()), "{maxplayers}" => $this->getServer()->getMaxPlayers()];
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())
You can add a code block by clicking the plus sign: And then add your code after you select PHP as the language:
PHP: <?phpdeclare(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 $flag, bool $value = true): void; public function prepareMetadata(): void { $this->setGenericFlag(Entity::DATA_FLAG_IMMOBILE, true); if (!$this->namedtag->hasTag("Scale", FloatTag::class)) { $this->namedtag->setFloat("Scale", 1.0, true); } $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", $visibility, true); $this->namedtag->setFloat("Scale", $scale, true); } 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?
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
You can take a look at my NaviCompass plugin here: https://github.com/Xenophilicy/NaviCompass/blob/master/src/Xenophilicy/NaviCompass/NaviCompass.php I have that exact function in there. If you know the name of the level, you can use something like this: PHP: $this->getServer()->getLevelByName($levelName) Then use that level object to get the player count accordingly
i cant find youre code in my code and i search this $this->getServer()->getLevelByName($levelName) no one can see this
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.
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?
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