question

accounts-5 avatar image
accounts-5 asked

ExecuteInventoryOperations in Rules

On player creation I want to grant items to a player using a rule. I'm using Azure CloudScripts and Economy V2.

As far as I understand, in rules I should use PlayerPlayStreamFunctionExecutionContext as context but where do I get the correct EntityId and EntityType for the ExecuteInventoryOperationsRequest.

I tried some things, including the Entity data in PlayStreamEventEnvelope but nothing seems to work.

EDIT: Just to clarify, the problem isn't getting the EntityId or EntityType out of PlayerPlayStreamFunctionExecutionContext but that it doesn't work when providing these values to the ExecuteInventoryOperationsRequest.

The values in PlayerPlayStreamFunctionExecutionContext look something like this.

Id: 6FF26F3FF7EC327B Type: player

I checked the Available Built-in Entity Types and "player" isn't even a real thing according to the page. Maybe that's the issue.

apisCloudScript
4 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.

Neils Shi avatar image Neils Shi commented ·

As you said, Azure Functions triggered by a Rule should use the PlayerPlayStreamFunctionExecutionContext context model which in the CS2AFHelperClasses.cs. Could you tell me how you got the EntityId and EntityType? And what is your error message?

0 Likes 0 ·
accounts-5 avatar image accounts-5 Neils Shi commented ·

Using the context as described above. Here are the logs for Id and Type.

Id: 6FF26F3FF7EC327B Type: player

0 Likes 0 ·
Neils Shi avatar image Neils Shi accounts-5 commented ·

This Id is actually a Master player account ID, the API ExecuteInventoryOperations need a Title player account ID, sorry for the misunderstanding before.

0 Likes 0 ·
Show more comments
Neils Shi avatar image
Neils Shi answered

Sorry for the misunderstanding before, the API ExecuteInventoryOperations need a Title player account ID, the previously mentioned "context. PlayStreamEventEnvelope.EntityId" is actually a Master player account ID. Cureently, we can't get Title player account ID directly. You should try to call GetTitlePlayersFromMasterPlayerAccountIds or GetAccountInfo API to get title player account id.

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.

accounts-5 avatar image accounts-5 commented ·

Alright, I'm gonna stick with GetTitlePlayersFromMasterPlayerAccountIds for now. Thanks for the help :)

0 Likes 0 ·
Neils Shi avatar image Neils Shi accounts-5 commented ·

I'm glad you solved it, feel free to let me know if there are any other questions.

0 Likes 0 ·
accounts-5 avatar image
accounts-5 answered

And here's an excerpt of the code, just in case I'm missing something:

             log.LogInformation($"Id: {context.PlayStreamEventEnvelope.EntityId}");
             log.LogInformation($"Type: {context.PlayStreamEventEnvelope.EntityType}");
    
             var executeInventoryOperationsRequest = new ExecuteInventoryOperationsRequest()
             {
                 Entity = new EntityKey()
                 {
                     Id = context.PlayStreamEventEnvelope.EntityId,
                     Type = context.PlayStreamEventEnvelope.EntityType
                 },
                 Operations = new List<InventoryOperation>
                 {
                     new()
                     {
                         Add = new AddInventoryItemsOperation()
                         {
                             Amount = 1,
                             Item = new InventoryItemReference()
                             {
                                 AlternateId = new AlternateId()
                                 {
                                     Type = "FriendlyId",
                                     Value = "avatar1"
                                 }
                             }
                         }
                     }
                 }
             };
    
             var executeInventoryOperationsResult = 
                 await economyApi.ExecuteInventoryOperationsAsync(executeInventoryOperationsRequest);
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.