Hello, I am working on a multiplayer project with mirror networking, I am integrating the store with the ECONOMY service.
At the moment I managed to get the client to ask the cloud code for the bundle he wants to buy, but I need the reward not to be sent to my client but to be listened by the server to process the items and deliver them to the player.
Is this possible?
currently my cloud code is developed in JS.
Cloud code JS
const { PurchasesApi } = require("@unity-services/economy-2.4");
module.exports = async ({ params, context, logger }) => {
const { projectId, accessToken } = context;
const { playerId, bundleId } = params;
//PurchaseApi
const purchaseApi = new PurchasesApi(context);
var playerPurchaseVirtualRequest = {id: bundleId};
var productPurchase = {projectId, playerPurchaseVirtualRequest, playerId};
const purchaseResult = await purchaseApi.makeVirtualPurchase(productPurchase);
return {
playerId: playerId,
purchaseResult: JSON.stringify(purchaseResult.data)
//configItem : itemSelected
};
};
Hi @FabrizioRagaglia ,
I need the reward not to be sent to my client but to be listened by the server to process the items and deliver them to the player.
If I understand the question correctly, currently the client makes a Cloud Code request to a function that allows the virtual purchase of the given bundle on behalf of another player and what you would like to do is notify the recipient player that they have been rewarded the bundle so that their client is able to sync the changes.
If that is the case, I believe your current options are limited as unfortunately JS does not offer the same feature set as C# modules so all I can suggest is checking out the push client Send push messages to see if that would fit your use case, but that would mean that you’d need to migrate over to C#.
Otherwise, you could have the script make a request to a third party API (e.g. one that can handle push messages/ notifications), or the only other thing I can think to try (but would not be very efficient) is have the other player client periodically make a request to a service that could supply some information e.g. Cloud Save which could then be updated by your script.
1 Like