• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Triggers

Unit Event 2.5.3.2.w3x
Variables
Variables
Unit Event
Unit Event Config
Unit Event
Unit In Action
Unit In Action
Unit Inaction
Test
On Create
On CompletelyCreated
On Summon
On Death
On Reincarnate
On Revival
On Removal
On Load
On Unload
On Transform
On Esc
Name Type is_array initial_value
CargoEvent real No
CargoTransportGroup group Yes
CargoTransportUnit unit Yes
CheckDeathInList boolean Yes
CheckDeathList integer Yes
CheckDeathTimer timer No
DeathEvent real No
DetectRemoveAbility abilcode No
DetectTransformAbility abilcode No
IsUnitAlive boolean Yes
IsUnitBeingUnloaded boolean Yes
IsUnitNew boolean Yes
IsUnitPreplaced boolean Yes
IsUnitReincarnating boolean Yes
IsUnitRemoved boolean Yes
IsUnitTransforming boolean Yes
KillerOfUnit unit Yes
SummonerOfUnit unit Yes
UDex integer No
UDexLastRecycled integer No
UDexMax integer No
UDexNext integer Yes
UDexPrev integer Yes
UDexUnits unit Yes
UnitInAction boolean Yes
UnitInActionEvent real No
UnitIndexerEnabled boolean No
UnitIndexEvent real No
UnitName string Yes
UnitTypeEvent real No
UnitTypeOf unitcode Yes
WorldMaxX real No
WorldMaxY real No
GUI Unit Event by Bribe, version 2.5.3.2
Unit Event Config
Events
Map initialization
Conditions
Actions
-------- --------
-------- Copy Unit Event Ability from Object Editor, then set DetectRemoveAbility to it as follows: --------
-------- --------
Set Variable Set DetectRemoveAbility = "A002"
-------- --------
-------- Paste it a second time, then set DetectTransformAbility to it as follows: --------
-------- --------
Set Variable Set DetectTransformAbility = "A001"
-------- --------
-------- Don't enable the following lines as they exist simply to make copying the system easier --------
-------- --------
Set Variable Set WorldMaxX = WorldMaxY
Set Variable Set CargoTransportUnit[0] = (Random unit from CargoTransportGroup[0])
Set Variable Set CheckDeathList[UDexMax] = UDexNext[UDexPrev[UDexLastRecycled]]
Set Variable Set UDexUnits[UDex] = SummonerOfUnit[0]
Countdown Timer - Pause CheckDeathTimer
Set Variable Set UnitIndexEvent = (CargoEvent + (DeathEvent + UnitTypeEvent))
Set Variable Set IsUnitAlive[0] = IsUnitBeingUnloaded[0]
Set Variable Set IsUnitNew[0] = IsUnitReincarnating[0]
Set Variable Set IsUnitRemoved[0] = UnitIndexerEnabled
Set Variable Set KillerOfUnit[0] = No unit
Set Variable Set UnitTypeOf[0] = No unit-type
Set Variable Set CheckDeathInList[0] = "false"
-------- One additional event to run right before Unit Indexer initializes, added 29 May 2017 for ZiBitheWand3r3r --------
Set Variable Set UnitIndexEvent = "-1.00"
-------- --------
-------- Initialize Unit Event now that all the InitTrig_ functions have run --------
-------- --------
Set Variable Set IsUnitPreplaced[0] = "true"
Custom script: call ExecuteFunc("UnitEventInit")
Set Variable Set UnitIndexEvent = "3.00"
Set Variable Set IsUnitPreplaced[0] = IsUnitTransforming[0]
//===========================================================================
function UnitEventDestroyGroup takes integer i returns nothing
    if udg_CargoTransportGroup[i] != null then
        call DestroyGroup(udg_CargoTransportGroup[i])
        set udg_CargoTransportGroup[i] = null
    endif
