Skip to content

Events

Subscribe with re.Events.On. All inventory events are server-side.

Event When
InventoryChanged { Changes } Items changed in an inventory. Triggered by moves, the game's changes to a player's items, your API calls
InventoryChangeRequested { Client, Changes } In approval mode only. Changes a client wants, waiting for your answer
PlayerInventoryCreated { Client, Inventory, ItemCount } A player's inventory was created by the host after the client joined
WorldInventoryCreated { Client, Inventory, Entity } A container or drop got its inventory. The place to seed or replace loot. A container's loot follows as Claimed changes (in approval mode once approved)
InventoryDestroyed { Inventory } An inventory is got destroyed. A container or drop that went away, or a player that left
InventoryUnlinked { Inventory, Entity } The entity your inventory was linked to is gone, the contents stay and the inventory can be re-linked
InventoryViolation { Client, Kind } A client did something a honest client probably does not do (see below)

InventoryChanged

One event per action. A take, drop, report of the player's game or API call can trigger this. Changes lists what happened, in order. Every change to any inventory's contents arrives here, also the ones your own bundle makes, so a bundle can keep a database "in sync" from this event alone.

An inventory destroy does not trigger a Removed. If you want to discard inventories from your DB that are destroyed (make sure you understand what destroyed means here), use the InventoryDestroyed event to get notified.

Each InventoryChange has:

Field Meaning
Kind What happened (table below)
Inventory The inventory that changed (Where the item went in case of a move aka. "Destination")
Item The item as that inventory stores it. Item.Quantity is how many came in or went out (0 for Updated and Generated)
Total How many of the item the inventory contains now. 0 means the stack is gone
Data That stack as GetItemData bytes, intended to be stored into databases. Empty when Total is 0
Source, SourceItem, SourceTotal, SourceData In case of a move this contains these "inventory data" where the item came from
Client The player whose action caused it. re.ClientId::Server() (65535/-1) if the change was triggered by the server API in a non player inventory. If you give an item into a player inventory, their client will process it and roll stats, so those changes that will then be triggered point to the player. Do validate that the player rolled sane stats
Kind Meaning Trust
Transfer Moved between two inventories (take, put, drop) Checked by the server
Added The player's game added an item (bought, crafted, rewarded), or your API added one Reported by the client
Removed The player's game removed an item (used, sold, consumed), or your API removed one Reported by the client
Updated An item's stats or mods changed, at the same quantity Reported by the client
Generated The game filled in an item the server made from its record (e.g. your AddItem), on its first report. Later changes are Updated Reported by the client
Initial What a player got from PlayerDevelopmentSystem when they first joined. Usually 3 pieces of clothing and some money Reported by the client
Claimed Loot a player's game rolled for a container or drop Reported by the client

Every type of event contains the item's current state in Item and Data. Updated and Generated are the kinds where only the state changed.

Item is what the inventory stores, which is not always what was asked for. Ammo put into a container joins a stack that is already there, and a unique item that collides with one already present gets a new counter. Use Item, Total and Data as they are and you stay consistent.

re.Events.On(
    "InventoryChanged",
    (re.InventoryChanged x) =>
    {
        foreach (var change in x.Changes)
        {
            Console.WriteLine(
                $"{change.Kind}: {change.Item.Record.Get():X} x{change.Item.Quantity} in {change.Inventory.Id}, now {change.Total}"
            );
        }
    }
);

InventoryViolation

Raised when the server refused or repaired something. The platform will only refuses or repairs structural damage. Whether to warn, kick or silently log violations is up to you.

Kind Meaning
ForgedPut A put or drop of something the server's copy of the player inventory does not contain
Malformed An item the game wouldn't create (an unknown or non-item record, the wrong identity for its record, invalid parts or stats), or an oversized report. A player claiming to have such an item has it taken away, or put back to the state the server last accepted
Flood More reports or requests per second than allowed
Desync The player's inventory differed from the server's copy and was resynced. Rare for honest clients, but not a guaranteed indicator that something malicious happened