Is there a way to determine Programmatically, in JS, (1) The current User’s
GamerTag (2) The MSFS Product type ( Base / Premium / Deluxe) ? (3) MSFS
Version #
Hello @N6722C I’m sorry but there is no official way of gathering those
informations. Best regards, Yohan
Thank you for that information,
The API call used by the Nameplates (aka InGameMarkers) returns everyone
else’s Xbox gamertag, so there might be some convoluted scheme where you can
get that to return the tag for the in-sim pilot. The current combo of the
map’s GET_AIR_TRAFFIC (locations but no info about the planes/users) and the
API call used by InGameMarkers (xbox name, altitude, plane type, but no
location) is just enough to not be useful and the data can’t be joined up. If
it is improved with a single API call, my plea would be to add ATC ID to the
data (so plane_type, lat/long/alt, atc_id, xbox_id). After that I could use
the velocity vectors and maybe an on_ground indication so I could predict
where the plane is between samples.
It was Benjamin Franklin who first said, “ You can do anything you set your
mind to ”. In many cases, this also applies to MSFS – with a little work
and thinking “outside the box”.
Obviously there’s a way to do it - I don’t see call signs in GET_AIR_TRAFFIC though, and InGameMarkers doesn’t seem like something I can access from Javascript. Anybody interested in clarifying further or will this remain a mystery for the uninitiated?
Hello everyone,
For obtaining the user’s gamertag, you have to register a CommunityListener (aka JS_LISTENER_COMMUNITY
) in JavaScript, and bind a function to the SetGamercardInfo
event, in order to trigger the data request. You can gather not just the user’s gamertag but also the MSFS build version number if you require it as well. I used this function on my EMB-110 for the EFB to gather the sim’s version number.
I will post an example of this call later, once I am on my computer, since I am replying from my phone right now.
Regards,
Carlos Daniel Gonzalez Gomez
NextGen Simulations
Hello everyone,
As I stated some hours ago (BTW please apologies for the long delay in my reply), here is an example of how you can use the CommunityListener
, so that you can gather the user’s gamertag.
Include.addScript("/JS/common.js"); // Do not forget this include, if you do not have the respective include in the HTML instrument you are targeting the listener for.
Include.addScript("/JS/Services/Community.js"); // This include is for the RegisterCommunityListener function, if you want to use it. Please see below.
class MyInstrument extends BaseInstrument {
constructor() {
super();
this.communityListener = null;
}
connectedCallback() {
super.connectedCallback();
// Initialize Community Listener
// Either using the RegisterCommunityListener function from the /JS/Services/Community.js file
this.communityListener = RegisterCommunityListener(() => { console.log("JS_LISTENER_COMMUNITY registered"); });
// Or, using the common RegisterViewListener function from /JS/common.js
// this.communityListener = RegisterViewListener("JS_LISTENER_COMMUNITY", () => { console.log("JS_LISTENER_COMMUNITY registered"); });
this.communityListener.onSetPlayerData(this.setPlayerData.bind(this));
// The above call is the equivalent of the following call:
// this.communityListener.on("SetGamercardInfo", this.setPlayerData.bind(this));
}
setPlayerData(data) {
console.log(data); // This will help you with the properties returned by the CommunityPanelPlayerData object
console.log(data.sName);
console.log(data.sBuildVersion);
// TODO: whatever you require to do with the instrument, from the data gathered.
}
disconnectedCallback() {
super.disconnectedCallback();
this.communityListener.unregister();
this.communityListener = null;
}
}
The more relevant properties from the CommunityPanelPlayerData
object (for our development context) are:
- sBuildVersion: it is the sim’s version in the following format: X.X.X.X, so for the current stable version, it would be 1.37.19.0
- sName: this is the one you are looking for, and is indeed the user’s gamertag.
Please let me know if this works for you guys (@N6722C and @jweather).
Regards,
Carlos Daniel Gonzalez Gomez
NextGen Simulations
Looks very familiar, have been using that for over a year now.
I think it was you that 1st told me how to do it years ago !!
Thanks