felixms / arma-rcon-class-php

A lightweight client for sending commands easily to a BattlEye server.
MIT License
46 stars 22 forks source link

getPlayerArray() format #29

Closed rruizrod closed 6 years ago

rruizrod commented 6 years ago

What exactly is the format of the array that is given when getPlayerArray() is called? I am trying to display the player list as a table on a control panel but for me to display them I need to know what the indexes are for the array. If you could please help it would be greatly appreciated.

felixms commented 6 years ago

TBH I don't exactly know anymore, but just use var_dump($array) to see the array and you'll know :)

rruizrod commented 6 years ago

How would I get it to show a full player list because at the moment it only shows the last person connected and not a list of all players. It seems as though the getPlayersArray() function prints to only one array

nerdalertdk commented 6 years ago

Sounds like and php problem and NOT an arc problem.

Show us your code ?

rruizrod commented 6 years ago
<?php 
                    try{
                        $rcon = new ARC($ip, $pass, $port);

                        $array = $rcon->getPlayersArray();
                        $array = $array["0"];
                        //print_r($array);
                        $id = $array['0'];
                        $ip = $array['1'];
                        $ping = $array['2'];
                        $guid = $array['3'];
                        $name = $array['4'];
                            //echo $id;
                        echo '  <table style="width: 100%; text-align: center; grid-area: table;">
                                    <tr>
                                        <th style="border: 1px solid black;">ID</th>
                                        <th style="border: 1px solid black;">IP</th>
                                        <th style="border: 1px solid black;">Ping</th>
                                        <th style="border: 1px solid black;">GUID</th>
                                        <th style="border: 1px solid black;">Name</th>
                                    </tr>
                                    <tr>
                                        <td style="border: 1px solid black;">' . $id . '</td>
                                        <td style="border: 1px solid black;">' . $ip . '</td>
                                        <td style="border: 1px solid black;">' . $ping . '</td>
                                        <td style="border: 1px solid black;">' . $guid . '</td>
                                        <td style="border: 1px solid black;">' . $name . '</td>
                                    </tr>
                                </table>';

                        $rcon->disconnect();
                    } catch (Exception $e){
                        echo "Ups! Something went wrong: {$e->getMessage()}";
                    }
                ?>

That is the code I have for it to show the player table on the page. As of right now it only shows the last person to have connected to the server.

felixms commented 6 years ago

By saying $array = $array["0"];, you just select the first element in the array, which is the reason why it shows only the last person to have connected. In order to show all players, you have to iterate over the array with a foreach loop.

nerdalertdk commented 6 years ago

Foreach($array AS $player) { var_dump($player); }

nerdalertdk commented 6 years ago

Also the number inside [] dont need ' or "

More info here https://www.google.dk/search?q=php+for+beginners