• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Melee to Ranged when acquiring item - simple system

Status
Not open for further replies.
Level 3
Joined
Oct 25, 2017
Messages
43
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)

  • 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)
Step 4:
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)
Step 5:
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.
 

Attachments

  • empty_projectile.mdx
    396 bytes · Views: 32
  • Melee to Ranged.w3x
    20.9 KB · Views: 39
Level 21
Joined
Mar 27, 2012
Messages
3,232
Don't use chaos. It messes up when the unit has any bonuses from buffs.
If you want an instant transition you can use a reverse bear form(for instance). The way it works is that you put the original form to the alternate field and the new form to the normal field. That way you can morph a unit instantly by just adding and removing the ability.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,198
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).
So you found that cursed thing... poor you.

The problem with Chaos is that it reapplies all attribute/property modifications to a unit. If a unit picks up a tome and uses Chaos then the tome modifier will end up being applied twice to it. Same applies for upgrades and even item abilities. This is why no one uses Chaos to morph unit types.

Someone found that one of the transformation abilities (either crow form or raven form) can be used as a working chaos ability to change a unit type without re-applying all property modifiers. The key is to make the base unit type the desired new unit type and the morph unit type the current unit type. After the ability is added and removed it reverts the unit to its base unit type, even if the ability was not used to morph.
 
Last edited:
Morphing changes the unit's type id, which breaks many other things depending on how your map is coded.

A much simpler solution is using the Mountain Giant's Warclub ability. This ability changes the attack used by the unit just like an orb, but without the limitation of enforcing different target types.
After all, changing damage/range parameters is exactly what Warclub was originally intended for.



So, yeah, why apply a workaround when you have a thing that does exactly what you want?
 
Status
Not open for further replies.
Top