- 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
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.
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