[Snippet] ReviveUnit

Scripts

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:
Code (jass) Select
1
library ReviveUnit /* 2.0.0.0
2
***************************************************
3
*
4
*   Resurrects a unit from his corpse, retaining
5
*   its handle ID, facing, and position.
6
*
7
***************************************************
8
*
9
*   ReviveUnit(unit whichUnit) returns boolean
10
*       - Resurrects the input unit.
11
*
12
***************************************************
13
*
14
*   Configurables
15
*       - 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 1000
19
       
20
    globals
21
        private constant integer DUMMY = 'eRez'
22
        private constant integer RESURRECT = 'URez'
23
    endglobals
24
/*
25
***************************************************
26
*
27
*   Notes
28
*       - Does not work on units without corpses.
29
*       - The resurrected unit's mana is determined
30
*         by the field: "Mana - Initial Amount"
31
*
32
***************************************************
33
*
34
*   Importing: Automatic
35
*       - Copy and paste this trigger.
36
*       - Save the map, close it, and reopen it
37
*       - Remove the exclamation ! from the object
38
*         merger lines above.
39
*
40
*   Importing: Manual
41
*       - Copy and paste this trigger.
42
*       - Copy and paste the dummy unit and resurrection
43
*         ability from the object editor.
44
*       - Change the configurable raw codes as necessary.
45
*
46
***************************************************/
47
48
    globals
49
        private unit reviver
50
        private real rx
51
        private real ry
52
    endglobals
53
   
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
        else
59
            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
        endif
65
        return success
66
    endfunction
67
   
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
        endmethod
76
    endmodule
77
   
78
    struct Revive extends array
79
        /* For backwards compatibility */
80
        static method Unit takes unit whichUnit returns boolean
81
            return ReviveUnit(whichUnit)
82
        endmethod
83
       
84
        implement Init
85
    endstruct
86
endlibrary


Here is a demo map.
  • ReviveUnit.w3x (19.23 KB)