joshuaferrara / node-csgo

A node-steam plugin for Counter-Strike: Global Offensive.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Problem with friend and playerProfileRequest

prugala opened this issue · comments

Hello

I have a problem with event friend and getting player.

My friend event:

steamFriends.on('friend', function(userId, relationship) { 
    if (relationship == 2 && !_.contains(secrets.blacklist, userId)) {
        steamFriends.addFriend(userId);

        setTimeout(function() {
            steamFriends.sendMessage(userId, 'Hello');
            setTimeout(function() {
                CSGO.playerProfileRequest(CSGO.ToAccountID(userId));
                CSGO.on("playerProfile", function(profile) {
                   steamFriends.sendMessage(userId, 'test');
                });
            }, 2000);
        }, 3000);
    }
});

and when I first time add bot he send me: Hello and test, but when I remove him and add again he send me Hello, test, test.
If I again remove and add him he send me Hello, test, test, test

Why? How can I get fix it?

commented

You're subscribing to 'playerProfile' event every time. Move 'CSGO.on("playerProfile"...' outside.

commented

Also this is not problem with node csgo, you should ask questions like this in gitter.

OK next time I ask in gitter. U said "Move 'CSGO.on("playerProfile"...' outside" but I need playerProfile for friend userid not bot.

commented

What you want is callback. For now it doesn't work but someone said it should. If you will move subscribe upper you'll still be able to get steamid from response.

commented

What are you doing now is quit hopeless. You can't get users profile if he bot in csgo. You better subscribe on gamesplayed event(not sure not how it called, but it contains info about game that friend opening).

Hmmm but for CSGO.playerProfileRequest(CSGO.ToAccountID(userId)) I need SteamID added friend, so how I can give it outside friend event?

For checking player profil I have if:

CSGO.playerProfileRequest(CSGO.ToAccountID(userId));
                CSGO.on("playerProfile", function(profile) {
                   if (profile.account_profiles.length > 0) {
                                 steamFriends.sendMessage(userId, 'test');
                               }
                            }

If array account_profiles is empty player dont have a csgo launched :)

The profile returned in the playerProfile event will contain account_id

Run the correct conversion on that and you'll be able to obtain their userId that you use to send them a message.

Therefore, you can move CSGO.on("playerProfile", ... out of steamFriends.on('friend'

Also, like @TrueCarry said: please use Gitter to ask about programming questions. Issues are reserved for bugs within node-csgo. Plus, more people are available within the Gitter channel. 👍

Example

CSGO.on("playerProfile", function(profile) {
       var accountId = profile.account_profiles[0].account_id;
       // Convert to correct format for userId here.
       steamFriends.sendMessage(userId, 'test');
});

steamFriends.on('friend', function(userId, relationship) { 
    if (relationship == 2 && !_.contains(secrets.blacklist, userId)) {
        steamFriends.addFriend(userId);
        setTimeout(function() {
            steamFriends.sendMessage(userId, 'Hello');
            setTimeout(function() {
                CSGO.playerProfileRequest(CSGO.ToAccountID(userId));
            }, 2000);
        }, 3000);
    }
});