BlzGetPlayerTownHallCount

Parameters
whichPlayerplayer
comment

Returns total count of player's town hall buildings of any race by counting town hall tech tree dependency equivalents 'TWN1' through 'TWN9' (which probably uses 'utyp' = "TownHall" for initial classification).

Each tier 1 town hall is counted as 1; tier 2 for 2 etc. Includes duplicate buildings: two tier 1s count as (2 * 1)=2.

note

Example (Lua, 2.0.3):

-- 3 Town hall IDs per each race (tier 1, 2, 3): humans, orcs, undead
local townHalls = {"htow", "hkee", "hcas", "ogre", "ostr", "ofrt", "unpl", "unp1", "unp2"}

print("Before spawning any town halls: ", BlzGetPlayerTownHallCount(Player(0)))

for i, code in pairs(townHalls) do
    local u = CreateUnit(Player(0), FourCC(code), -2048 + i*384, 512, 90)
    print("Spawned town hall #".. i ..". Total count by API: ".. BlzGetPlayerTownHallCount(Player(0)))
end

Prints: 0; 1, 3, 6; 7, 9, 12; 13, 15, 18

note

See: GetPlayerTechCount for equivalency class explanation.

patch

1.32.0.13369

Source
common.j (raise an issue to discuss on Github or submit a PR)
return type
integer
Source code
native BlzGetPlayerTownHallCount                   takes player whichPlayer returns integer