Economy v2 is now Generally Available. For support and feedback, go to the PlayFab Forum.
- Defines loot tables with weighted item pools in Title Data.
- Uses an Azure Function to roll random items from a loot table.
- Atomically subtracts a container token and grants the randomly selected items in a single call.
How it works
- Define loot tables in Title Data: Store your drop table configurations (item IDs, weights, quantities) as JSON in Title Data so you can update them without redeploying code.
- Represent containers as virtual currency: Use the same container token pattern as fixed-contents containers: a virtual currency that acts as an unopened loot box.
- Call an Azure Function to open the container: The function reads the loot table, runs weighted random selection, then calls
ExecuteInventoryOperationsto atomically subtract 1 container token and add the randomly selected items.
Prerequisites
- A PlayFab developer account.
- A title created in Game Manager.
- Published catalog items that you can grant as loot rewards.
- A virtual currency representing the container (see Containers with fixed contents for setup instructions).
- An Azure Functions project connected to your PlayFab title.
Step 1: Define loot tables in Title Data
Store your loot table definitions in Title Data so designers can update drop rates without code changes.Example loot table structure
Create a Title Data key calledLootTables with a JSON value:
Setting Title Data
Game Manager
- Go to Content > Title Data.
- Create a key called
LootTables. - Paste your JSON loot table configuration as the value.
- Select Save.
API
Use SetTitleData:Step 2: Create the Azure Function
Create an Azure Function that your game client calls when a player wants to open a container. The function:- Verifies the player has at least one container token.
- Reads the loot table from Title Data.
- Runs weighted random selection.
- Calls
ExecuteInventoryOperationsto atomically subtract the token and grant the rewards.
Data models
Weighted random selection
Full Azure Function
The
GetContainerCurrencyId helper function maps a loot table name to its corresponding container currency ID. You can store this mapping in Title Data alongside the loot tables, or use a naming convention.Step 3: Grant container tokens to players
Grant container tokens to players through gameplay, store purchases, or rewards. Use the same approach described in Containers with fixed contents.Step 4: Call the function from your game client
When the player wants to open a container, call the Azure Function by using ExecuteFunction:Loot table design patterns
Rarity tiers
The classic rarity system with exponentially decreasing weights:- Common: ~90.0%
- Uncommon: ~9.0%
- Rare: ~0.9%
- Legendary: ~0.09%
Multi-roll with mixed rewards
A supply crate that gives three random items from a mixed pool:Guaranteed + random (pity system)
For a “guaranteed rare or better every 10 opens” pattern, track the player’s open count in Display Properties or Player Data, and override the random selection in the Azure Function when the threshold is reached.Nested drop tables
A loot table can reference another loot table by ID. Your Azure Function resolves the reference recursively:ItemId starts with TABLE: and, if so, rolls on the referenced table instead of granting the item directly.
Security considerations
- Always run loot logic server-side in an Azure Function. Never trust the client to determine which items were rolled. This approach prevents manipulation.
- Use
IdempotencyIdon theExecuteInventoryOperationscall to prevent duplicate grants if the function is retried. For more information, see Idempotent transactions and retries. - Validate container ownership by checking the player’s inventory before subtracting. The
Subtractoperation inExecuteInventoryOperationsfails if the player doesn’t have enough tokens, which rolls back the entire batch. - Log all rolls for auditing. The function’s return value and PlayStream events provide a trail of what each player received.
