Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/sr2echa/TF2-Source-Code/llms.txt

Use this file to discover all available pages before exploring further.

Each TF2 player carries an inventory of CEconItemView objects representing their owned items. On the server, each CTFPlayer instance holds a CTFPlayerInventory that exposes the active loadout — what weapon or cosmetic is equipped in each slot. The inventory data is synchronized from the Steam Game Coordinator (GC) via CGCClientSystem.

CTFPlayerInventory

CTFPlayerInventory (game/shared/tf/tf_item_inventory.h) inherits from CPlayerInventory and provides TF2-specific loadout logic:
// game/shared/tf/tf_item_inventory.h
class CTFPlayerInventory : public CPlayerInventory
{
public:
    virtual CEconItemView *GetItemInLoadout( int iClass, int iSlot );
    bool ClearLoadoutSlot( int iClass, int iSlot );     // CLIENT_DLL only
    virtual int  GetMaxItemCount() const;
    virtual bool CanPurchaseItems( int iItemCount ) const;

    void OnHasNewItems();
    void OnHasNewQuest();
};
GetItemInLoadout( iClass, iSlot ) is the primary accessor used by CTFPlayer::GetLoadoutItem() to determine which weapon to give at spawn.

CEconItemView

CEconItemView is the in-memory representation of a single item instance. It holds the item definition index, item ID (64-bit), quality, level, and the attribute list:
// Accessing an equipped item's attributes
CEconItemView *pItem = pInventory->GetItemInLoadout( TF_CLASS_SOLDIER, TF_LOADOUT_SLOT_PRIMARY );
if ( pItem && pItem->IsValid() )
{
    item_definition_index_t nDefIdx = pItem->GetItemDefinitionIndex();
    int nQuality = pItem->GetItemQuality();
    // Read attributes
    float flValue = 0.f;
    pItem->FindAttribute( GetItemSchema()->GetAttributeDefinitionByName( "mult_dmg" ), &flValue );
}

Base items and fallback

If a player has no item equipped in a slot (or equips the base/stock item), LOADOUT_SLOT_USE_BASE_ITEM (value 0) signals that the class default weapon should be used. CTFPlayer::GiveDefaultItems() reads each slot and either grants the equipped item or the class default.

Wearable items

Cosmetic items are CTFWearable (game/shared/tf/tf_item_wearable.h) entities attached to the player model. On equip, the server spawns a wearable entity, parents it to the player, and applies the cosmetic model override. Wearables use MOVETYPE_FOLLOW to track the player bone attachment.

Item notifications and GC sync

On the client, CTFPlayerInventory::ItemHasBeenUpdated() fires when the GC delivers an updated item. The inventory manager (CEconItemInventoryManager) coordinates multiple player inventories and handles GC message callbacks for item grants, removals, and attribute changes.
Strange-quality items track kill/event counts via CEconItemAttribute values updated server-side and periodically pushed to the GC. CTFGameStats records the events; CTFPlayer::Event_Killed() triggers the attribute increment.
Killstreak kits add attributes that track the current killstreak count and apply sheen/killstreaker effects. The sheen is a VMT parameter overlay applied to the weapon material at runtime by the material proxy system.
Inventory data lives on Valve’s GC servers. The local game only holds a cached copy. During GC downtime, players fall back to their stock loadout.

Build docs developers (and LLMs) love