Snippet Any Unit Is Unloaded even workaround

DioD

New Member
Reaction score
57
There is no event for unit UNload (there is unit loaded to transport event but no unload event).

First and last way to detect this used "worldwide" - periodic checks.

But, i managed to get some workaround.

note:
your map must have free area, where units normally cannot get, 1-2 cells boundary, otherwise usage if this code is not possible.
codeexec methods are experemental
memory allocation is experemental

JASS:
library UUE initializer INIT
//Custom event for Unit Unit Unloaded from transport event.
//Copypaste to any place, it will work fine without any modifications.
//You may refer to unloaded unit with GetFilterUnit() evar.


    globals
    
        private trigger RegLoaded
        private trigger RegReturn
        private group Marked

        private force FFCXZ__ForceExec
        private boolexpr array ExecData
        private integer ExecMeta
        
        private real XCC
        private real YCC
        
        
    endglobals
    
    
function UUE_Register takes code data, boolean Active returns nothing
    local integer i = 0
    local boolexpr Check = Condition(data)
    local boolean FFAG = false
    
    loop
        set FFAG = ExecData<i> == Check
        exitwhen FFAG or i == ExecMeta
        set i = i + 1
    endloop
    
    if Active then
        if FFAG then
            //Given function already registered for system
            //Multiple registrations for same function not allowed for security reasons
            //You may tweak this but not supported by me
            return
        endif
        
        set ExecData[ExecMeta] = Check
        set ExecMeta = ExecMeta + 1
        return
    endif
    
    if not FFAG then
        //given function not registered by system
        //its unregistration is not possible
        return
    endif
    
    if i != ExecMeta then
        set ExecData<i> = ExecData[ExecMeta]
    endif
    
    set ExecMeta = ExecMeta - 1

endfunction

private function REG takes nothing returns boolean
    call GroupAddUnit(Marked,GetTriggerUnit())
    
    call SetUnitX(GetTriggerUnit(),XCC)
    call SetUnitY(GetTriggerUnit(),YCC)
    
    //call BJDebugMsg(&quot;REG &quot; + GetUnitName(GetTriggerUnit()))
    
    return false
endfunction

private function MAIN takes nothing returns boolean

    local integer i = 0
    
    //call BJDebugMsg(&quot;MAIN &quot; + GetUnitName(GetFilterUnit()))

    if not IsUnitInGroup(GetFilterUnit(),Marked) then
        return false
    endif
    
    call GroupRemoveUnit(Marked, GetFilterUnit())
    
    loop
        exitwhen i == ExecMeta
        call ForceEnumPlayers(FFCXZ__ForceExec,ExecData<i>)
        set i = i + 1
    endloop
    
    return false
endfunction


private function START takes nothing returns nothing
    local region RegReg= CreateRegion()
    
    set RegReturn = CreateTrigger()
    call RegionAddRect(RegReg,GetPlayableMapRect())
    call TriggerRegisterEnterRegion(RegReturn,RegReg,Condition(function MAIN))
    //call RemoveRegion(RegReg)
    //set RegReg = null
    
    
    set RegLoaded = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(RegLoaded, EVENT_PLAYER_UNIT_LOADED)
    call TriggerAddCondition(RegLoaded, Condition(function REG))
    
    set Marked = CreateGroup()
    set ExecMeta = 0
endfunction

private function STOP takes nothing returns nothing
    call BJDebugMsg(&quot;Press ESC to switch exec function&quot;)
    call BJDebugMsg(&quot;There are 2 functions present at demomap, up to 1500 functions supported&quot;)
//na
endfunction

private function INIT takes nothing returns nothing
    local rect xx = GetWorldBounds()
    call TimerStart(CreateTimer(),1.00,false,function STOP)
    set XCC = GetRectMinX(xx)
    set YCC = GetRectMinX(xx)
    call RemoveRect(xx)
    set xx = null
    
    set FFCXZ__ForceExec = CreateForce()
    call ForceAddPlayer(FFCXZ__ForceExec,Player(0))
    
    call START()
endfunction

endlibrary</i></i></i>


JASS:
globals

    boolean flag = false

endglobals

function ZOZO takes nothing returns boolean
    call BJDebugMsg(&quot;ZOZO EXEC &quot; + GetUnitName(GetFilterUnit()))
    return false
endfunction

function AOAO takes nothing returns boolean
    call BJDebugMsg(&quot;AOAO EXEC &quot; + GetUnitName(GetFilterUnit()))
    return false
endfunction

function Trig_Untitled_Trigger_005_Actions takes nothing returns nothing
    set flag = not flag

    call UUE_Register(function ZOZO, flag)
    call UUE_Register(function AOAO, not flag)
endfunction

//===========================================================================
function InitTrig_Unit_Unloaded_Sample takes nothing returns nothing
    set gg_trg_Unit_Unloaded_Sample = CreateTrigger(  )
    call TriggerRegisterPlayerEventEndCinematic( gg_trg_Unit_Unloaded_Sample, Player(0) )
    call TriggerAddAction( gg_trg_Unit_Unloaded_Sample, function Trig_Untitled_Trigger_005_Actions )
endfunction
 

Attachments

  • Unit Unload Event Sample Map.w3x
    29 KB · Views: 231

Weep

Godspeed to the sound of the pounding
Reaction score
401
Your method to move the unit and detect region re-entry was already used in Jesus4Lyf's Transport library - it's not new information.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top