-
Notifications
You must be signed in to change notification settings - Fork 0
Get Server Player List
Get server player list can be used to get up to 3 different outputs: names, skins and heads. It might be worth noting, however, that the more player heads/skins that need to be loaded, the slower your page will load. The effects of which could be considerable.
To return what you want, you need to pass into the function getPlayerList();
three things: $player_names, $player_heads and $player_skins
. All of which should contain a Boolean input.
So it looks a bit like this:
`var = getPlayerList($player_names,$player_heads,$player_skins);`
Should you not input 3 Boolean values, so, for example, it looked like this: getPlayerList(true,false);
, then it would default player skins to off.
DEFAULT VALUES:
- Player Names:
true
- Player Heads:
false
- Player Skins:
false
Because we believe that you should have the power to output the results how you want, the function returns a 2d array. The array contains only what you need, so for example, should you request Player Names only, you will get an array that looks like this:
`[[mc_user1],[mc_user2],...]`
And should you want Player Heads and Player Names, you will get this:
`[["<img src='https://mcapi.ca/avatar/2d/mc_user1/100' alt='$i' class='head'>", "mc_user1"], ...]`
####So wuuutt...? I don't know how php works, how am I meant to output it?
Bellow is a sample piece of code of how you could output it, but not necessarily should output it:
<?php
function getPlayers($player_names=true, $player_heads=true, $player_skins=false, $max=20){
$output = "";
$count = 0;
foreach(getPlayerList($player_names, $player_heads, $player_skins) as $i){
if($count > $max) {
break;
}
$output .= join("", $i) . "<br>";
$count += 1;
}
$output = substr($output,0,-4);
return $output;
}
?>
This function will return a list of as a string (one on each line), so all you need to do to get it to display on your page is:
<p><?php echo getPlayers(); ?></p> <!-- Names only, up to 20 players -->
<p><?php echo getPlayers(true,true,false,30); ?></p> <!-- Names and Heads only, up to 30 players -->
Note: whilst we will do as much as we can to explain how to use our API, we cannot teach you to code. If you are experiencing an issue that is not to do with our API, please consult somewhere like stackoverflow for assistance.