endfunction
function UnitEventCheckAfter takes nothing returns nothing
    local integer id = 0
    local unit u
    loop
        set id = udg_CheckDeathList[id]
        exitwhen id == 0
        set udg_UDex = id
        set u = udg_UDexUnits[id]
        if udg_IsUnitNew[id] then
            //The unit was just created.
            set udg_IsUnitNew[id] = false
            set udg_UnitIndexEvent = 1.50 //New event requested by SpellBound to detect when unit fully enters scope.
            set udg_UnitIndexEvent = 0.00
        elseif udg_IsUnitTransforming[id] then
           //Added 21 July 2017 to fix the issue re-adding this ability in the same instant
           set udg_UnitTypeEvent = 0.00
           set udg_UnitTypeEvent = 1.00
           set udg_UnitTypeOf[id] = GetUnitTypeId(u) //Set this afterward as otherwise the user won't know what the previous unittype was.
           set udg_IsUnitTransforming[id] = false
           call UnitAddAbility(u, udg_DetectTransformAbility)
        elseif udg_IsUnitAlive[id] then
            //The unit has started reincarnating.
            set udg_IsUnitReincarnating[id] = true
            set udg_IsUnitAlive[id] = false
            set udg_DeathEvent = 0.50
            set udg_DeathEvent = 0.00
        elseif GetUnitTypeId(u) != 0 and not IsUnitType(u, UNIT_TYPE_DEAD) then //with vJass, could just use UnitAlive instead of both of these values.
            //Moved this code to fire after a 0 second timer instead.
            set udg_IsUnitAlive[id] = true
            set udg_DeathEvent = 2.00
            set udg_DeathEvent = 0.00
            set udg_IsUnitReincarnating[id] = false
        endif
        set udg_CheckDeathInList[id] = false
    endloop
    set u = null
    //Empty the list
    set udg_CheckDeathList[0] = 0
endfunction
function UnitEventCheckAfterProxy takes integer i returns nothing
    if udg_CheckDeathList[0] == 0 then
        call TimerStart(udg_CheckDeathTimer, 0.00, false, function UnitEventCheckAfter)
    endif
    if not udg_CheckDeathInList[i] then
        set udg_CheckDeathList[i] = udg_CheckDeathList[0]
        set udg_CheckDeathList[0] = i
        set udg_CheckDeathInList[i] = true
    endif
endfunction

function UnitEventOnUnload takes nothing returns nothing
    local integer i = udg_UDex
    call GroupRemoveUnit(udg_CargoTransportGroup[GetUnitUserData(udg_CargoTransportUnit[i])], udg_UDexUnits[i])
    set udg_IsUnitBeingUnloaded[i] = true
    set udg_CargoEvent = 0.00
    set udg_CargoEvent = 2.00
    set udg_CargoEvent = 0.00
    set udg_IsUnitBeingUnloaded[i] = false
    if not IsUnitLoaded(udg_UDexUnits[i]) or IsUnitType(udg_CargoTransportUnit[i], UNIT_TYPE_DEAD) or GetUnitTypeId(udg_CargoTransportUnit[i]) == 0 then
        set udg_CargoTransportUnit[i] = null
    endif
endfunction

function UnitEventOnDeath takes nothing returns boolean
    local integer pdex = udg_UDex
    set udg_UDex = GetUnitUserData(GetTriggerUnit())
    if udg_UDex != 0 then
        set udg_KillerOfUnit[udg_UDex] = GetKillingUnit() //Added 29 May 2017 for GIMLI_2 
        set udg_IsUnitAlive[udg_UDex] = false
        set udg_DeathEvent = 0.00
        set udg_DeathEvent = 1.00
        set udg_DeathEvent = 0.00
        set udg_KillerOfUnit[udg_UDex] = null
        if udg_CargoTransportUnit[udg_UDex] != null then
            call UnitEventOnUnload()
        endif
    endif
    set udg_UDex = pdex
    return false
endfunction
  
