Auto Refreshing players online

Discussion in 'Server & Community Management' started by Malo, May 4, 2013.

  1. Im looking for something similar to shotbow

    (http://shotbow.net/forum/pages/Home/)

    Were the players online refreshes every 5 seconds. I have looked around, but haven't been able to find something that can do that...
     
    • Agree Agree x 2
  2. CustomForms

    CustomForms Retired Moderator
    Retired Supporter

    Would involve using JavaScript. You need to register the JavaScript in html, then you need to say "hey, im using JavaScript," before you can actually start coding the script in JavaScript.
     
  3. I don't know javascript :[ ... i don't even know much about html and css.
     
  4. Lol html is just basic markup really, I suggest learning javascript. It's alot easier than java.
     
  5. you could always right click and go inspect element :c

    but you gotta see if the code is public or private if its public then you could use it :)
     
  6. CustomForms

    CustomForms Retired Moderator
    Retired Supporter

    Inspect element does not show you JavaScript Scripts.
     
  7. Yes it does.
     
  8. In the resources tab.

    And please don't take tips from them on web development. Such bad use of includes on that pages (around line 253 they have another <html> tag). W3C Validator gives 96 errors and they load 3 different versions of jquery...
     
    • Like Like x 1
  9. And I've worked it out :D

    Assuming you have a PHP script at /playercount.php which simply outputs the total players (as a single value).

    HTML:
    <p>Players <span id="playercount">0</span>/100</p>
    Replace the 100 with your max count and the 0 with the number which is displayed if the ajax fails to load.

    Then just before your closing </body> tag (and after you load jquery).
    HTML:
    <script>
    // load it at start
    $('#playercount').load('playercount.php');
     
    //set it to load every x ms
    var auto_refresh = setInterval(
        function () {
            $('#playercount').load('playercount.php'); // here is the file to load
        },
        5000); //here is update interval in ms
    </script>
     
    #9 LukeHandle, May 7, 2013
    Last edited: May 7, 2013
  10. jtaylor69

    jtaylor69 Retired Moderator
    Retired

    The number of players are stored in this text file.
    www.shotbow.net/serverList.txt

    This is then parsed using Ajax and JS to update real-time on the home page.

    HTML:

        function updateServerLists() {
            $.ajax({
              url: "//shotbow.net/serverList.txt",
              success: function(data) {        
                  if (data.indexOf(",") > -1) {          
                      // Parse the data
                      var pData = data.split(",");
                    for (i=0;i<phpServerArray.length;i++) {
                       var el = document.getElementById(phpServerArray[i] + "-players");
                       if (pData[i] != "o" && typeof pData[i] !== "undefined") {                      
                           var origNumber = parseInt(el.innerHTML);
                           var dataNumber = parseInt(pData[i]);
                         
                           if (origNumber != dataNumber) {
                               el.innerHTML = pData[i];
                           }
                         
                           if (origNumber > dataNumber) {
                                fadeColor(el, redColor);
                                fadeBack(el);
                            } else if (origNumber < dataNumber) {
                               fadeColor(el, greenColor);
                               fadeBack(el);
                           }
     
    • Like Like x 2
    • Useful Useful x 2