foreach all the online players then if($p->getGamemode() === 0 [for survival gamemode] ){ //code to execute }
ah. I was trying to make a HUD , replacing {SURVIVAL_PLAYERS} {SPECTATOR_PLAYERS} ,, how can l str_replace this?
no... I mean .. str_replace {SURVIVAL_PLAYERS} // with people in survival . I am not understand you my friend xd
i hope you arent using a translator or so, either ways let me elaborate it again you foreach all players then check for gamemode int, if it's in specified gamemode you increment said counter after that you replaces said string with said incremental counter
Something as simple as this: PHP: function formatPlayerGamemodesToString($string, array $players) : string{$gm = [0 => [], 1 => [], 2 => [], 3 => []];Foreach($players as $player){$gm[$player->gamemode][] = $player->getName();}$string = str_ireplace (['{SURVIVAL_PLAYERS}', '{CREATIVE_PLAYERS}', '{ADVENTURE_PLAYERS}', '{SPECTATOR_PLAYERS}'], [implode(', ', $gm[0]), implode(', ', $gm[1]), implode(', ', $gm[2]), implode(', ', $gm[3])], $string);return $string;} Usage: PHP: $string = formatPlayerGamemodesToString("Players in survival : {SURVIVAL_PLAYERS}" [$player1, $player2]);echo $string;//if players are in in survival output should be: Players in survival : player1, player2
PHP: foreach($this->getServer()->getOnlinePlayers() as $check) { $count = 0; if ($check->getGamemode() == 3) { $count++; } $check->sendPopup("there are ".$count." spectator(s) !"); //You can use str_replace("{SPECTATOR_COUNT}", $count, $string); like for config } Example
ahh thankyou! but what if a player changes gamemode back to survival. the increment counter stay the same... but Is false
actually i think that's better then recalculating it every tick for every player even tho it would give off a significant memory impact