function UnitEventOnOrder takes nothing returns boolean
    local integer pdex = udg_UDex
    local unit u = GetFilterUnit()
    local integer i = GetUnitUserData(u)
    if i > 0 then
        set udg_UDex = i
        if GetUnitAbilityLevel(u, udg_DetectRemoveAbility) == 0 then
            if not udg_IsUnitRemoved[i] then
                set udg_IsUnitRemoved[i] = true
                set udg_IsUnitAlive[i] = false
                set udg_SummonerOfUnit[i] = null
                
                //For backwards-compatibility:
                set udg_DeathEvent = 0.00
                set udg_DeathEvent = 3.00
                set udg_DeathEvent = 0.00
                
                //Fire deindex event for UDex:
                set udg_UnitIndexEvent = 0.00
                set udg_UnitIndexEvent = 2.00
                set udg_UnitIndexEvent = 0.00
                
                set udg_UDexNext[udg_UDexPrev[i]] = udg_UDexNext[i]
                set udg_UDexPrev[udg_UDexNext[i]] = udg_UDexPrev[i]
                
                // Recycle the index for later use
                set udg_UDexUnits[i] = null
                set udg_UDexPrev[i] = udg_UDexLastRecycled
                set udg_UDexLastRecycled = i
                call UnitEventDestroyGroup(i)
            endif
        elseif not udg_IsUnitAlive[i] then
            if not IsUnitType(u, UNIT_TYPE_DEAD) then
                call UnitEventCheckAfterProxy(i) //modified 22 Oct 2022 to ensure the unit is fully revived before firing the event.
            endif
        elseif IsUnitType(u, UNIT_TYPE_DEAD) then
            if udg_IsUnitNew[i] then
                //This unit was created as a corpse.
                set udg_IsUnitAlive[i] = false
                set udg_DeathEvent = 0.00
                set udg_DeathEvent = 1.00
                set udg_DeathEvent = 0.00
            elseif udg_CargoTransportUnit[i] == null or not IsUnitType(u, UNIT_TYPE_HERO) then
                //The unit may have just started reincarnating.
                call UnitEventCheckAfterProxy(i)
            endif
        elseif GetUnitAbilityLevel(u, udg_DetectTransformAbility) == 0 and not udg_IsUnitTransforming[i] then
            set udg_IsUnitTransforming[i] = true
            call UnitEventCheckAfterProxy(i)  //This block has been updated on 21 July 2017
        endif
        if udg_CargoTransportUnit[i] != null and not udg_IsUnitBeingUnloaded[i] and not IsUnitLoaded(u) or IsUnitType(u, UNIT_TYPE_DEAD) then
            call UnitEventOnUnload()
        endif
        set udg_UDex = pdex
    endif
    set u = null
    return false
endfunction
function UnitEventOnSummon takes nothing returns boolean
    local integer pdex = udg_UDex
    set udg_UDex = GetUnitUserData(GetTriggerUnit())
    if udg_IsUnitNew[udg_UDex] then
        set udg_SummonerOfUnit[udg_UDex] = GetSummoningUnit()
        set udg_UnitIndexEvent = 0.00
        set udg_UnitIndexEvent = 0.50
        set udg_UnitIndexEvent = 0.00
    endif
    set udg_UDex = pdex
    return false
endfunction
function UnitEventOnLoad takes nothing returns boolean
    local integer pdex = udg_UDex
    local integer i = GetUnitUserData(GetTriggerUnit())
    local integer index
    if i != 0 then
        set udg_UDex = i
        if udg_CargoTransportUnit[i] != null then
            call UnitEventOnUnload()
        endif
        //Loaded corpses do not issue an order when unloaded, therefore must
        //use the enter-region event method taken from Jesus4Lyf's Transport.
        if not udg_IsUnitAlive[i] then
            call SetUnitX(udg_UDexUnits[i], udg_WorldMaxX)
            call SetUnitY(udg_UDexUnits[i], udg_WorldMaxY)
        endif
        
        set udg_CargoTransportUnit[i] = GetTransportUnit()
        set index = GetUnitUserData(udg_CargoTransportUnit[i])
        if udg_CargoTransportGroup[index] == null then
            set udg_CargoTransportGroup[index] = CreateGroup()
        endif
        call GroupAddUnit(udg_CargoTransportGroup[index], udg_UDexUnits[i])
        set udg_CargoEvent = 0.00
        set udg_CargoEvent = 1.00
        set udg_CargoEvent = 0.00
        set udg_UDex = pdex
    endif
    return false
