Skip to content

Instantly share code, notes, and snippets.

@ziggi
Forked from Westie/gist:234209
Last active July 3, 2018 15:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ziggi/d3a8f93783b7deea2895 to your computer and use it in GitHub Desktop.
Save ziggi/d3a8f93783b7deea2895 to your computer and use it in GitHub Desktop.
SampQueryAPI (for sa-mp 0.3.7) example
<?php
include "SampQueryAPI.php";
$query = new SampQueryAPI('127.0.0.1', '7777');
if ($query->isOnline()) {
$aInformation = $query->getInfo();
$aServerRules = $query->getRules();
?>
<b>General Information</b>
<table width="400">
<tr>
<td>Hostname</td>
<td><?= htmlentities($aInformation['hostname']) ?></td>
</tr>
<tr>
<td>Gamemode</td>
<td><?= htmlentities($aInformation['gamemode']) ?></td>
</tr>
<tr>
<td>Players</td>
<td><?= $aInformation['players'] ?> / <?= $aInformation['maxplayers'] ?></td>
</tr>
<tr>
<td>Language</td>
<td><?= htmlentities($aInformation['language']) ?></td>
</tr>
<tr>
<td>Map</td>
<td><?= htmlentities($aServerRules['mapname']) ?></td>
</tr>
<tr>
<td>Weather</td>
<td><?= $aServerRules['weather'] ?></td>
</tr>
<tr>
<td>Time</td>
<td><?= $aServerRules['worldtime'] ?></td>
</tr>
<tr>
<td>Version</td>
<td><?= $aServerRules['version'] ?></td>
</tr>
<tr>
<td>Password</td>
<td><?= $aInformation['password'] ? 'Yes' : 'No' ?></td>
</tr>
</table>
<br />
<b>Online Players</b>
<?php
$aPlayers = $query->getDetailedPlayers();
if (!is_array($aPlayers) || count($aPlayers) == 0) {
echo '<br /><i>None</i>';
} else {
?>
<table width="400">
<tr>
<td><b>Player ID</b></td>
<td><b>Nickname</b></td>
<td><b>Score</b></td>
<td><b>Ping</b></td>
</tr>
<?php
foreach ($aPlayers as $sValue) {
?>
<tr>
<td><?= $sValue['playerid'] ?></td>
<td><?= htmlentities($sValue['nickname']) ?></td>
<td><?= $sValue['score'] ?></td>
<td><?= $sValue['ping'] ?></td>
</tr>
<?php
}
echo '</table>';
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment