Snippet Any Unit Is Unloaded even workaround

DioD

New Member
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

Weep

Godspeed to the sound of the pounding
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.
  • tom_mai78101 tom_mai78101:
    I have a GIF though
  • tom_mai78101 tom_mai78101:
    In the GIF, I've configured it so the lower the "Main Value" is, the better. I had to compress it pretty far down though.
  • tom_mai78101 tom_mai78101:
    And this is the thread with the video that shows the wall clip. https://tasvideos.org/Forum/Topics/23453
    +2
  • tom_mai78101 tom_mai78101:
    Hmm, about the Headline News, I noticed threads are being moved into the subforum (Health News, Environmental News, etc.). When that happens, the TH Forum Home page loses the articles, and instead would show old articles posted 1 or 2 weeks ago.
  • tom_mai78101 tom_mai78101:
    What do we do with the Home page?
  • Ghan Ghan:
    I added those forums to the filter for that widget.
  • tom_mai78101 tom_mai78101:
    Oh nice. They're back. Thanks.
  • tom_mai78101 tom_mai78101:
    Now I think it makes more sense for me to put news in their own subforums, without worry.
  • The Helper The Helper:
    Awesome Ghan thanks! I was purposely not moving the first 15 news articles in Headline news to the different subforums but I guess I don't have to do that now?
  • tom_mai78101 tom_mai78101:
    Question: Is there a way to remove thread redirects? It creates a copy of the moved thread and takes up space, and I am leaning towards wanting to remove them in the Headline News. But if they have an expiration date, I guess I'm fine with it.
  • The Helper The Helper:
    If you move a thread please leave a permanent redirect. You can delete any redirects after 6 months. The redirects are left to help Search Engines find the moved content.
  • tom_mai78101 tom_mai78101:
    What if you move the permanent redirect, not the thread?
  • The Helper The Helper:
    I think that works but I have not messed with it. You can delete redirects though if you have to that will not delete the original thread
  • The Helper The Helper:
    if a redirect ends up in the same forum as the post it goes to though I think the redirect drops or fails or something but they are not bugged out and when you are working on an indirect the original post is safe.
  • The Helper The Helper:
    Happy Early Friday :)
    +1
  • V-SNES V-SNES:
    Happy Friday :)
  • tom_mai78101 tom_mai78101:
    Fun Friday for me
  • tom_mai78101 tom_mai78101:
    Happy Fun Friday to all.
    +2
  • The Helper The Helper:
    Happy Sunday everyone!!!
  • V-SNES V-SNES:
    Happy Sunday!!!
    +1
  • jonas jonas:
    Happy monday :p
  • jonas jonas:
    Everyone hates mondays?
    +1
  • The Helper The Helper:
    Happy Tuesday!
  • jonas jonas:
    Happy belated tuesday

    Staff online

    • Ghan
      Administrator - Servers are fun

    Members online

    Affiliates

    Hive Workshop NUON Dome World Editor Tutorials

    Network Sponsors

    Apex Steel Pipe - Buys and sells Steel Pipe.
    Top