endfunction
function UnitEventEnter takes nothing returns boolean
    local integer pdex = udg_UDex
    local integer i = udg_UDexLastRecycled
    local unit u = GetFilterUnit()
    if udg_UnitIndexerEnabled and GetUnitAbilityLevel(u, udg_DetectRemoveAbility) == 0 then
        //Generate a unique integer index for this unit
        if i == 0 then
            set i = udg_UDexMax + 1
            set udg_UDexMax = i
        else
            set udg_UDexLastRecycled = udg_UDexPrev[i]
        endif
        //Link index to unit, unit to index
        set udg_UDexUnits[i] = u
        call SetUnitUserData(u, i)
        
        //For backwards-compatibility, add the unit to a linked list
        set udg_UDexNext[i] = udg_UDexNext[0]
        set udg_UDexPrev[udg_UDexNext[0]] = i
        set udg_UDexNext[0] = i
        set udg_UDexPrev[i] = 0

        set udg_CheckDeathInList[i] = false

        call UnitAddAbility(u, udg_DetectRemoveAbility)
        call UnitMakeAbilityPermanent(u, true, udg_DetectRemoveAbility)
        call UnitAddAbility(u, udg_DetectTransformAbility)
        set udg_UnitTypeOf[i] = GetUnitTypeId(u)
        set udg_IsUnitNew[i] = true
        set udg_IsUnitAlive[i] = true
        set udg_IsUnitRemoved[i] = false
        set udg_IsUnitReincarnating[i] = false
        set udg_IsUnitPreplaced[i] = udg_IsUnitPreplaced[0] //Added 29 May 2017 for Spellbound
        call UnitEventCheckAfterProxy(i)
        
        //Fire index event for UDex
        set udg_UDex = i
        set udg_UnitIndexEvent = 0.00
        set udg_UnitIndexEvent = 1.00
        set udg_UnitIndexEvent = 0.00
    else
        set udg_UDex = GetUnitUserData(u)
        if udg_CargoTransportUnit[udg_UDex] != null and not IsUnitLoaded(u) then
            //The unit was dead, but has re-entered the map.
            call UnitEventOnUnload()
        endif
    endif
    set udg_UDex = pdex
    set u = null
    return false
endfunction
//===========================================================================
function UnitEventInit takes nothing returns nothing
    local integer i = bj_MAX_PLAYER_SLOTS //update to make it work with 1.29 
    local player p
    local trigger t = CreateTrigger()
    local trigger load = CreateTrigger()
    local trigger death = CreateTrigger()
    local trigger summon = CreateTrigger()
    local rect r = GetWorldBounds()
    local region re = CreateRegion()
    local boolexpr enterB = Filter(function UnitEventEnter)
    local boolexpr orderB = Filter(function UnitEventOnOrder)
    set udg_WorldMaxX = GetRectMaxX(r)
    set udg_WorldMaxY = GetRectMaxY(r)
    call RegionAddRect(re, r)
    call RemoveRect(r)
    call UnitEventDestroyGroup(0)
    call UnitEventDestroyGroup(1)
    
    set udg_CheckDeathList[0] = 0
    set udg_UnitIndexerEnabled = true
    call TriggerRegisterEnterRegion(CreateTrigger(), re, enterB)
    call TriggerAddCondition(load, Filter(function UnitEventOnLoad))
    call TriggerAddCondition(death, Filter(function UnitEventOnDeath))
    call TriggerAddCondition(summon, Filter(function UnitEventOnSummon))
    loop
        set i = i - 1
        set p = Player(i)
        call SetPlayerAbilityAvailable(p, udg_DetectRemoveAbility, false)
        call SetPlayerAbilityAvailable(p, udg_DetectTransformAbility, false)
        call TriggerRegisterPlayerUnitEvent(summon, p, EVENT_PLAYER_UNIT_SUMMON, null)
        call TriggerRegisterPlayerUnitEvent(t, p, EVENT_PLAYER_UNIT_ISSUED_ORDER, orderB)
        call TriggerRegisterPlayerUnitEvent(death, p, EVENT_PLAYER_UNIT_DEATH, null)
        call TriggerRegisterPlayerUnitEvent(load, p, EVENT_PLAYER_UNIT_LOADED, null)
        call GroupEnumUnitsOfPlayer(bj_lastCreatedGroup, p, enterB)
        exitwhen i == 0
    endloop
    set summon = null
    set death = null
    set load = null
    set re = null
    set enterB = null
    set orderB = null
    set p = null
    set r = null
    set t = null
endfunction
function InitTrig_Unit_Event takes nothing returns nothing
endfunction
Unit In Action v 1.0.0.0
Addon to UnitEvent to simplify the AI experience of tracking which units can and cannot perform actions

