question

Kim Strasser avatar image
Kim Strasser asked

How can I create a close friends system with PlayFab?

At the moment, I use PlayFabClientAPI.AddFriend with FriendTitleDisplayName in my game when player A wants to add player B to his friends list. player A needs to write player B's DisplayName in a text box. Any player can add any other player to his friends list. The player can use this friends list to compare his statistics with the other players statistics in the friends list. The players in the friends list don't get notified that they were added by a certain player because it's not necessary that they know it.

But I want to create some features that are restricted to close friends only. In addition, if player A sends a close friends request to player B then player B needs to accept it in order to get close friends. In addition, if player A is not yet in player B's friends list, then player A should automatically be added to player B's friends while accepting player A's close friends request. If player B declines the request, then they are not close friends and player B will not automatically add player A to his friends list. In both cases, player A should get a response so that he knows if player B accepted or declined the close friends request.

Close friends restricted features:

I want that close friends can invite each other to participate in special challenges during events in my game. It's necessary that player A accepts player B's challenge invitation in order that the challenge gets started for both players. player B should get notified if player A accepted or declined the challenge invitation. In addition, each player needs to pay 500 Gold Coins as participation fee when the challenge gets started. The challenge can not be started when one or both players have not enough Gold Coins.

For example, I want to create the following challenge during my events: The player(player A or player B) with the highest score in the global leaderboard at the end of the event wins 1000 Gold Coins.

The global leaderboard is active and all title players can add scores from the start time of the event until the end time of the event. The challenge between two players doesn't affect the global leaderboard. I just want to compare player A's and player B's score at the end of the event if they started a challenge and the winner gets a 1000 Gold Coins reward. The global leaderboard's rewards are different and don't affect the challenge's reward.

It should only be possible to send a challenge invitation to a close friend and during the event is running. I store the start time and the end time of my leaderboard events in my PlayFab Title-->Content-->Title Data.

Is it possible to create a close friends system with the current PlayFab APIs? Would it be possible to distinguish between a close friend and a normal friend when I call PlayFabClientAPI.GetFriendLeaderboard to get the friends scores?

How can I create the request and send the notification when a player wants to get close friends with another player?

How can I create the challenge invitation and send the notification when a player wants to start a challenge with a close friend?

Leaderboards and StatisticsFriends
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Made Wang avatar image
Made Wang answered

>>Is it possible to create a close friends system with the current PlayFab APIs?/How can I create the request and send the notification when a player wants to get close friends with another player?

You can refer to Two-way friend confirmation with Cloud Script - Playfab Community to implement two-way adding friends. Then you can add tags to friends to distinguish between close friends and normal friends. Regarding sending notifications, you can use PlayFab's notification push, or use a third-party plugin as mentioned in the thread.

>>I want that close friends can invite each other to participate in special challenges during events in my game./How can I create the challenge invitation and send the notification when a player wants to start a challenge with a close friend?

You can use Lobby to implement invitations and real-time notifications. But currently Lobby has no SDK for mobile. If you are developing on mobile, you can refer to Building Lobbies with Azure PlayFab to manually implement Lobby.

>>I want to create the following challenge during my events: The player(player A or player B) with the highest score in the global leaderboard at the end of the event wins 1000 Gold Coins.

If you want to get a specific two player's score in the leaderboard, then you can call GetPlayerStatistics for each player individually, and then manually award the reward.

>>Would it be possible to distinguish between a close friend and a normal friend when I call PlayFabClientAPI.GetFriendLeaderboard to get the friends scores?

GetFriendLeaderboard won’t filter by or return the friend tag, so you need to get the friend leaderboard first, then call GetFriendsList and get close friends through the tag, and then process these two sets of information manually to get the corresponding leaderboard.

5 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Kim Strasser avatar image Kim Strasser commented ·

I create a mobile game for Android and iOS. I'm not sure if I need a lobby because player A only needs to accept player B's challenge invitation by clicking on a button, they don't need to be online together at the same time. Player A should receive the invitation and the invitation should get stored somehow(in Player Title Data?) so that player A can accept or decline it when he wants. After player A clicked on the accept button the challenge immediately starts and player B should get a notification that the challenge has started. This notification should get stored as well so that player B can read the notification when he plays my game. If player A declined the challenge, then player B should get a notification that only informs him that the challenge was declined. In addition, a challenge invitation can only be sent and accepted/declined when the remaining time of an event is more than 24 hours.

Would it be possible to create a challenge limit for each player so that a player can not have more than 10 challenges simultaneously?

In addition, I don't want that player A can send a new invitation to player B until player B has accepted/declined player A's first invitation.

0 Likes 0 ·
Made Wang avatar image Made Wang Kim Strasser commented ·

I feel like the challenge you are talking about is a state, then you can use Azure Function Cloud Script to send invitations, store challenges and send notifications.

You can create two keys in the player data, one named "Invitation" to store received invitations, and one named "Challenges" to store currently accepted challenges, and can have the player's PlayFabId as the value. When sending an invitation, accepting an invitation and declining an invitation, cloudScript can update the player data of the corresponding player and send a notification.

When accepting an invitation, you can first get the challenges that the player has accepted and determine whether the number has reached the limit.

When player A sends an invitation to player B, CloudScript can obtain the invitation currently owned by player B, and if player A's invitation already exists, return the information that player A's invitation already exists.

0 Likes 0 ·
Made Wang avatar image Made Wang Made Wang commented ·

It should be added that there are some limitations in updating PlayData, which you can check in Game Manager->Title settings->Limits. And when multiple players send invitations to the same player at the same time, it may end up being only one player's invitation written correctly.

0 Likes 0 ·
Show more comments
Made Wang avatar image Made Wang Kim Strasser commented ·

As mentioned above, you can store the PlayFabId of the inviter in the player data. When you need to read these invitations, you can get these PlayFabId via GetUserData, and then generate information on the client side. The specific content needs to be implemented manually. If you need other information such as display name, then you can call GetPlayerProfile to get it.

If you have already stored the accepted challenges in your player data, then you can get this value and manually calculate the number of challenges you have accepted and compare it to the limits you set.

You can refer to the following format to store.

{
    "Invitations":
    {
        "PlayFabId A",
        "PlayFabId B",
        "PlayFabId C"
    }
}
{
    "Challenges":
    {
        "PlayFabId D",
        "PlayFabId E",
        "PlayFabId F",
        "PlayFabId G"
    }
}
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.