function SkillCopyCondition takes nothing returns boolean
return GetSpellAbilityId()=='XXXX'
endfunction
function SkillCopyActions takes nothing returns nothing
local unit caster = GetSpellAbilityUnit()
local unit target = GetSpellTargetUnit()
local integer int = 0
local unit copy = CreateUnit(GetOwningPlayer(caster),GetUnitTypeId(target),GetUnitX(target),GetUnitY(target),GetUnitFacing(target))
if IsUnitType(target,UNIT_TYPE_HERO)==true then
call SetHeroLevel(copy,GetHeroLevel(target),false)
loop
exitwhen int>5
call UnitAddItemById(copy,GetItemTypeId(UnitItemInSlot(target,int)))
if GetItemType(UnitItemInSlot(target,int))==ITEM_TYPE_PURCHASABLE then
call SetItemCharges(UnitItemInSlot(copy,int),GetItemCharges(UnitItemInSlot(target,int)))
endif
set int=int+1
endloop
endif
call SetUnitState(copy,UNIT_STATE_LIFE,GetUnitState(target,UNIT_STATE_LIFE))
call SetUnitState(copy,UNIT_STATE_MANA,GetUnitState(target,UNIT_STATE_MANA))
set caster = null
set target = null
set copy = null
set int = 0
endfunction
function SkillCopyInit takes nothing returns nothing
local trigger trig = CreateTrigger()
call TriggerAddAction(trig,function SkillCopyActions)
call TriggerAddCondition(trig,Condition(function SkillCopyCondition))
call TriggerRegisterAnyUnitEventBJ(trig,EVENT_PLAYER_UNIT_SPELL_EFFECT)
set trig = null
endfunction