x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

How to retrieve and iterate through steam friends

So, I'd like to retrieve the steam friends of a user. I'm using GameSparks for session handling and only integrated steam so users can authenticate with it. Oddly, GameSparks only stores avatars of friends who haven't played the game yet. You apparantly can only retrieve the user name through a GS ListGameFriends request. So I'll probably have to retrieve all steam friends, filter those who have already played the game and then retrieve the avatar through the steam api.... (if you know a better way, please tell me).

However, I haven't found a function to actually get all friends of a user. ISteamUser is supposed to have a getFriendList function, but it's not showing up for SteamUser(). SteamFriends() also don't have a fitting function (there's only one where you can count friends, but it needs an iterator I cannot create).

Thanks in advance.

Product Version: UE 4.18
Tags:
more ▼

asked May 31 '18 at 06:41 PM in C++ Programming

avatar image

Natural Games
55 7 11 13

avatar image phil_me_up May 31 '18 at 11:41 PM

but it needs an iterator I cannot create

Why can't you create this iterator?

avatar image Natural Games Jun 01 '18 at 07:39 AM

Well, the function I wanted to use is the GetFriendCount() function. I thought I could just use that as length and iterate through it, to then use the GetFriendByIndex() function to actually get the friends. But both functions require a EFriendFlags as iterator for the GetFriendCount function which also has to be the same value as for the GetFriendByIndex one. I'm just not sure if it is as easy as that: can you just create a flag, put it into the count function and that return value into the GetFriendByIndex? I'm a little bit confused about the function descriptions since it seems like it's already looping through all specified friends, but only returns one friend

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

So after some more research (the steam api docs are huge) I found a solution. I was actually on the right way. Here's my code:

 TArray<FSteamPlayer> AControllerFunctions::getSteamFriends(int offset) {
     
     // Array of all regular steam friends
     TArray<FSteamPlayer> friends;
     friends.Reserve(10);
 
     // Number of friends, used to break the loop
     int maxFriends = getSteamFriendsCount();
 
     // Empty CSteamID object to check if there's no friend to get left
     // You can't just check if it's null for some reason
     CSteamID zero;    
 
     // Temp var, holding the current friend from the loop
     CSteamID temp = SteamFriends()->GetFriendByIndex(offset, k_EFriendFlagImmediate);
 
     while (offset <= maxFriends || temp != zero) {
         
         temp = SteamFriends()->GetFriendByIndex(offset, k_EFriendFlagImmediate);
 
         // Create custom struct holding username and avatar
         FSteamPlayer steamplayer;
         steamplayer.username = SteamFriends()->GetFriendPersonaName(temp);
         steamplayer.avatar = getSteamAvatar(SteamFriends()->GetSmallFriendAvatar(temp));
         
         friends.Add(steamplayer);
         offset++;
     }
     
     return friends;
 }
 

 


more ▼

answered Jun 01 '18 at 09:44 AM

avatar image

Natural Games
55 7 11 13

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question