<?php require_once "../src/tmpapilib.php"; //Include the library file. use truckersmp\tmpapilib as truckersmp; //Tell PHP to use the library namespace. $api = new truckersmp(); //Load the class into a variable, as defined by "use" above. $servers = $api->servers(); //Use the class variable to access one of the class functions. echo "<h1>Servers:</h1>"; foreach ($servers['response'] as $v) { //Foreach to loop through all servers supplied by the API and print their statuses. if ($v['online'] == TRUE) { $online = "Online"; } else { $online = "Offline"; } echo "<p>" . $v['game'] . " " . $v['name'] . ":" . $online . "(" . $v['players'] . "/" . $v['maxplayers'] . ")" . "</p>"; } echo "<hr>"; var_dump($servers); //Dumping all of the information so you can see what is available.
<?php require_once "../src/tmpapilib.php"; //Include the library file. use truckersmp\tmpapilib as truckersmp; //Tell PHP to use the library namespace. $api = new truckersmp(); //Load the class into a variable, as defined by "use" above. $time = $api->game_time(); //Use the class variable to access one of the class functions. echo "<p>Year-Month-Day Hours:Minutes</p>"; echo "<p><b>Current Game time:</b> " . $time['years'] . "-" . $time['months'] . "-" . $time['days'] . " " . $time['hours'] . ":" . $time['minutes'] . "</p>"; echo "<hr>"; var_dump($time); //Dumping all of the information so you can see what is available.
<?php require_once "../src/tmpapilib.php"; //Include the library file. use truckersmp\tmpapilib as truckersmp; //Tell PHP to use the library namespace. $api = new truckersmp(); //Load the class into a variable, as defined by "use" above. $version = $api->version(); //Use the class variable to access one of the class functions. echo "<p><b>TruckersMP Version:</b> " . $version['name'] . "</p>"; echo "<hr>"; var_dump($version); //Dumping all of the information so you can see what is available.
<?php require_once "../src/tmpapilib.php"; //Include the library file. use truckersmp\tmpapilib as truckersmp; //Tell PHP to use the library namespace. $api = new truckersmp(); //Load the class into a variable, as defined by "use" above. $thisplayer = $api->player(1); //Use the class variable to access one of the class functions, loading the player with ID 1. Also works with SteamID64. echo "Player 1 is " . $thisplayer['response']['name'] . '<br>'; //Write the information about Player 1 to the document. echo "(S)He is a " . $thisplayer['response']['groupName'] . '<br>'; echo "<hr>"; var_dump($thisplayer); //Dumping all of the information so you can see what is available.