Ok so i've had this issue some time ago on another project, about how to make a unit switch automatically to a ranged attack when picking up a ranged item. No automatic way but to use metamorphosis or bear form.
Today I was looking through the abilities section and noticed the Chaos (orc unit) abilities and they seemed to automatically switch a unit's type when acquired (same with Troll Beserker).
Long story short, found an easy way to switch units from melee to ranged automatically without too much work:
Step 1:
Create 2 instances of the unit/hero you want - one with normal melee attack and one with the ranged attack
Step 1.5:
Add an empty projectile to the ranged projectile art of the ranged hero/unit (you can find it below)
Step 1.6:
Make sure that if you just copy paste a melee hero and then tweek the numbers to make him ranged, you also change attack type to missile
Step 2:
Create 2 instances of the Beserker Upgrade spell - one that changes the unit to the ranged version and one that changes the unit to the melee version. You can pick the units from the Data - New Unit Type field of the spell
Step 3:
Create the trigger to check if the item is picked is ranged or melee (unfortunately you will have to do this for each item or just check for item class or level if you want to have item types)
You probably want to maintain abilities through the transitions so you will need to use this for all abilities that are on your hero or that are acquired later
Use the Orb of Fire ability to add a projectile to your ranged attack by adding it to the ranged item
Step 6:
Ignore the bow and the animation of the villager in the demo map, its just there to show its a bow.
Hope this helps some people who face the same issue like I did and couldn't find a viable solution.
Today I was looking through the abilities section and noticed the Chaos (orc unit) abilities and they seemed to automatically switch a unit's type when acquired (same with Troll Beserker).
Long story short, found an easy way to switch units from melee to ranged automatically without too much work:
Step 1:
Create 2 instances of the unit/hero you want - one with normal melee attack and one with the ranged attack
Step 1.5:
Add an empty projectile to the ranged projectile art of the ranged hero/unit (you can find it below)
Step 1.6:
Make sure that if you just copy paste a melee hero and then tweek the numbers to make him ranged, you also change attack type to missile
Step 2:
Create 2 instances of the Beserker Upgrade spell - one that changes the unit to the ranged version and one that changes the unit to the melee version. You can pick the units from the Data - New Unit Type field of the spell
Step 3:
Create the trigger to check if the item is picked is ranged or melee (unfortunately you will have to do this for each item or just check for item class or level if you want to have item types)
-
Ranged
-
Events
-
Unit - A unit Acquires an item
-
-
Conditions
-
(Item-type of (Item being manipulated)) Equal to Your Item
-
-
Actions
-
Unit - Add Upgrade Ranged to (Triggering unit)
-
-
-
Melee
-
Events
-
Unit - A unit Loses an item
-
-
Conditions
-
(Item-type of (Item being manipulated)) Equal to Your Item
-
-
Actions
-
Unit - Add Upgrade Melee to (Triggering unit)
-
-
You probably want to maintain abilities through the transitions so you will need to use this for all abilities that are on your hero or that are acquired later
-
Custom script: call UnitMakeAbilityPermanent(udg_Unit, true, udg_Ability)
Use the Orb of Fire ability to add a projectile to your ranged attack by adding it to the ranged item
Step 6:
Ignore the bow and the animation of the villager in the demo map, its just there to show its a bow.
Hope this helps some people who face the same issue like I did and couldn't find a viable solution.