Jump to content

[RESOLVED] TruckersMPID about API or Logs - Problem


Recommended Posts

Hi guys,

Is there a way with PHP to find out his TruckersMPID using the InGame ID (1234)?

For example with the API: https://api.truckersmp.com/v2/servers/{server_id}/{ingame_id}

 

Since the API does not issue this option, I wanted to create this via the chat log of ETS2MP, but the logs are corrupted because PHP can not read the file properly.

 

Do you have a solution for my problem?

Link to comment
Share on other sites

8 minutes ago, JND_3004 said:

Hi guys,

Is there a way with PHP to find out his TruckersMPID using the InGame ID (1234)?

For example with the API: https://api.truckersmp.com/v2/servers/{server_id}/{ingame_id}

 

Since the API does not issue this option, I wanted to create this via the chat log of ETS2MP, but the logs are corrupted because PHP can not read the file properly.

 

Do you have a solution for my problem?

 

I do not have enough knowledge about PHP or API, but you can type "/pinfo ID" to learn the TruckersMP ID of a player. For example if you want to see the TruckersMP ID of the player "385", you can type "/pinfo 385" to see the player's TruckersMP ID. (Type without inverted commas.)

Link to comment
Share on other sites

Just now, BOSSENTERPRiSES said:

 

I do not have enough knowledge about PHP or API, but you can type "/pinfo ID" to learn the TruckersMP ID of a player. For example if you want to see the TruckersMP ID of the player "385", you can type "/pinfo 385" to see the player's TruckersMP ID. (Type without inverted commas.)

Thanks for your answer.

I also know that I could work in the game with /pinfo, but I would like to work with PHP, so in my case /pinfo unfortunately uses nothing.

 

Sorry for my english.

  • Upvote 1
Link to comment
Share on other sites

But can not something like that be included in the API?

 

4 hours ago, scarface0359 said:

This isn't possible at the moment with the current API.

I know ..

 

3 hours ago, CJMAXiK [RU] said:

You can do this using ETS2Map API, but there is no public API for that, so...

Yes, unfortunately :/

Link to comment
Share on other sites

  • 3 weeks later...

Hi, That's how I wrote it-to get how many players are online

//Must be jquery.min.js

var mp = {
  sersers: function() {
    $.getJSON('https://api.truckersmp.com/v2/servers', { }, function(data) {
      var result = data;
      var id = result.response[2]['id']; //respons['2'] - this server 1,2,3,4
      var players = result.response[2]['players'];
      if (id) {
        $('.onlinemp').find("#result").text(players);
        $('#count').text(declOfNum(players, ['player', 'player', 'players']));
      }
      setTimeout(function() {
        mp.sersers();
      }, 5000);
    });
  }
}
function declOfNum(number, titles) {
  cases = [2, 0, 1, 1, 1, 2];
  return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
}
<span class="onlinemp">Server status Europe 2: <span id="result"></span> <span id="count"></span> online</span>
<script type="text/javascript">
  mp.sersers();
</script>

 

Link to comment
Share on other sites

3 hours ago, Usersrrr said:

Hi, That's how I wrote it-to get how many players are online


//Must be jquery.min.js

var mp = {
  sersers: function() {
    $.getJSON('https://api.truckersmp.com/v2/servers', { }, function(data) {
      var result = data;
      var id = result.response[2]['id']; //respons['2'] - this server 1,2,3,4
      var players = result.response[2]['players'];
      if (id) {
        $('.onlinemp').find("#result").text(players);
        $('#count').text(declOfNum(players, ['player', 'player', 'players']));
      }
      setTimeout(function() {
        mp.sersers();
      }, 5000);
    });
  }
}
function declOfNum(number, titles) {
  cases = [2, 0, 1, 1, 1, 2];
  return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
}

<span class="onlinemp">Server status Europe 2: <span id="result"></span> <span id="count"></span> online</span>
<script type="text/javascript">
  mp.sersers();
</script>

 

 

Have you really read my post? i think no.

I will not results from player count from a server ...

 

Please read my start post ;)

Link to comment
Share on other sites

 

On 6/9/2017 at 4:32 AM, JND_3004 said:

Thanks for your answer.

I also know that I could work in the game with /pinfo, but I would like to work with PHP, so in my case /pinfo unfortunately uses nothing.

 

Sorry for my english.

Thanks for your answer.

I also know that I could work in the game with /pinfo, but I would like to work with PHP, so in my case /pinfo unfortunately uses nothing.

 

Sorry for my english.

Link to comment
Share on other sites

Its very easy to find out TruckersMP ID if you know the Player id & Server.
Here is the PHP code:

 

<?php
$give_pid = $_POST['p_id'];// Input this from html form.
$give_server = $_POST['server'];  // There can be multiple people with same pid on different servers. so we take server as input also

$url = "http://tracker.ets2map.com/v2/fullmap";
$response = file_get_contents($url);
$trucks = json_decode($response);

foreach($trucks->Trucks AS $truck){
	if($truck->p_id == $give_pid && $truck->server == $give_server){
		$find_mp_id = $truck->mp_id;
      $flag=0;
		break;
	}else{
      $flag=1;
}
if($flag != 1){
	echo $find_mp_id;
}else{
  echo "Not Found";
}
//SERVER ID can be found here https://api.truckersmp.com/v2/servers
?>

WARNING: The API that is returning server info shows wrong server id.

For all those who are saying its not possible.. please do some research. Then come to a conclusion.

  • Upvote 1
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.