question

blazej avatar image
blazej asked

Gift System

Hi everyone! I have a question, would it be possible to make a gift system like in coin masters? (those where you send money to all or some friends) If so, how to do it? I mean sending to a given person or to all friends + showing gifts that can be take from a given friend. Greeting and hope for help! :)

Here are pictures of exactly what I mean:

https://support.coinmastergame.com/hc/article_attachments/360004333754/Screenshot_20180426-145625_Coin_Master.jpg

https://bestcmstrategies.com/wp-content/uploads/2019/10/addpeoplecoinmaster-577x1024.png

Player DataTrading
10 |1200

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

Simon Cui avatar image
Simon Cui answered

Yes. If you want to send and receive “money” as currency among friends(or given players), you can use CloudScript to do it securely, where you can call Server API including Add User Virtual Currency and Subtract User Virtual Currency functions.

Additionally, If you want to send “gift” which is an item, then you can use Trading related functions. For similar information, please refer to this case: Player Gifting another Player?

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.

blazej avatar image blazej commented ·

Okay and how can I do it in cloudscript? And how can I do that you can see from which player the gift comes? (ID is enough) Can you give an example or something? because im so bad in cloudscript coding haha

1 Like 1 ·
Simon Cui avatar image
Simon Cui answered

@Błażej Michacz

If you click the link of “CloudScript” that I mentioned above, you will see CloudScript Functions quickstart guide and CloudScript (Legacy) quickstart, either of which provides a simple guidance of CloudScript for beginners. CloudScript(Legacy) is easier to start. To execute CloudScript(Legacy) methods, you may refer to Executing CloudScript (Legacy) functions from a Unity game client. For further information, please refer to Writing custom CloudScript (Legacy) tutorial.

  • "how can I do that you can see from which player the gift comes?"

If you go to “Game Manager” -> “My Game” -> “Automation” -> “Cloud Script” -> “Revisions(legacy)”, you can see there is a variable named “currentPlayerId” inside “handlers.helloWorld”. The pre-defined "currentPlayerId" variable is initialized to the PlayFab ID of the player logged-in on the game client.

Supposing that first Player wants to send gift to second player:

In your client side, you can include a method of “Open Trade” API. Inside “Open Trade” API, you can set the PlayFabId of second player into “AllowedPlayerIds”. Then you can get the “result.Trade.TradeId” from the callback of “Open Trade” API. the first player can call “Execute Cloud Script” Client API to invoke your “Update User Read Only Data” CloudScript function and pass the “PlayFabId of second player” and “tradeId” to CloudScript function’s args. The second player can call “Get User Read Only Data” to get the key-value pairs data of “PlayFabId of the first player” and TradeID. By using “Accept Trade” Client API and set “PlayFabId of the first player” as “OfferingPlayerId” and “traded” as “TradeId”, the second player can accept trade.

In CloudScript side, you may set a handler that contains “Update User Read Only Data” Server API to set read only data for the second player including “currentPlayerId”(which is PlayFabId of the first player) and “TradeId”.

2 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.

blazej avatar image blazej commented ·

I've tried but I really can't do this part 'Supposing that first Player wants to send gift to second player'. Could you please give some sample cloudscript code that I could use? Thanks in advance.

1 Like 1 ·
Simon Cui avatar image Simon Cui blazej commented ·

You may refer to those links mentioned above. Additionally, if you are using CloudScript(legacy), you can refer to “Game Manager” -> “My Game” -> “Automation” -> “Cloud Script” -> “Revisions(legacy)”, where you can see some extra sample codes in there. Please let me know if you have any particular question about CloudScript after reading those documents.

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.