• 🏆 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!

SetUnitArmorType POC

Status
Not open for further replies.
Level 13
Joined
Nov 7, 2014
Messages
571
This is a proof of concept (POC) way of changing a unit's armor type in-game.
This exists because Blizzard "forgot" to expose such a functionality for scripting with Jass2 (bad blizzard, bad).

Of course an ability is required that does this, and the only one I could find is the
Root ability: 'Aro1' (Ancients) and 'Aro2' (Ancient Protector).
This ability has a data field called "Uprooted Defense Type".
We make a different ability based on Aro1 or Aro2 for each defense type.

This ability (and those based on it) has a little problem though.
It removes the unit's ability to move when:
1) it's added while uprooted
2) it's removed while rooted

So the problem is how to restore the unit's ability to move?
Unfortunately UnitAddAbility(u, 'Amov') doesn't seem to work... in this case.

Instead the Burrow (Crpyt Fiend) ability ('Abur') is used which restores the unit's ability
to move when unburrowed.

But unfortunately it has problems of it's own:
1) playing a unit's death animation when unburrowing
2) for heroes it modivies the base armor, damage, max life and max mana...
3) probably others...

And that's unfortunate, so that's why this is just a POC.

JASS:
library LibSetUnitArmorType

globals
    /* export */ constant integer ARMOR_TYPE_NORMAL = 'ap01'
    /* export */ constant integer ARMOR_TYPE_SMALL = 'ap02'
    /* export */ constant integer ARMOR_TYPE_MEDIUM = 'ap03'
    /* export */ constant integer ARMOR_TYPE_LARGE = 'ap04'
    /* export */ constant integer ARMOR_TYPE_FORTIFIED = 'ap05'
    /* export */ constant integer ARMOR_TYPE_HERO = 'ap06'
    /* export */ constant integer ARMOR_TYPE_DIVINE =  'ap07'
    /* export */ constant integer ARMOR_TYPE_UNARMORED = 'ap08'

    private constant integer UNROOT_ORDER_ID = 852166

    private constant integer BURROW_ABILITY_ID = 'Abur'
    private constant integer BURROW_ORDER_ID = 852533
    private constant integer UNBURROW_ORDER_ID = 852534
endglobals

/* export */ function SetUnitArmorType takes unit u, integer armor_type returns nothing
    local integer array armor_types
    local real original_facing

    call UnitAddAbility(u, BURROW_ABILITY_ID)

    call IssueImmediateOrderById(u, BURROW_ORDER_ID)
    call TriggerSleepAction(0.1)

    call IssueImmediateOrderById(u, UNBURROW_ORDER_ID)
    // When unburrowing the unit's death animation is played for some reason.
    call SetUnitTimeScale(u, 0)
    call TriggerSleepAction(0.1)
    call SetUnitAnimation(u, "stand")
    call SetUnitTimeScale(u, 1)

    // When we add the Aro1 (Ancients), Aro2 (Ancient Protector) or an ability based on
    // those, like the ones we are using for the armor changing, the unit's facing is changed
    // to the default for buildings.
    set original_facing = GetUnitFacing(u)
    call UnitAddAbility(u, armor_type)
    call SetUnitFacing(u, original_facing)
    call IssueImmediateOrderById(u, UNROOT_ORDER_ID)
    call TriggerSleepAction(0.1)
    call UnitRemoveAbility(u, armor_type)
endfunction

endlibrary
 

Attachments

  • set-unit-armor-type-poc.w3x
    15.3 KB · Views: 87
Level 9
Joined
Jul 30, 2012
Messages
156
There is a big problem with this system. Burrow is already a very buggy ability, and you have just found one more bug for the list: When you use 'Abur' in this way, the unit becomes immune to stuns! Try to stun any unit after you change their armor type with this. The unit will be stunned, but you can control it right after, before the stun ends.
 
Level 11
Joined
Dec 3, 2011
Messages
366
There is a big problem with this system. Burrow is already a very buggy ability, and you have just found one more bug for the list: When you use 'Abur' in this way, the unit becomes immune to stuns! Try to stun any unit after you change their armor type with this. The unit will be stunned, but you can control it right after, before the stun ends.

This bug occured when you became transform or metamor .... Because game engine.
 
Level 9
Joined
Jul 30, 2012
Messages
156
This bug occured when you became transform or metamor .... Because game engine.

Actually I've been doing extensive testing on all bugs related to morphing and I can say that this one is different from all of them. I have already enumerated 3 different kinds of stun-immunity bugs, but this one can be classified as the 4th. It seems to be specific to the Burrow ability. So far I didn't find any way to revert the bug after it happens, not even with the unit dying.
 
Try this out. Oh, and I don't take credit for any of the code in the file I posted. It's just a little edited combination of two genius's work.


I'd like to thank leandrotp for http://www.hiveworkshop.com/forums/lab-715/heroicunit-engineering-upgrade-non-hero-units-270930/ because I was too lazy to actually do that to make this work, so here's a possible method to having in-game armor type modification with hybrid hero's.

Careful with the process, it crashed every other method I tried besides this one. Oh, and thank you Aniki for sharing this. I think everyone should be using custom stun systems by now, so many possibilities that make the default system useless.

Edit: Don't use armor # on any of the spawned tinkers, its an example of why it crashes. Instead use one of the other units with "test2" before or/and after armor 1-7. To re-add heroic capability after armor # then just "test2". I didn't fix all the bugs in the method I posted so after armor # the units lose heroic capability however easy enough to add it back without any bugs besides hero stats not actually being visible.
 

Attachments

  • hero type addition.w3x
    18.3 KB · Views: 77
Status
Not open for further replies.
Top