简体   繁体   中英

SAMP PHP API Integration

ServerStats

I want to show the number of players in the server instead of that UNKNOWN thing, I haven't enabled the API yet, can I get help that, I want to integrate the progress bar to the total players in game like if players are 50/100 = 50% of the bar will be filled. Like the bar should work as the api updates.

<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>

Just use the SACNR monitor API, and

<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>

Where We fetch from API the following things

<?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>

You may find the API at http://monitor.sacnr.com/api.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM