question

Noah Branham avatar image
Noah Branham asked

How would I get A user's online/offline status

Hi! I have the code below, and I would like to access if a user is online or offline on my friend's list. I currently have the friend's list actually working and allowing people to add eachother and they pop up on the list etc. But I was confused as to how I would check to see if the other person is currently logged in or not.

public void DisplayFriends(List<FriendInfo> friendsCache)
    {
        friendsCache.ForEach(f =>
        {
            GameObject Friend1 = Instantiate(Friend, Vector3.zero, Quaternion.identity);
            Friend1.transform.SetParent(FriendPanel.transform);
            Friend1.transform.localPosition = Vector3.zero;
            FriendUser.text = f.Username;
            //Friend's offline/online status.
            Debug.Log(f.Username);
        });
    }
Friends
1 comment
10 |1200

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

michaelbb avatar image michaelbb commented ·

Hi Noah,

how did you achieve it?

And Maybe you could also share how you achieved that both Players are Aware of each other.

Many thanks,

Michael

0 Likes 0 ·
Noah Branham avatar image
Noah Branham answered

I figured out how I would do this, but now was wondering how I would receive the player's avatar as an image?

1 comment
10 |1200

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

v-humcin avatar image v-humcin ♦ commented ·

If you don't mind can you share the solution you found as a reply to this question so that it may allow further discussion? Did you end up using player data?

Also could you also post your new question as a separate thread, it will make it easier to keep the conversations organized. Thanks!

0 Likes 0 ·
contrejo27 avatar image
contrejo27 answered

Since there's no answer I'm posting my approach. You can set your own entity object for your player entity that tells you if you are online or offline.

And this is a good reference to get started with setting entity objects.

https://docs.microsoft.com/en-us/gaming/playfab/features/data/entities/quickstart

       void SetOnlineStatus(bool isOnline)
        {
            var data = new Dictionary<string, object>()
            {
                {"Online", isOnline},
            };


            var dataList = new List<SetObject>()
            {
                new SetObject()
                {
                    ObjectName = "PlayerData",
                    DataObject = data
                },
                // A free-tier customer may store up to 3 objects on each entity
            };


            PlayFabDataAPI.SetObjects(new SetObjectsRequest(),
                result =>
                {
                    print(result);
                },
                error =>
                {
                    print(error);
                });
        }
10 |1200

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

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.