question

Ritik Agarwal avatar image
Ritik Agarwal asked

Trading of virtual currency via cloud script

I got to know that we can trade virtual currency b/w two players via cloud script.
Can any one told me how can I make a cloud script for trading of virtual currency?

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

·
Sarah Zhang avatar image
Sarah Zhang answered

If you want to use CloudScript or AzureFunctions to implement this feature. As the answer in your previous thread said, you need to use Server API AddUserVirtualCurrency, SubtractUserVirtualCurrency to handle the exchanges of the User VC. Suppose two players A and B want to exchange VC. The possible workflow would like this.

  1. Player A passes the offered VC and requested VC, Player B’s PlayerId to CloudScript.
  2. CloudScript writes the trade info in Player B’s User Read-Only data.
  3. Player A tells Player B there is a trade.
  4. If Player B accepts this trade, B sends the accept request to CloudScript.
  5. CloudScript read its Read-Only Data then uses the AddUserVirtualCurrency and SubtractUserVirtualCurrency API to complete the exchange.

In the above process, you need to make at least two CloudScript functions. One function used to handle the trade request. Another one used to handle the trade acceptation and exchange the players’ VC.

Except using CloudScript, you can also consider using PlayFab native trade API to implement such VC trades. Please check this document for more info about PlayFab Trading. The API is designed to trade the item instances of players. If you want to trade VC, you can add the VC to the Container to create several types of VC packs. Players can purchase the corresponding VC pack firstly, then use the trade API to do the trade. The possible workflow could like this.

  1. Before trading, Player A purchases the corresponding VC containers.
  2. Player A uses OpenTrade to open a trade to give the VC containers instances to Player B.
  3. Player A tells Player B there is a trade.
  4. Player B uses AcceptTrade to accept the trade.
  5. Player B uses the UnlockContainerItem to unlock the containers and get the VC.
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.