MaxKorlaar / Hypixel-PHP-Examples

Gets you started with exploring the infinite possibilities of PHP and Hypixel's API.
https://github.com/Plancke/hypixel-php
MIT License
1 stars 0 forks source link

Problem with echo player's guild coins stats. #1

Open idavydoff opened 6 years ago

idavydoff commented 6 years ago

Hey Max! I am trying to echo "How many guild coins player made today" with hypixel api. Doing this but it won't work $player->getInt('dailyCoins-16-9-2017') Can u help me with it?

MaxKorlaar commented 6 years ago

Are you doing this on a guild player? 'dailyCoins' does not exist for 'normal' players in the API.

For example, this is what a Guild response looks like in the API:

{
  "success": true,
  "guild": {
    "_id": "53669426ed5099e8f963a1f8",
    "bankSizeLevel": 0,
    "canMotd": true,
    "coins": 165795,
    "coinsEver": 775795,
    "created": 1399231526370,
    "memberSizeLevel": 1,
    "members": [
      {
        "uuid": "fc3054d276b340bf82330246cd2dd3a6",
        "rank": "MEMBER",
        "joined": 1441991834864,
        "dailyCoins-17-9-2017": 750
      },
      {
        "uuid": "4a9fa46e111b4dd3bbbff7900f823139",
        "rank": "MEMBER",
        "joined": 1435428417573
      },
      {
        "uuid": "6a1bf504a7714b5cb6e6a014c290e509",
        "rank": "GUILDMASTER",
        "joined": 1457736256933
      },
      {
        "uuid": "9ebca3c71bab4b518796bd4ed4704b6d",
        "rank": "OFFICER",
        "joined": 1463510760846
      },
      {
        "uuid": "3204cdd57d0d485987f1077524d43e05",
        "rank": "OFFICER",
        "joined": 1466438055992
      }
    ],
    "name": "Vape Nation",
    "vipCount": 5,
    "mvpCount": 6,
    "canTag": true,
    "tag": "KLOON",
    "canParty": true,
    "dailyCoins-17-9-2017": 750
  }
}

You can see that you can find the amount of coins a specific player has earned under a player in the members object of the guild. I'm certain there's a function along the likes of getMembers() on a Guild object. What's your full code?

idavydoff commented 6 years ago

I am trying to do a table where ppl can see how many g coins other members earn today.

<?php
                        if ($guild != null) {
                            $memberList = $guild->getMemberList();
                            foreach ($memberList->getList() as $rank => $members) {
                                  foreach ($members as $member) {
                                      $player = $member->getPlayer();
                                      if ($player == null) continue;
                                      echo '<tr class="playerInfo">';
                                      echo '<td style="display: none;">uuid_' . $player->getUUID() . '</td>';
                                      echo '<td><img class="member-list" src="http://cravatar.eu/helmavatar/'. $player->getName().'/32" /></td>';
                                      echo '<td><b><a href="https://namemc.com/profile/'.$player->getName().'">'.$player->getFormattedName().'</a></b></td>';
                                      echo '<td>' . $rank . '</td>';
                                      echo '<td>'. $memberList->getInt('dailyCoins-16-9-2017') .'</td>';
                                      echo '<td>' . date('Y/m/d H:i:s', $member->getJoinTimeStamp() / 1000) . '</td>';
                                      echo '<td>' . date('Y/m/d H:i:s', $player->get('lastLogin') / 1000) . '</td>';
                                      echo '</tr>';
                                      echo '<tr style="height: 0;" id="uuid_' . $player->getUUID() . '">';
                                      echo '<td colspan=5 style="padding: 0 0;"></td>';
                                      echo '</tr>';
                                  }
                              }
                            }
                    ?>
idavydoff commented 6 years ago

Everything works fine except g coins :p

MaxKorlaar commented 6 years ago

Oh, the problem is quite simple. You might spot it yourself if you add var_dump($player); after the continue; bit. It will dump your player object and you'll see that there are only the daily coins for 17-10-2017 and a few days back. It doesn't go back a full month, I believe.

MaxKorlaar commented 6 years ago

Oh and you're doing $memberList->getInt but you should be doing it on either the $player or the $member. var_dump the $member object to find out which one.

idavydoff commented 6 years ago

var_dump($player) and var_dump($member) are the same and return mini games stats. I did var_dump($members) and get very large array with things like this image

idavydoff commented 6 years ago

How can I echo it?

MaxKorlaar commented 6 years ago

You're looking at it wrong. You're trying to get the coin history from the $members, because you think it's a direct property of the $members object. $members however is an array, and if you look closely at the array you can see that for each member in the array, in your screenshot the 23rd member, the property 'coinHistory' is a thing.

You'll have to use $member in your foreach loop. Try var_dumping $member->coinHistory for example.

idavydoff commented 6 years ago

don't work image

MaxKorlaar commented 6 years ago

Yes, it doesn't. But do you see that you've got the right object now? I'm certain there is a function that belongs to the GuildMember object which allows you to request the coin history. Can you look at the source code for the GuildMember class and look for the function that allows you to request the coin history? It should be a public function, and you can use it on the $member object :)

idavydoff commented 6 years ago

source code in hypixel api?

MaxKorlaar commented 6 years ago

Yes. I think the file is also named 'GuildMember.php'

idavydoff commented 6 years ago

this file? https://github.com/Plancke/hypixel-php/blob/master/src/responses/guild/GuildMember.php

idavydoff commented 6 years ago

but I am using this old api ;p https://github.com/Plancke/hypixel-php/tree/old

MaxKorlaar commented 6 years ago

Oh, all classes are in one file in the old wrapper. I've highlighted the class for you: https://github.com/Plancke/hypixel-php/blob/old/HypixelPHP/HypixelPHP.php#L2106-L2164

idavydoff commented 6 years ago

Did this $member->getCoinHistory() and I am getting an array. How can I get something from this?

idavydoff commented 6 years ago

right?

    <?php 
            $mcoins = array($member->getCoinHistory());
            foreach($mcoins as $value){
                echo "$value[0] <br>";
            }
    ?>
MaxKorlaar commented 6 years ago

Try var_dumping $value, I'm not sure why you're selecting the first item of it but if it works you're right.

MaxKorlaar commented 6 years ago

Wait, why are you putting $member->getCoinHistory() inside an array? It is already an array. Now you're just nesting it:

[
  0 => (another array containing the actual coin history)
]
idavydoff commented 6 years ago

Got it

<?php
foreach($mcoins as $value){
    echo $value;
} 
?>

But How to add it to this table rn xd image

MaxKorlaar commented 6 years ago

Try using foreach($mcoins as $date => $value) {} and var_dump($date). Then you'll have to figure out which date is equal to today's date.

Anyway, I can't help you from here on because now it's relatively simple PHP programming and I've got other programming work to do 😛

idavydoff commented 6 years ago

k thx