-
Notifications
You must be signed in to change notification settings - Fork 15
Player Request
You can get the information for a player by calling the player() method on the Client instance. This method takes 1 parameter which can either be the players SteamID64 or TruckersMP ID like so:
SteamID64
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player('76561198154335536')->get();TruckersMP ID
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player(28159)->get();This will return an instance of the Player model.
To get the data from the model, a number of helpful getters have been created as shown below.
| Method | Type | Description |
|---|---|---|
getId() |
int | The TruckersMP ID of the player requested |
getName() |
string | The players username |
getAvatar() |
string | The URL to the players avatar used on the website |
getSmallAvatar() |
string | The URL to the players small avatar (32px x 32px) |
getJoinDate() |
Carbon | The date and time the user registerd (UTC) |
getSteamID64() |
string | The players SteamID64 |
getGroupId() |
int | The ID of the group the player belongs to |
getGroupName() |
string | The name of the group the player belongs to |
getGroupColor() |
string | The hex colour of the players group |
isBanned() |
bool | If the user is currently banned |
getBannedUntilDate() |
?Carbon | The date and time the ban will expire (UTC) or null if not banned or ban is permanent |
hasBansHidden() |
bool | If the players bans are hidden |
isAdmin() |
bool | If the player is an admin or not |
getCompanyId() |
int | The players company ID |
getCompanyName() |
string | The players company name |
isInCompany() |
bool | If the player is in a company |
getCompanyMemberId() |
int | The players company member ID |
getDiscordSnowflake() |
?string | The players Discord Snowflake if set to public |
Below is an example of how you would get the players name:
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player(28159)->get();
echo 'The players name is ' . $player->getName();There are a few helpful methods which have been added to the Player model to perform additional requests. The following methods are available:
| Method | Type | Description |
|---|---|---|
getBans() |
BanCollection | Get the bans for the player |
getCompany() |
?Company | The players company or null if they are not part of one |
getCompanyMember() |
?CompanyMember | The player as a company member or null if they are not part of a company |
getCompanyRole() |
?CompanyRole | The players company role or null if they are not part of a company |
You can get the bans for the player by executing the following script, this will make 2 calls to the API and will return an instance of BanCollection. For more information on the BanRequest or Ban model, please refer to the Bans Request page.
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player(28159)->get();
$bans = $player->getBans();
$banCount = 0;
foreach ($bans as $ban) {
$banCount++;
}
echo 'This player has {$banCount} bans';If you would like to get the company which the player is part of, you can execute the following request. This will make 2 calls to the API and return an instance of the Company model. For more information on the CompanyRequest or Company model, please refer this Company Request page.
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player(28159)->get();
$company = $player->getCompany(); // Instance of `Company` model
echo $player->getName() . ' is part of ' . $company->getName();To get the player as a company member, you can execute the following request. This will make 2 separate calls to the API and return an instance of the CompanyMember model.
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player(28159)->get();
$member = $player->getCompanyMember(); // Instance of `CompanyMember` modelThe players company role can be got by executing the following, which will return an instance of the CompanyRole model. Please note this will call the API 3 times as we first need to get the member.
<?php
require_once('vendor/autoload.php');
$client = new TruckersMP\APIClient\Client();
$player = $client->player(28159)->get();
$role = $player->getCompanyRole(); // Instance of `CompanyRole` model
echo 'This player has the ' . $role->getName() . ' role.';If you have any questions about the library, you can create a topic on our forum.
This package is open-source and is licensed under the MIT license.