03.05.2018, 13:26
Um exemplo de como usar essa API.
PHP Code:
$query = new SampQuery("127.0.0.1", 7777);
if ($query->connect()) {
$info = $query->getInfo();
$players = $query->getDetailedPlayers();
$query-close();
// Informaзхes sobre o servidor (tabelado)
echo '<table>
<tr>
<th>Hostname</th>
<td>'.$info['hostname'].'</td>
<th>Gamemode</th>
<td>'.$info['gamemodename'].'</td>
</tr>
<tr>
<th>Jogadores</th>
<td>'.$info['players'].'</td>
<th>Mбximo</th>
<td>'.$info['maxplayers'].'</td>
</tr>
</table>';
// Listar jogadores caso nгo esteja 0 ou acima de 100.
if(1 <= $info['players'] < 100)
{
echo '<table>
<tr>
<th>ID</th>
<th>Nickname</th>
<th>Scores</th>
<th>Ping</th>
</tr>';
foreach($players as $player)
{
echo '
<tr>
<td>'.$player['playerid'].'</td>
<td>'.$player['nickname'].'</td>
<td>'.$player['score'].'</td>
<td>'.$player['ping'].'</td>
</tr>';
}
echo '</table>';
}
}
else
echo 'Servidor off-line.';