1. Hey,
    Quite new to the hypixel api, and I have got something working, where is displays my stats.
    How would you add a text box where you can type your name and it displays the stats for that name?
    - Mds
     
    #1
    • Funny Funny x 1
  2. Which programming language are you talking about?
     
    #2
    • Funny Funny x 1
  3. oh sorry, php
     
    #3
    • Funny Funny x 1
  4. #4
    • Funny Funny x 1
    • Useful Useful x 1
  5. #5
    • Funny Funny x 1
  6. Okay what you wanna do is:
    Code:
    <form method="post" action="yourfile.php" class="form-horizontal">
    <input placeholder="Enter your name" name="username" />
    <button name="buttonsend1" type="submit">Show me</button>
    </form>
    Then on top of your php file:
    Code:
    <?php
    if (isset($_POST['buttonsend1'])){
    $player = $_POST["username"]
    echo $player;
    // Do other stuff here
    }
    ?>
    
     
    #6
    • Funny Funny x 1
    • Useful Useful x 1
  7. Unexpected echo where it says:
    Code:
    echo $player;
    
     
    #7
    • Funny Funny x 1
  8. Theres a ; missing :p Try this instead:
    Code:
    <?php
    if (isset($_POST['buttonsend1'])){
    $player = $_POST["username"];
    echo $player;
    // Do other stuff here
    }
    ?>
    
     
    #8
    • Funny Funny x 1
  9. I don't know how I did not see that.. xD
    Thanks!
    1 question, how do I make it the formatted name?
     
    #9
    • Funny Funny x 1
  10. It shows you in the example I sent above. Once you set everything up like in the example do:
    Code:
     echo 'Formatted Name: ' . $player->getFormattedName(true, true);
     
    #10
    • Funny Funny x 1
  11. Code:
    <?php
    if (isset($_POST['buttonsend1'])){
    $player = $_POST["username"];
    echo 'Name: ' . $player->getFormattedName(true, true);
        echo '<br>';
        echo 'SkyWars Kills: ' . $player->getStats()->getGameFromID(HypixelPHP\GameTypes::SKYWARS)->getInt('kills');
        echo '<br>';
        echo 'SkyWars Wins: ' . $player->getStats()->getGameFromID(HypixelPHP\GameTypes::SKYWARS)->getInt('wins');
        echo '<br>';
    }
    ?>
    
    This code does not work.
     
    #11
    • Funny Funny x 1
  12. Sure you need: Make sure you have the HypixelPHP file in your directory and you fill in your /api key.
    Code:
    <?php
    include_once('HypixelPHP.php');
    $HypixelPHP = new HypixelPHP\HypixelPHP(['api_key' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx']);
    // get a player object using the hypixel api object
    if (isset($_POST['buttonsend1'])){
    $playername = $_POST["username"];
    $player = $HypixelPHP->getPlayer([\HypixelPHP\KEYS::PLAYER_BY_NAME => $playername]);
    if ($player != null) {
    echo 'Name: ' . $player->getName();
    echo '<br>';
    echo 'Formatted Name: ' . $player->getFormattedName(true, true);
    echo '<br>';
    echo 'Paintball Kills: ' . $player->getStats()->getGameFromID(\HypixelPHP\GameTypes::PAINTBALL)->getInt('kills');
    echo '<br>';
    echo 'Rank: ' . $player->getRank()->getCleanName();
    echo '<br>';
    echo 'Pre EULA Rank: ' . $player->getRank(true, true)->getCleanName();
    } else {
    echo 'Player == null';
    print_r($HypixelPHP->getUrlErrors());
    }
    }
    ?>
    
     
    #12
    • Funny Funny x 1
  13. Thanks for the help, everything is working!

    Thread can now be closed.
     
    #13
    • Funny Funny x 1
  14. Your problems/errors are pretty common, easy PHP mistakes, I recommend that you learn some more PHP before you use the API.
     
    #14
    • Funny Funny x 1
  15. The API / Plancke's PHP wrapper is actually a great way to learn PHP as it's very practical and fun and not that difficult :)
     
    #15
    • Like Like x 1
    • Funny Funny x 1
  16. If you haven't even gotten around "Hello world", or the basic syntaxes (fx. ';') starting with the API is starting too big.
     
    #16
    • Funny Funny x 1
  17. Yeah.. I started to
     
    #17
    • Funny Funny x 1

Share This Page