[Ajuda] API SAMP PHP
#1

Usando essa API https://sampforum.blast.hk/showthread.php?tid=355574
Eu consegui pegar algumas informaзхes do meu servidor como:
print_r($query->getBasicPlayers());
Array ( [0] => Array ( [name] => Indio [score] => 6 ) )

print_r($query->getDetailedPlayers());
Array ( [0] => Array ( [playerid] => 0 [nickname] => Indio [score] => 6 [ping] => 15 ) )

Mas como printar essas informaзхes separadas?
Tipo apenas nickname, apenas score, queria colocar dentro de uma tabela pra base de algumas coisas como onlinelist
Reply
#2

PHP Code:
$players $query->getBasicPlayers();
foreach(
$players as $player)
{
    echo 
$player['name']." - ".$player['score']."<br>";

Reply
#3

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(<= $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.'
Reply
#4

Muito obrigado aos dois! +REP
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)