Replacing a Hero actually works more gracefully than you might think. The game will transfer the hero's level, XP, carried items. You will have to make the trigger force re-learning the spells, which is a little finnicky due to GUI limitations but a few custom script lines make it work nicely. (This example will only work for a specific hero type. You need to have the ability ID codes and in this game version we can't dynamically read them from the unit.)
-
TurnOn
-

Events
-


Unit - A unit Is issued an order with no target
-

Conditions
-


(Issued order) Equal to (Order(flamingarrows))
-


(Unit-type of (Triggering unit)) Equal to Melee Hero
-

Actions
-


Set HeroSelected = ((Triggering unit) is selected by Player 1 (Red))
-


-------- you will need rawcode of each Ability your hero has --------
-


-------- this should be an Integer Array variable type --------
-


-------- yes we are putting letters into an integer value --------
-


Custom script: set udg_HeroAbilityID[1] = 'AHfa'
-


Custom script: set udg_HeroAbilityID[2] = 'AHds'
-


Custom script: set udg_HeroAbilityID[3] = 'AHre'
-


Custom script: set udg_HeroAbilityID[4] = 'AHad'
-


For each (Integer A) from 1 to 4, do (Actions)
-



Loop - Actions
-




Custom script: set udg_HeroAbilLevel[GetForLoopIndexA()] = GetUnitAbilityLevelSwapped(udg_HeroAbilityID[GetForLoopIndexA()], GetTriggerUnit())
-


Unit - Replace (Triggering unit) with a Ranged Hero using The old unit's relative life and mana
-


-------- Select Hero if they were already selected --------
-


If (All Conditions are True) then do (Then Actions) else do (Else Actions)
-



If - Conditions
-




HeroSelected Equal to True
-



Then - Actions
-




Selection - Add (Last replaced unit) to selection for Player 1 (Red)
-



Else - Actions
-


-------- Relearn Hero spells --------
-


-------- Since skill points are already refunded by Replace action, this method works nicely --------
-


For each (Integer A) from 1 to 4, do (Actions)
-



Loop - Actions
-




For each (Integer B) from 1 to HeroAbilLevel[(Integer A)], do (Actions)
-





Loop - Actions
-






Custom script: call SelectHeroSkill(bj_lastReplacedUnit,udg_HeroAbilityID[GetForLoopIndexA()])
There are more limitations to work around that I haven't done in this example. For things where I'm not offering a solution, that's because I can't think of a
good solution:
- Ability cooldowns. Since I imagine you only have a small handful of heroes for whom this system will be used, you could use Timers to monitor cooldowns, and then Disable the ability on the replaced unit, re-enabling it when the timer expires. The cooldown visual on the icon won't look quite right, but it will remain unavailable for the correct duration.
- Enemy units have to re-acquire target.
- Item slots get resorted. If you have manually moved items within the inventory to different slots, that will be undone.
- Attack 2 is not visible in a Hero info card; it will be buried beneath the Attributes. Solution: Only use Attack 1 for both unit types, just change the attack properties.
There might be more limitations, but depending on the type of map you're making, I think there might be some real potential to make this work. Maybe not perfectly, but perhaps good enough.
EDIT: note: I tested the above on game ver. 1.27 (I don't have 1.28 installed) and it works.