• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

How do i make the exact same copy of a unit with triggers?

Status
Not open for further replies.
READ
I want a trigger that will make a copy of a certain unit that copies the unit's current health, mana, items, abilities?
Getting everything with variables isn't an option.
(And sorry for the 'read' thing, but i'm tired of asking questions and people not reading and answering just the title; i always get irrelevant answers because people don't read the actual question)
 
Create an unit with UnitType of <OldUnit>.
Set Life of <NewUnit> to Life of <OldUnit>.
Set Mana of <NewUnit> to Mana of <OldUnit>.
Loop through <OldUnit>'s inventory and create each of them for <NewUnit>. (work with slot number in loop)

If you add/remove abilities via trigger we can talk about it later, once you have the basics working. Else it should be enough.
 
Level 15
Joined
Oct 29, 2012
Messages
1,474
I think IcemanBo included everything about Items, HP, Mana...

That's the same with level and experience pôints,
  • Hero - Set Hero Level to 'Replaceable Hero
  • Hero - Set Experience points to 'Your Heros XPs'
Since IcemanBo didn't include abilities thingy, I would give a preview about the idea

The event would be (A Unit learns a skill) or (A Unit learns an ability)
You save the learned ability inside a variable which is also inside the hashtable
With an array '1' if it's the first ability

When you come to give the ability to the copied hero, you just give him the variable from the hashtable for example :
  • For each Integer A from 1 to 6 Do Multiple Actions
    • Loop
      • Unit - Learn Ability[IntegerA] for 'Your Hero Or Unit'

Good luck
 
Level 5
Joined
Jan 23, 2014
Messages
152
Wouldnt it be better to use the "add ability" function instead of learn ability? I'm also trying to do the same, but I still dont have any ideas how.
 
Level 15
Joined
Aug 7, 2013
Messages
1,338
If you're going to be deep copying units frequently like WaterKnight says, it would be advisable to create a function that takes a unit as a parameter and returns a new unit (the copy). You'll also need a parameter that says where to put the new unit (i.e. location / point coordinates). From there follow IcemanBo's solution, and add whatever else you need.

e.g.

JASS:
function copyUnit takes unit whichUnit, location whichLoc returns unit
  local unit copy = CreateUnitAtLoc(whichLoc, GetUnitTypeId(whichUnit), ...)
  return copy
endfunction

I want a trigger that will make a copy of a certain unit that copies the unit's current health, mana, items, abilities?
Getting everything with variables isn't an option.

You'll have a problem unless you are doing a very simple copy, since to "avoid" variables you'll be at the mercy of what natives are available.
 
Status
Not open for further replies.
Top