Skip to content

D2 Documentation

Robbie Gibson edited this page Apr 15, 2014 · 16 revisions

D2 provides several functions for working internally with Valve API data and hero/item images. Most of the main functions deal with turning ids into information about [heroes](D2 Documentation#wiki-hero-id-functions), [items](D2 Documentation#wiki-item-id-functions), [abilities](D2 Documentation#wiki-ability-id-functions), [game modes](D2 Documentation#wiki-game-mode-id-functions), and [users](D2 Documentation#wiki-user-id-functions). There are also a few [functions](D2 Documentation#wiki-steam-id-conversions) to help with converting between Steam's 64 and 32-bit account IDs.

The JSON files are objects indexed by ID. Keep in mind that many of the files have a bunch of extraneous entries. For example, the item file has items from Wraith Night and New Bloom, and the abilities file has all the abilities for neutral jungle creeps.

Data Functions

# d2.loadJson(callback)

This function uses d3.json to load all the different JSON files (heroes, items, etc). When everything is loaded, the callback function is called.

# d2.getKeys(keytype)

This returns all the keys for one of the JSON files. The keytype options are "heroes," "items," "abilities," and "game_modes."

# d2.loadUserData(user, callback)

This function uses d3.json to load the data for the given user. It also looks through all that user's matches and pulls their player object out to the top level for ease of access later. It also pulls out which side the player was on and whether they won or lost.

Like d3.json, this function uses a callback function as one if its parameters. The callback function will be called once the data is loaded and filtered with the the arguments error (the error, if any) and data (the data as an object.

If the user doesn't exist, this function will raise an error.

Hero ID Functions

# d2.getHeroInfo(id)

Returns an object of all the data for a given hero id. DO NOT use this function if you are going to add new fields to the hero object, to track item purchases for instance, because this object is shared across all calls to getHeroInfo

The fields are:

  • name: A hero's Valve-given name. This is not often used elsewhere (ex. Zeus's name from Valve is Zuus)

  • dname: The hero's actual in-game name as an English string.

  • img: The path from the home directory to the hero's image. It will look like /img/heroes/<name>.jpg, so you can just use this to insert images from anywhere.

  • id: The hero's numerical ID.

  • stat: The hero's primary attribute as one of "intelligence," "agility," or "strength."

  • pa: The hero's primary attribute as one of "int," "agi," or "str."

  • dac: The hero's attack type, either "Melee" or "Ranged."

  • droles: A string of the roles given to each hero by Valve. For example, Anti-Mage has roles "Carry - Escape."

  • attribs: The hero's attributes. This is itself an object with the following fields:

    • int: The hero's intelligence, with attributes b (their starting int) and g (their int gain per level).

    • agi: Same as int.

    • str: Same as int.

    • ms: Base move speed

    • armor: Base armor

    • dmg: The hero's base attack, without any bonuses from their starting attributes. It's given as an object with two keys, max and min, for the the maximum and minimum damages.

If no hero has this id, then throws an error: No hero with id 'id'.

# d2.getHeroInfoCopy(id)

This function returns a copy of the object for hero info. Use this function if you are planning to update or create new parts of the array. For example, the "hero flare" for the sunburst graph should use this call, so you don't add children or counters in weird places.

# d2.getHeroName(id)

Returns the hero name, in English, of the hero with the specified id. If no hero has this id, then throws an error: No hero with id 'id'.

This is just a convenience method It has the same effect as calling d2.getHeroData(id).dname.

Item ID Functions

# d2.getItemInfo(id)

Returns an object of all the data for a given item id. DO NOT use this function if you are going to add new fields to the item object, to track children for instance, because this object is shared across all calls to getItemInfo If the id corresponds to a recipe, not all of the below fields exist. Recipes only have the name, id, and img fiedls.

The fields are:

  • name: A item's Valve-given name. This is often confusing(ex. Shadowblade is called "invis_sword")

  • dname: The item's actual in-game name as an English string.

  • img: The path from the home directory to the item's image. It will look like /img/items/<name>.jpg, so you can insert images from anywhere.

  • id: The item's numerical ID.

  • cost: The cost in gold of the item.

  • mc: The mana cost of the item's active ability, or false if the item has no active.

  • cd: The item's cooldown, or false if no cooldown

  • qual: The item type. This corresponds to which row of the shop it is in. The qualities are artifact, common, component, consumable, epic, rare, and secret_shop.

  • created: A boolean representing whether the item is created from other components or bought alone.

  • components: A list of the components of an item. However, this list doesn't include a recipe, unless the recipe actually serves to upgrade the item.

    For example, the component list for Necronomicon 1 is ["staff_of_wizardry", "belt_of_strength"], but the list for Necronomicon 2 is ["necronomicon", "recipe_necronomicon"].

  • desc: The item's in-game description as a string.

  • attrib: The item's attributes formatted as an html string.

  • lore: The item's lore, as a string.

  • notes: All the extra help notes for complicated items. These are the ones that you would see in the game by pressing alt and hovering over the item.

If no item has this id, then throws an error: No item with id 'id'.

# d2.getItemInfoCopy(id)

This function returns a copy of the object for item info. Use this function if you are planning to update or create new parts of the array. For example, the list of max items on each hero for the sunburst graph should use this call, so you don't add children or counters in weird places.

# d2.getItemName(id)

Returns the item name, in English, of the item with the specified id. If no item has this id, then throws an error: No item with id 'id'.

This is just a convenience method It has the same effect as calling d2.getItemData(id).dname.

Ability ID Functions

# d2.getAbilityInfo(id)

This function, like the others, returns the object for the ability with the given id.

Abilities, in general, have the following fields:

  • affects: Tell how the ability is targeted ("point," "hero," etc), what type of damage the ability iz, and who the ability affects. This is already formatted as HTML with <apan> tags.

  • attrib: This tells the ability's special properties, for example, slow, poison damage, radius. This is also formatted as HTML.

  • cmb: This holds the ability's mana cost and cooldown, heavily HTML formatted.

  • desc: The string that describes what the ability does.

  • dmg: The damage the ability does.

  • dname The ability's actual English display name.

  • hurl: This stands for "hero url." It contains the hero's english display name separated by underscores. I think Valve uses it as the url to the hero page (e.g. dota2.com/heroes/<hurl>).

  • id: The ability's id.

  • img: A link to our ability image. The string is from the base directory.

  • lore: The ability's lore string.

  • name: The Valve name of the ability. This is often not what you'd guess. In general, it's the Valve hero name (e.g. rattletrap, nevermore) plus the ability.

  • notes: The extra notes you see when you hold ALT over an ability.

# d2.getAbilityData(id)

This function returns all the data for the abilities as an object indexed by id.

Game Mode ID Functions

# d2.getGameModeInfo(id)

Returns the info for the game mode with the id. This only has two fields: id, holding the id, and name, holding the name of the mode.

User ID Functions

# d2.getUserInfo(id32)

This function returns an object with info for the given 32-bit Steam account ID. As a reminder, right now, all these objects are static. They will hold whatever value they were when the data was pulled (~April 13), so they won't represent current data.

Users, in general, have the following fields:

  • avatar: Returns a link to a 32x32 version of the user's profile image

  • avatarmedium: Returns a link to a 64x64 version of the user's profile image

  • avatarfull: Returns a link to a 128x128 version of the user's profile image

  • communityvisibilitystate: An integer that describes the access setting of the profile

    • 1: Private

    • 2: Friends only

    • 3: Friends of Friends (although this value is currently returned for Users Only and Public profiles as well)

    • 4: Users Only

    • 5: Public

  • profilestate: A binary flag that tells whether the user has configured their profile

  • personaname: The user's display name.

  • lastlogoff: A Unix timestamp of when the user was last online. This value is in seconds, so if you want to use Javascript new Date(), multiply by 1000.

  • profileurl: The URL to the user's Steam Community profile.

  • personastate: The user's status

    • 0: Offline (Also set when the profile is Private)

    • 1: Online

    • 2: Busy

    • 3: Away

    • 4: Snooze

    • 5: Looking to trade

    • 6: Looking to play

  • commentpermission (Optional): If present the profile allows public comments.

  • realname (Optional): The user's real name.

  • primaryclanid (Optional): The 64 bit ID of the user's primary group.

  • timecreated (Optional): A unix timestamp of the date the profile was created. Again, this is in seconds, not milliseconds

  • loccountrycode (Optional): String for where user is located. It is an abbreviation.

  • locstatecode (Optional): Two-letter(?) abbreviation of the state where the user is located.

  • loccityid (Optional): An integer ID internal to Steam representing the user's city.

  • gameid (Optional): If the user is in game this will be set to it's app ID as a string.

  • gameextrainfo (Optional): The title of the game.

  • gameserverip (Optional): The server URL given as an IP address and port number separated by a colon, this will not be present or set to "0.0.0.0:0" if none is available.

Steam ID Conversions

# d2.id64To32(id)

Returns the Steam 32-bit account ID for the given 64-bit account ID.

# d2.id32To64(id)

Returns the Steam 64-bit account ID for the given 32-bit account ID.

Clone this wiki locally