I want to purchase the number of several in the same ItemID.
There is no variable to use the PurchaseItem function.
Is there another way?
I want to purchase the number of several in the same ItemID.
There is no variable to use the PurchaseItem function.
Is there another way?
Currently, there are 2 work around solutions, and you are able use either of them in Cloud Script:
Sending a feature request or voting for an existing one on the forum will always be appreciated and more votes from other users can help with the priority.
Here's my Cloudscript implementation of SethDu's first bullet. (Although it does not meet the requirements of the OP's request to purchase multiple of the same product.)
handlers.PurchaseItems = function (args) { const itemListArray = args.itemList; const itemListSet = new Set(itemListArray); const clientPrice = args.price; // 1. get all catalog items let catalog; try { catalog = server.GetCatalogItems({}).Catalog; } catch(e) { return 500; } // 2. for each passed item, total the prices from the catalog let serverPrice = 0; for (let catalogItemIndex = 0; catalogItemIndex < catalog.length; catalogItemIndex++) { if (itemListSet.has(catalog[catalogItemIndex].ItemId)) { serverPrice += catalog[catalogItemIndex].VirtualCurrencyPrices.yourVirtualCurrency; } } // 3. compare the passed price to the actual price if (serverPrice != clientPrice) { return 1053; } // 4. make sure the player has enough virtualCurrency const getPlayerCombinedInfoRequest = { "PlayFabId": currentPlayerId, "InfoRequestParameters": { "GetUserVirtualCurrency": true } }; let virtualCurrencyBalance; try { virtualCurrencyBalance = server.GetPlayerCombinedInfo(getPlayerCombinedInfoRequest).InfoResultPayload.UserVirtualCurrency.yourVirtualCurrency; } catch(e) { return 500; } if (virtualCurrencyBalance < serverPrice) { return 1059; } // 5. grant items const grantItemsToUserRequest = { "ItemIds": itemListArray, "PlayFabId": currentPlayerId } try { server.GrantItemsToUser(grantItemsToUserRequest); } catch(e) { return 500; } // 6. subtract virtual currency const subtractUserVirtualCurrencyRequest = { Amount: serverPrice, PlayFabId: currentPlayerId, VirtualCurrency: "yourVirtualCurrency" } try { server.SubtractUserVirtualCurrency(subtractUserVirtualCurrencyRequest); } catch(e) { return 500; } return 200; };
3 People are following this question.