When we are making a social leaderboard request, we also want to get the leaderboard data for a specified player.
In our game we have an AI character who appears as a friend of the player within the game. This character has a GameSparks account and we wish to include this character when requesting social leaderboard data. Since this AI character is not real, we can't add the character as a friend of the player within GameSparks (or I am wrong here, would it be possible to have this account automatically become a friend of the player when they register?).
The only option we can see here is to make a social leaderboard request and then make another leaderboard request for the AI character. The problem with this is that the returned ranks are localised. I.E. PlayerA may be ranked 20th globally, but is the top amongst their friends, so their returned rank for the social leaderboard request will be 1. This means that we would need to sort them manually ourselves client-side. This introduces potential issues if we change now leaderboards are sorted, we'd need to do this in both code and GameSparks dashboard.
Any suggestions would be appreciated, thanks!
To have the AI player to appear as a friend they would need to be in a team with a player that was marked as "Social". Players in a team set up this way will be regarded as friends of the owner and would then show up in the social leaderboard results. You can read more about teams here. If you have any further questions just let us know.
Is it possible to add a player to a Team without needing to send them a request?
I guess for the above solution to work, I would need to create a team for each player and add the AI player to that team when the player registers, so is this possible to do automatically without the requirement of sending a request to the AI player and then accepting it?
The other way of doing it is to have one team with the AI player as the leader, and add all other players into it, but if the team is a social team (which is what is required here I believe), then that would make all players within it friends of each other, is that correct?
You can add players dynamically into a team with SparkTeam.addMembers. I've provided the documentation here: https://docs.gamesparks.com/api-documentation/cloud-code-api/player/sparkteam.html#addmembers
Hope this helps,
Oh great, I incorrectly thought you needed to get the player's permission before they could be added to a team.
No problem we're glad to help,