Difference between revisions of "WebAPI/GetPlayerItems"

From Team Fortress Wiki
Jump to: navigation, search
(Section name capitalization)
(Moved to Examples)
Line 38: Line 38:
 
= Inventory Token =
 
= Inventory Token =
  
The inventory token is a combination of class loadout flags and position in the player's backpack. This unsigned 32 bit number is split into two two-byte words. The high word contains flags for each class. A 1 bit in a class's slot indicates that the items is equipped in the appropriate loadout slot for that class. The low word contains the backback position with 0 being the upper left slot, 1 the second slot from the left on the top row, etc. Here it is visually:
+
The inventory token is a combination of class loadout flags and position in the player's backpack. This unsigned 32 bit number is split into two two-byte words. The high word contains flags for each class. A 1 bit in a class's slot indicates that the items is equipped in the appropriate loadout slot for that class. The low word contains the backback position with 0 being the upper left slot, 1 the second slot from the left on the top row, etc. See [[../Examples#GetPlayerItems_Inventory_Token|examples]]. Here it is visually:
  
  
Line 63: Line 63:
 
   1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0  Equipped by Pyro and Engy
 
   1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0  Equipped by Pyro and Engy
 
                                                                       in backback slot 42
 
                                                                       in backback slot 42
 
In C++ the backpack position and equip status could be determined from an inventory token with these functions:
 
 
#define CLASS_SCOUT    0
 
#define CLASS_SNIPER    1
 
#define CLASS_SOLDIER  2
 
#define CLASS_DEMOMAN  3
 
#define CLASS_MEDIC    4
 
#define CLASS_HEAVY    5
 
#define CLASS_PYRO      6
 
#define CLASS_SPY      7
 
#define CLASS_ENGINEER  8
 
 
uint32 ExtractBackpackPosition( uint32 unInventoryToken )
 
{
 
  return unInventoryToken & 0xFFFF;
 
}
 
 
bool IsEquippedForClass( uint32 unInventoryToken, uint32 unClass )
 
{
 
  return 0 != unInventoryToken & ( 1 << ( unClass + 16 ) );
 
}
 
 
Similarly, in PHP (assuming $class is a numeric matching the defines above):
 
 
function is_equipped_for_class($class,$inventory_token)
 
{
 
  return ($inventory_token & 0x80000000) && ($inventory_token & (0x00010000 << $class));
 
}
 
function extract_backpack_position($inventory_token)
 
{
 
  return $inventory_token & 0x0000FFFF;
 
}
 
 
In Lua 5.1 (which does not have bitwise operators), these functions can be used:
 
 
function extract_backpack_position(inventory_token)
 
  return inventory_token % 2^16
 
end
 
 
function is_equipped_for_class(inventory_token, class)
 
  return inventory_token % 2^(class+17) >= 2^(class+16)
 
end
 
  
 
{{Languages|WebAPI/GetPlayerItems}}
 
{{Languages|WebAPI/GetPlayerItems}}
 
[[Category:WebAPI|GetPlayerItems]]
 
[[Category:WebAPI|GetPlayerItems]]

Revision as of 11:53, 31 October 2010

This method returns the specified player's backpack content.

This documentation is for version v0001 of GetPlayerItems.

URL

http://api.steampowered.com/ITFItems_440/GetPlayerItems/v0001/

Method-specific Parameters

SteamID
The 64 bit ID of the user the backpack will be retrieved for.

Status Codes

  • 1: OK. Data returned as specified below.
  • 8 ("SteamID parameter was missing"): The "steamID" parameter of the URL was not included, or if present was not a valid SteamID64 value.
  • 15 ("Permission denied"): The player's profile is set to Private.

Result Data

A list of the player's items is returned, as follows:

  • "items": An object containing an unsorted array of "item":
    • "id": The unique ID of the specific item.
    • "defindex": the defindex of the item, as found in the item array returned from GetSchema.
    • "level": The arbitrary "level" value of the item as displayed in the inventory.
    • "quantity": 1.
    • "flag_cannot_trade": true if the cannot be traded. This is true for items granted by an Achievement, purchased items, and certain promotional items.
    • "inventory": An inventory token as described below, or 0 if the item has been awarded but not yet found (placed in the backpack).
    • "quality": The "quality" of the item (see definition in GetSchema).
    • "custom_name": The item's custom name if it has one.
    • "attributes": If the item has additional effects to the ones normally associated with it as described in GetSchema, an object containing an array of "attribute":

Inventory Token

The inventory token is a combination of class loadout flags and position in the player's backpack. This unsigned 32 bit number is split into two two-byte words. The high word contains flags for each class. A 1 bit in a class's slot indicates that the items is equipped in the appropriate loadout slot for that class. The low word contains the backback position with 0 being the upper left slot, 1 the second slot from the left on the top row, etc. See examples. Here it is visually:


  ┌───────────────────────────────────────────────────────────────── Always 1
  │ ┌─┬─┬─┬─┬─┬─┬─────────────────────────────────────────────────── Unused
  │ │ │ │ │ │ │ │ ┌───────────────────────────────────────────────── Engineer 
  │ │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────────── Spy 
  │ │ │ │ │ │ │ │ │ │ ┌───────────────────────────────────────────── Pyro 
  │ │ │ │ │ │ │ │ │ │ │ ┌─────────────────────────────────────────── Heavy 
  │ │ │ │ │ │ │ │ │ │ │ │ ┌───────────────────────────────────────── Medic 
  │ │ │ │ │ │ │ │ │ │ │ │ │ ┌─────────────────────────────────────── Demoman 
  │ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌───────────────────────────────────── Soldier 
  │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌─────────────────────────────────── Sniper 
  │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌───────────────────────────────── Scout 
  │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ ┌─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─┬─ Backpack Position 
  │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │ │
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Examples:

  1 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1  Equipped Pyro item 
                                                                     in backback slot 9
  1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 1  Unequipped item 
                                                                     in backback slot 41
  1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0  Equipped by Pyro and Engy
                                                                     in backback slot 42