UnitIndexEvent == 1.00 >> Created
DeathEvent == 2.00 >> Ressurrected
CargoEvent == 2.00 >> Unloaded from a transport
Unit In Action
Events
Game - UnitIndexEvent becomes Equal to 1.00
Game - DeathEvent becomes Equal to 2.00
Game - CargoEvent becomes Equal to 2.00
Conditions
UnitInAction[UDex] Equal to False
Actions
Set Variable Set UnitInAction[UDex] = "true"
Set Variable Set UnitInActionEvent = "0.00"
Set Variable Set UnitInActionEvent = "1.00"
Set Variable Set UnitInActionEvent = "0.00"
UnitIndexEvent == 2.00 >> Removed from game
DeathEvent == 0.50 >> Starts Reincarnating
DeathEvent == 1.00 >> Dies
CargoEvent == 1.00 >> Loaded into a transport
Unit Inaction
Events
Game - UnitIndexEvent becomes Equal to 2.00
Game - DeathEvent becomes Equal to 0.50
Game - DeathEvent becomes Equal to 1.00
Game - CargoEvent becomes Equal to 1.00
Conditions
UnitInAction[UDex] Equal to True
Actions
Set Variable Set UnitInAction[UDex] = "false"
Set Variable Set UnitInActionEvent = "0.00"
Set Variable Set UnitInActionEvent = "2.00"
Set Variable Set UnitInActionEvent = "0.00"
On Create
Events
Game - UnitIndexEvent becomes Equal to 1.00
Conditions
Actions
Set Variable Set UnitName[UDex] = ((Name of UDexUnits[UDex]) + ( + (String(UDex))))
Game - Display to (All players) the text: (UnitName[UDex] + has been created)
On CompletelyCreated
Events
Game - UnitIndexEvent becomes Equal to 1.50
Conditions
Actions
Game - Display to (All players) the text: (UnitName[UDex] + 's creation is now complete.)
On Summon
Events
Game - UnitIndexEvent becomes Equal to 0.50
Conditions
Actions
Game - Display to (All players) the text: (UnitName[UDex] + ( was summoned by + UnitName[(Custom value of SummonerOfUnit[UDex])]))
On Death
Events
Game - DeathEvent becomes Equal to 1.00
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
KillerOfUnit[UDex] Equal to No unit
Then - Actions
Game - Display to (All players) the text: (UnitName[UDex] + has died)
Else - Actions
Game - Display to (All players) the text: (UnitName[UDex] + ( was killed by + UnitName[(Custom value of KillerOfUnit[UDex])]))
On Reincarnate
Events
Game - DeathEvent becomes Equal to 0.50
Conditions
Actions
Game - Display to (All players) the text: (UnitName[UDex] + has started reincarnating)
On Revival
Events
Game - DeathEvent becomes Equal to 2.00
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
IsUnitReincarnating[UDex] Equal to True
Then - Actions
Game - Display to (All players) the text: (UnitName[UDex] + has finished reincarnating)
Else - Actions
Game - Display to (All players) the text: (UnitName[UDex] + has come back to life)
On Removal
Events
Game - UnitIndexEvent becomes Equal to 2.00
Conditions
Actions
Game - Display to (All players) the text: (UnitName[UDex] + is gone forever)
On Load
Events
Game - CargoEvent becomes Equal to 1.00
Conditions
Actions
Game - Display to (All players) the text: (UnitName[UDex] + ( was loaded into + UnitName[(Custom value of CargoTransportUnit[UDex])]))
On Unload
Events
Game - CargoEvent becomes Equal to 2.00
Conditions
Actions
Game - Display to (All players) the text: (UnitName[UDex] + ( was unloaded from + UnitName[(Custom value of CargoTransportUnit[UDex])]))
On Transform
Events
Game - UnitTypeEvent becomes Equal to 1.00
Conditions
Actions
Set Variable Set UnitName[UDex] = ((Name of UDexUnits[UDex]) + ( + (String(UDex))))
Game - Display to (All players) the text: (UnitName[UDex] + has transformed!)
Removing a paused unit from a transport no longer causes a bug with indexing - used to be a huge problem in the AutoIndex/AIDS days.
On Esc
Events
Player - Player 1 (Red) skips a cinematic sequence
Conditions
Actions
Unit - Pause Knight 0003 <gen>
Wait 0.00 seconds
Unit - Remove Knight 0003 <gen> from the game
Top