• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

[Trigger] Copy A Unit

Status
Not open for further replies.

Vex

Vex

Level 3
Joined
Dec 1, 2007
Messages
33
Make a copy of a unit or also make the copy mimic the original?

If it's a copy only, you can make a trigger that creates a new unit. Where unit-type, player, position and facing angle is set to the same as the original unit. How you let the trigger know which unit that should be used depends on how you want the trigger to activate though.
 
Level 19
Joined
May 1, 2008
Messages
1,130
unit starts teh effect of a ability
ability being used = your ability
(this is if u clone yourself)
create 1 unit type of casting unit for owner of casting unit at position of casting unit facing default facing angle (that is just or units, for heroes its a bit difficult cuz u need to use variables for the hero level and skill levels
 
Level 4
Joined
Dec 23, 2005
Messages
41
In Jass....

Well...

JASS:
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
Just replace the XXXX by the ability code and don't forget to call SkillCopyUnit at init with
JASS:
call ExecuteFunc("SkillCopyInit")
; it should work. Edit #1 : Checked syntax.
 
Level 5
Joined
Jun 30, 2008
Messages
84
Well...

JASS:
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
Just replace the XXXX by the ability code and don't forget to call SkillCopyUnit at init with
JASS:
call ExecuteFunc("SkillCopyInit")
; it should work. Edit #1 : Checked syntax.
Oh god thanks! +Rep
 
Status
Not open for further replies.
Top