Jump to content

website


Recommended Posts

Moved to Developer Portal

•Intel® Core™ i7-6850K •Asus ROG Strix X99 Gaming •Asus ROG Strix GeForce GTX 1080 Ti OC 11GB •Corsair Dominator® Platinum Series 32GB DDR4 3000MHz C15 •Samsung 970 PRO NVMe M.2 512GB •Samsung 860 EVO 1TB 
•Corsair HX1000i High-Performance ATX Power Supply •NZXT Kraken X72 •Coolermaster MasterCase H500M
Link to comment
Share on other sites

You need to use PHP to connect to the TruckersMP API (seen here: https://stats.truckersmp.com/api) and use it to get the URL of api.truckersmp.com/v2/bans/{id} where {id} is your TruckersMP account ID (found by going to your account page on the website).

 

For example, my URL would be the following: https://api.truckersmp.com/v2/bans/1044649

 

This returns a bunch of JSON strings you can then parse using json_decode in PHP and detect whether or not "active" is set to true or false. I wrote a little example here:

 

<?php
	$baseURL = "https://api.truckersmp.com/v2/bans"; // Base URL, does not include player ID
	$playerID = "1044649"; // ID by itself makes it easier to change on the fly
	$fullURL = $baseURL."/".$playerID; // Putting the full URL together

	// Making call with cURL, assuming you have cURL installed (you should)
	$json = file_get_contents($fullURL);

	// Convert JSON to PHP Object
	$phpObj = json_decode($json);

	$banStatus = $phpObj->response[0]->active; // Checking the most recent ban to see if it's active or not
?>

 

Once you've done this, all you have to do is check whether or not the expiration date has passed the current date. If it has, they aren't banned. If it hasn't, they're still banned. Just make sure to account for timezone differences.

 

I've provided all you should need to at least get started. Good luck!

Edited by SDCore
Edited the "response" object
Link to comment
Share on other sites

19 hours ago, SDCore said:

I'm not 100% sure, as I've not worked extensively with the TruckersMP API, but I'm assuming if "active" on the most recent ban is false, it means you're still banned. If it's true, you aren't banned.

Wrong.

 

Active means the player was NOT unbanned before the ban expired. If it says it is not active, then teh player was unbanned early.

The ban can be active even if it has expired.

  • Upvote 1

HumaneWolf - Website - Twitter - GitHub

Ex-Developer

 

Link to comment
Share on other sites

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.