Hello! In my game, I want to make something like a referral system: assign each player a personal code, and every time someone uses someone else's code, the owner of the code will receive coins.
Can I do it with Playfab tools?
Let's assume the following algorithm of actions:
1) I give out a personal code to each player when they first enter the game: I need to make a request to the Playfab database from the client side to get a list of all codes to avoid a match when generating a new code. Then send the new code of the new player to his profile on Playfab.
2) When someone uses someone else's code, I have to go back to the Playfab database to find out if such a code exists and if so, to which player it belongs. After that, I need to issue the required amount of coins to the owner of the code.
3) At the same time, I need to block the players from using any codes several times - each player can use someone's code only once and get coins for it. But others can use the player's code an unlimited number of times and for each use he will receive coins.
Please tell me, did I present the algorithm of actions correctly? Tell me, what tools can I implement this? In particular, how can I search through the codes of all players or are there any other Playfab tools to make my task easier?
I hope for your answer.
Thank you!
Answer by Xiao Zha · Jun 20 at 09:39 AM
According to your description, the referral system can be implement with UGC.
>> 1) I give out a personal code to each player when they first enter the game: I need to make a request to the Playfab database from the client side to get a list of all codes to avoid a match when generating a new code. Then send the new code of the new player to his profile on Playfab.
When the player first enter the game, you can create a UGC Item with a unique code, then store the code in player data which you can achieve with Get User Data API.
>> 2) When someone uses someone else's code, I have to go back to the Playfab database to find out if such a code exists and if so, to which player it belongs. After that, I need to issue the required amount of coins to the owner of the code.
When someone use the code, you can search the UGC items to find out if the code exists, then use cloudscript to grant coins to the owner of the code.
>> 3) At the same time, I need to block the players from using any codes several times - each player can use someone's code only once and get coins for it. But others can use the player's code an unlimited number of times and for each use he will receive coins.
When a player uses a code, you can record the code in that player’s player data, and next time you use a code, you can check the code in player data to confirm whether the code has been used by the current player.