• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Detecting unloaded units.

Status
Not open for further replies.
Yep, I'd suggest the transport lib.

If you don't want to use it, then you should basically have two triggers. One that registers when a unit is loaded, and one that registers when a unit enters the map.

For the first trigger, just add all units that are loaded into a unit group. For the second, just check if the unit entering the map is in that group. It should work. Transport does that same method afaik, it just has extra nifty stuff like getting the transport unit data (eg: how many are loaded etc.).
 
Whoops. :p You're right, for a second I thought it would fire the event. I guess my memory is a little off. Anyway, I still suggest using transport, but it is also fine to do something like this:
JASS:
scope LalatestUnload initializer Init
    globals
        private group g = CreateGroup()
    endglobals
    
    private function lulu takes nothing returns boolean
        //unit is loaded
        call GroupAddUnit(g,GetTriggerUnit())
        return false
    endfunction
    
    private function checkifloaded takes nothing returns nothing
        local unit f = GetEnumUnit()
        if not IsUnitLoaded(f) then
            call GroupRemoveUnit(g,f)
            //unloaded, do whatever
        endif
        set f = null
    endfunction
    
    private function Enumerationlala takes nothing returns nothing
        call ForGroup(g,function checkifloaded)
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t  = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t,EVENT_PLAYER_UNIT_LOADED)
        call TriggerAddCondition(t,Condition(function lulu))

        call TimerStart(CreateTimer(),0.08,true,function Enumerationlala)
        //modify interval to determine how frequently it will check it
    endfunction

endscope

It should work, although it is not entirely efficient since it will not register it immediately. (still pretty fast though)
 
Status
Not open for further replies.
Top