MeleeRandomHeroLoc

Parameters
p player
id1 integer
id2 integer
id3 integer
id4 integer
loc location
bug

Leaks handle hero: In Jass you must set local variables that hold agents (or any child type) to null at the end of functions to avoid reference counter leaks.

bug

Leaks handle v: In Jass you must set local variables that hold agents (or any child type) to null at the end of functions to avoid reference counter leaks.

comment
note

It does not touch the passed loc location, you must remove it manually to avoid leaks.

patch

1.00

return type
unit
Source code
function MeleeRandomHeroLoc takes player p, integer id1, integer id2, integer id3, integer id4, location loc returns unit
    local unit    hero = null
    local integer roll
    local integer pick
    local version v

    // The selection of heroes is dependant on the game version.
    set v = VersionGet()
    if (v == VERSION_REIGN_OF_CHAOS) then
        set roll = GetRandomInt(1,3)
    else
        set roll = GetRandomInt(1,4)
    endif

    // Translate the roll into a unitid.
    if roll == 1 then
        set pick = id1
    elseif roll == 2 then
        set pick = id2
    elseif roll == 3 then
        set pick = id3
    elseif roll == 4 then
        set pick = id4
    else
        // Unrecognized id index - pick the first hero in the list.
        set pick = id1
    endif

    // Create the hero.
    set hero = CreateUnitAtLoc(p, pick, loc, bj_UNIT_FACING)
    if bj_meleeGrantHeroItems then
        call MeleeGrantItemsToHero(hero)
    endif
    return hero
endfunction
Source
Blizzard.j
wc3modding.com
MeleeRandomHeroLoc