0

服务器统计

我想显示服务器中的玩家数量而不是那个 UNKNOWN 的东西,我还没有启用 API,我能得到帮助吗,我想将进度条集成到游戏中的总玩家,比如玩家是 50 /100 = 50% 的条将被填充。就像栏应该随着 api 更新而工作。

<div class="is-clearfix"></div> 
<section class="section dark-grey has-text-centered">
    <div class="container">
        <div class="heading">
            <h1 class="title">Our Servers</h1>
            <br>
        </div>
        <div class="columns is-gapless">
            <div class="column">
                <div class="card card-server">
                    <div class="card-image">
                        <figure class="image is-2by1">
                            <img src="./OutBreak Gaming_files/sfcnr_card1.png">
                        </figure></div> <div class="card-content">
                        <div class="title" style="font-size: 1.25em; color: rgb(119, 119, 119); margin-top: 0.5em;">87.98.241.207:7775</div> 
                        <div class="players is-marginless">
                            <div class="content playersOnline">
                                Unknown PLAYERS ONLINE
                            </div> 
                            <progress value="0" max="100" class="progress is-success"></progress>
                            <br></div> <a class="button is-info is-medium is-fullwidth">Play Now</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</section>
</div>
4

1 回答 1

0

只需使用 SACNR 监控 API,然后

<div class="columns is-gapless">
<div class="column"><div class="card card-server">
<div class="card-image">
<figure class="image is-2by1">
<img src="./OutBreak Gaming_files/sfcnr_card1.png"></figure></div> 
<div class="card-content">
<div class="title" style="font-size: 1.25em; color: rgb(119, 119, 119); margin-top: 0.5em;">87.98.241.207:7775</div> Hostname:
<div class="hosting"></div>Gamemode:
<div class="game-mode"></div>Map:
<div class="language"></div> Players:
<div class="players is-marginless"><div class="content playersOnline">
    FETCHING PLAYERS ONLINE
  </div> 
<progress value="0" max="100" class="progress is-success"></progress><br></div> 
<a href="samp://87.98.241.207:7775"><a class="button is-info is-medium is-fullwidth">Play Now</a></a></div></div></div></div></div></section></div>

我们从 API 获取以下内容的位置

<?php
require_once("sampsvr.php");
$monitor = new SACNR\Monitor;
//$obj = $monitor->get_info_by_id(1790345);
$obj = $monitor->get_info_by_ip('87.98.241.207','7775');
$players = $obj->Players;
$hostName = $obj->Hostname;
$Gamemode = $obj->Gamemode;
$Mapname = $obj ->Language;
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){

  $('.progress').val(<?php echo $players;?>);
  $('.playersOnline').html(<?php echo $players;?> +' PLAYERS ONLINE' );
  $('.hosting').html("<?php echo $hostName;?>");
  $('.game-mode').html("<?php echo $Gamemode;?>");
  $('.language').html("<?php echo $Mapname;?>");
});
</script>

您可以在http://monitor.sacnr.com/api.html找到 API

于 2017-06-08T09:47:58.927 回答