library CloneHero
struct Clone
// edit is must!
private static constant integer DUMMY_MDX_RAW_RED = 100 // those are the colors
private static constant integer DUMMY_MDX_RAW_GREEN = 50 // of the new unit
private static constant integer DUMMY_MDX_RAW_BLUE = 10 // last created.
private static constant integer DUMMY_MDX_RAW_ALPHA = 0 // alpha = invisibility if you dont know.
//-------------Dont touch below!
private static integer array CLONE_ITEMS
private static unit CLONE_NEW = null
private static integer array CLONE_ITEMCHARGES
private static integer array ABILITY_LEVEL
private static integer array CLONE_STATS
private static real array CLONE_STATSREAL
private static player CLONE_OWNER
private static item TempItem = null
private static integer m =0
private static integer c =0
static method Unit takes unit CLONE_OLD, boolean KILLOLD, boolean CLONEITEMS, string model, integer ABILITY1, integer ABILITY2, integer ABILITY3, integer ABILITY4, integer ABILITY5, integer ABILITY6 returns unit
if CLONEITEMS then
set c = 0
set m = UnitInventoryCount(CLONE_OLD)
loop
set c = c + 1
set CLONE_ITEMS[c] = GetItemTypeId(UnitItemInSlot(CLONE_OLD, c))
set CLONE_ITEMCHARGES[c] = GetItemCharges(UnitItemInSlot(CLONE_OLD, c))
exitwhen c == m
endloop
endif
set ABILITY_LEVEL[1] = GetUnitAbilityLevel(CLONE_OLD, ABILITY1)
set ABILITY_LEVEL[2] = GetUnitAbilityLevel(CLONE_OLD, ABILITY2)
set ABILITY_LEVEL[3] = GetUnitAbilityLevel(CLONE_OLD, ABILITY3)
set ABILITY_LEVEL[4] = GetUnitAbilityLevel(CLONE_OLD, ABILITY4)
set ABILITY_LEVEL[5] = GetUnitAbilityLevel(CLONE_OLD, ABILITY5)
set ABILITY_LEVEL[6] = GetUnitAbilityLevel(CLONE_OLD, ABILITY6)
set CLONE_STATS[1] = GetHeroStr(CLONE_OLD, false)
set CLONE_STATS[2] = GetHeroAgi(CLONE_OLD, false)
set CLONE_STATS[3] = GetHeroInt(CLONE_OLD, false)
set CLONE_STATS[4] = GetHeroXP(CLONE_OLD)
set CLONE_STATSREAL[1] = GetWidgetLife(CLONE_OLD)
set CLONE_STATSREAL[2] = GetUnitState(CLONE_OLD, UNIT_STATE_MANA)
set CLONE_STATSREAL[3] = GetUnitX(CLONE_OLD)
set CLONE_STATSREAL[4] = GetUnitY(CLONE_OLD)
set CLONE_STATSREAL[5] = GetUnitFacing(CLONE_OLD)
set CLONE_STATSREAL[6] = GetUnitFlyHeight(CLONE_OLD)
set CLONE_OWNER = GetOwningPlayer(CLONE_OLD)
if KILLOLD then
if IsUnitHidden(CLONE_OLD) then
// i donno why, but it is sayd to bug if killing a hidden unit.. so donno
call KillUnit(CLONE_OLD)
endif
call RemoveUnit(CLONE_OLD)
endif
set CLONE_NEW = CreateUnit(CLONE_OWNER, GetUnitTypeId(CLONE_OLD), CLONE_STATSREAL[3], CLONE_STATSREAL[4], CLONE_STATSREAL[5])
call SetUnitFlyHeight(CLONE_NEW, CLONE_STATSREAL[6], 0)
call SetWidgetLife(CLONE_NEW, CLONE_STATSREAL[1])
call SetUnitState(CLONE_NEW, UNIT_STATE_MANA, CLONE_STATSREAL[2])
call SetHeroStr(CLONE_NEW, CLONE_STATS[1], true)
call SetHeroAgi(CLONE_NEW, CLONE_STATS[2], true)
call SetHeroInt(CLONE_NEW, CLONE_STATS[3], true)
call SetHeroXP(CLONE_NEW, CLONE_STATS[4], false)
//! textmacro ability takes number
if ABILITY$number$ != 0 then
call UnitAddAbility(CLONE_NEW, ABILITY$number$)
call SetUnitAbilityLevel(CLONE_NEW, ABILITY$number$, ABILITY_LEVEL[$number$])
endif
//! endtextmacro
//! runtextmacro ability("1")
//! runtextmacro ability("2")
//! runtextmacro ability("3")
//! runtextmacro ability("4")
//! runtextmacro ability("5")
//! runtextmacro ability("6")
call SetUnitVertexColor(CLONE_NEW, DUMMY_MDX_RAW_RED, DUMMY_MDX_RAW_GREEN, DUMMY_MDX_RAW_BLUE, DUMMY_MDX_RAW_ALPHA)
loop
set c = c - 1
set TempItem = UnitAddItemById(CLONE_NEW, CLONE_ITEMS[c])
call SetItemCharges(TempItem, CLONE_ITEMCHARGES[c])
exitwhen c == 0
endloop
return CLONE_NEW
endmethod
endstruct
endlibrary