question

Dusan Lazarevic avatar image
Dusan Lazarevic asked

How to take some action on player's inventory change?

I am working on a game for a client and he has some real gifts he'd like to send to players when they make some in-game purchases in virtual currency. For example, player earned some coins in game play and he enters the gifts shop, fills shipping info and makes e.g. "Gift card" purchase. Now my client wants some notification where he can get info about player name, his shipping details (stores as player data already), the purchased gift, etc...

Which strategy would you suggest me for such a scenario? I thought about making a Rule which fires when player specific inventory item added and then send email about that. Or maybe make a webhook to outside server? Or maybe run a cloud script, but don't have an idea yet what that script would do :)

Any ideas?

Thanks

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.

Dusan Lazarevic avatar image Dusan Lazarevic commented ·

In the meantime I learned that email notification isn't really possible. I took advice from another topic here, to make an admin account and attach contact email to it. Then I created Rule to execute cloud script which calls server.SendEmailFromTemplate through SMTP. Everything worked fine, except that email now contains info about admin player, and not the actual player that fired an event...

So, please, I need help for following scenario:

- Player purchases inventory item and pays with virtual currency

- I need an email notification sent to some admin email, containing player ID, inventory item info, event info, and potentially some other player's data

Is this possible?

0 Likes 0 ·
Citrus Yan avatar image
Citrus Yan answered

Hi @Dusan Lazarevic, sorry for this delayed reply,

As I see it, you want to manage sort of a list of the players (shipping info, player name, purchased gift, etc. ) who bought a certain gift so you can send them some real gifts, is that right? Making a Rule that acts on players’ inventory changes sound like a good approach to me, however, calling server.SendEmailFromTemplate in Cloud Script to send an email to an admin account is problematic:

It loses the context of the event fired by the actual player, for instance, you cannot access the variables such as the name of the purchased gift ( $Event.ItemId or $Event.DisplayName, depending on your settings) in that event.

What I suggest is using Webhook calls in Cloud Script to push the info to your custom server:

  1. Use Rule to act on players’ inventory changes (triggered by the player_inventory_item_added event), the Action is “Execute Cloud Script”.
  2. What the Cloud Script Function does is:
    1. Gather player’s info (shipping info, player name, purchased gift, etc. ), most of the info can be retrieved from the context of the Cloud Script function, the context looks similar to this:
{
      "playerProfile": {
        "DisplayName": "test",
        ...
        
      "playStreamEvent": {
        ...
        "DisplayName": "My first item",
        ...
        "ItemId": "One",
        ...
      },
      "triggeredByTask": null
}

You can retrieve the player name (it’s in playerProfile.DisplayName), purchased gift name (playStreamEvent.DisplayName or playStreamEvent.ItemId depending on your own settings ), for shipping details, you may need to call GetUserData to retrieve it since you mentioned that it’s stored as player data.

2. Make a webhook call with the gathered info to your external server, the server is responsible for managing players' info.

Please feel free to reach to us if you have any questions about the process.

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

Dusan Lazarevic avatar image Dusan Lazarevic commented ·

Thank you @Citrus Yan

That’s exactly what I did, please check my cloud script for sendWebHook function :) And I also attached it to a rule, as you suggested

Best and thanks again

0 Likes 0 ·
Citrus Yan avatar image Citrus Yan Dusan Lazarevic commented ·

Sounds great! By the way, I cannot check your cloud script since I don't know your title id:(

0 Likes 0 ·
Dusan Lazarevic avatar image Dusan Lazarevic Citrus Yan commented ·

Ah, sorry, it's BEA20 :)

0 Likes 0 ·
Dusan Lazarevic avatar image
Dusan Lazarevic answered

@Citrus Yan Can you please check my recent logs, I constantly get CloudScriptExecutionTimeLimitExceeded error, though I changed nothing in the script and it does nothing special to cause excessive execution time. It shouldn't run more than 0.01 secs :)

Function: sendWebHook

Title: BEA20


Thanks

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.