14 years
edited 8 years
ReviveUnit
Revives a unit in a similar fashion to reviving a hero. Note it does not work on units who do not leave a corpse (e.g. exploded, does not decay etc.).
Here is the code:
1 library ReviveUnit /* 2.0.0.0
2 ***************************************************3 *4 * Resurrects a unit from his corpse, retaining5 * its handle ID, facing, and position.6 *7 ***************************************************8 *9 * ReviveUnit(unit whichUnit) returns boolean10 * - Resurrects the input unit.11 *12 ***************************************************13 *14 * Configurables15 * - Remove the ! from //! after saving.16 */17 //! external ObjectMerger w3a AHre URez anam "Dummy Resurrection" aher 0 acat "" atat "" Hre1 1 1 aare 1 0 aran 1 0 acdn 1 0 amcs 1 0 atar 1 "Air,Dead,Enemy,Friend,Ground,Neutral"18 //! external ObjectMerger w3u ushd eRez unam "Dummy" uabi "Aloc,Avul" ucbs 0 ucpt 0 umdl ".mdl" usca "0.01" ushu "None" umvh 0 umvs 0 ufoo 0 umpi 100000 umpm 100000 umpr 100019
20 globals21 private constant integer DUMMY = 'eRez'
22 private constant integer RESURRECT = 'URez'
23 endglobals24 /*25 ***************************************************26 *27 * Notes28 * - Does not work on units without corpses.29 * - The resurrected unit's mana is determined30 * by the field: "Mana - Initial Amount"31 *32 ***************************************************33 *34 * Importing: Automatic35 * - Copy and paste this trigger.36 * - Save the map, close it, and reopen it37 * - Remove the exclamation ! from the object38 * merger lines above.39 *40 * Importing: Manual41 * - Copy and paste this trigger.42 * - Copy and paste the dummy unit and resurrection43 * ability from the object editor.44 * - Change the configurable raw codes as necessary.45 *46 ***************************************************/47 48 globals49 private unit reviver
50 private real rx
51 private real ry
52 endglobals53
54 function ReviveUnit takes unit u returns boolean
55 local boolean success
56 if IsUnitType(u, UNIT_TYPE_HERO) == true then
57 return ReviveHero(u, GetUnitX(u), GetUnitY(u), false)
58 else59 call SetUnitX(reviver, GetUnitX(u))
60 call SetUnitY(reviver, GetUnitY(u))
61 set success = IssueImmediateOrderById(reviver, 852094)
62 call SetUnitX(reviver, rx)
63 call SetUnitY(reviver, ry)
64 endif65 return success66 endfunction67
68 private module Init
69 private static method onInit takes nothing returns nothing
70 set rx = GetRectMaxX(bj_mapInitialPlayableArea) - 1
71 set ry = GetRectMaxY(bj_mapInitialPlayableArea) - 1
72 set reviver = CreateUnit(Player(15), DUMMY, rx, ry, 0)
73 call SetUnitPathing(reviver, false)
74 call UnitAddAbility(reviver, RESURRECT)
75 endmethod76 endmodule77
78 struct Revive extends array
79 /* For backwards compatibility */80 static method Unit takes unit whichUnit returns boolean
81 return ReviveUnit(whichUnit)
82 endmethod83
84 implement Init85 endstruct86 endlibrary
Here is a demo map.