question

carlo.rodriguez08@gmail.com avatar image
carlo.rodriguez08@gmail.com asked

Save Player Stats before they disconnect or force quit game - PUN+ with PlayFab

I'm using PUN+ along with PlayFab and I am looking for a way to be able to save a player's stats in the case they get disconnected or pull the plug for whatever reason. I'm not entirely sure how I'd go about that and have tried looking for info on it, but to no avail. Am I supposed to store certain properties of the player in order to save their stats without them being in the game?

At the moment, the only way the stats save is if the match reaches the end, or if one player were to leave then the remaining player would win and their updated stats would be saved, but I'm unable to add the loss to the player who leaves.

Any help would be appreciated, thanks!

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

By Player Stats I assume you mean PlayFab's UserStatistics or any other user related data stored on PlayFab. I'm also guessing it's a 1v1 game.

At the moment, the only way the stats save is if the match reaches the end, or if one player were to leave then the remaining player would win and their updated stats would be saved, but I'm unable to add the loss to the player who leaves.

I think you are updating user data directly from client (using UpdateUserStatistics or UpdateUserData). I don't recommend that and I advise you to start using CloudScript instead. From CloudScript it should be easier to update both players data once you have their PlayFabIDs. You should just change the client API call with RunCloudScript and implement one or more CloudScript handlers.

It is also easy to detect that an opponent has left. You should receive an event in the player's client which is still connected and joined to the room. That's when you should update statistics.

In the future this process will be easier when Photon RealTime will support webhooks.

10 |1200

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

carlo.rodriguez08@gmail.com avatar image
carlo.rodriguez08@gmail.com answered

You're correct. It's a 1v1 game and the clients themselves are updating the stats. Under any normal circumstance, I would probably use CloudScripts, unfortunately, we do not have the budget to go through that pricing plan at the moment and were planning to go along with the Standard tier.

I understand that Photon has the OnPhotonPlayerDisconnect, but is there another way to do the update since I imagine in that case I'd have to have each player to keep track of the other player's stats, no? Also, how do I make sure the stats are being updated for the disconnected player and not the player still in the game?

10 |1200

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

Hamza Lazaar avatar image
Hamza Lazaar answered

Unfortunately you cannot update other players' data using client API methods.
You should find another way to do this.
Maybe use TitleData as temporarily holder of room leave events and player should query them once logged in. I'm not recommending anything however.
Good luck.

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.