• 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.

[Snippet] Invul Units

Level 9
Joined
Apr 23, 2011
Messages
460
Picks every unit on the map that is created before event occurs and makes them invulnerable. Mostly to be used for units that are created at map initialization or literally right after it. The practical use for this spell is if you have global units of a type that are created on map init that you want invulnerable, but you do not want all units of that type to be invulnerable you can use this script to set only units that are created before initialization (Placed in WE) or created at or milliseconds after initialization.
You can however change the event in the configuration trigger to whatever you like, but keep in mind if you do this, if you have any units of the types you declare on the map, all of them will become invulnerable. You can edit this by setting up a boolean exp filter on it to check for which player it belongs to though ; ). Script is annotated to where you need to edit. Credits to Bribe for helping me make the script and for parts of the layout. Also for helping me better understand structs and how to run them.

JASS:
library InvulUnits initializer init
/*  ################################################################################################################
    #Can be used to invul all units of declared types in hashtable at any event occurrence.                        #
    #Please note if you do use it at event occurrence other than .5 seconds after init, ALL units                  #
    #will be invul. If you apply a filter to the GroupEnumUnitsInRect it will make only units matching condition   #
    #invul. Using this method you can apply a multi-condition filter and narrow down what units you want invul.    #
    #You can also change the rct variable to be any rect in your map :P.                                           #
    #This system is really handy if you need to invul some units. If you want to make some units invul, do the     #
    #same as above but replace "true" in the hashtable boolean saves with false. The unit has to be invul to start #
    #for this to have any affect.                                                                                  #
    ################################################################################################################
    Thanks to Bribe for his input on this system, always a helpful person.
    Credits to me, khamarr3524, along with Bribe if used. Thanks :)
*/    
    struct InvulUnits extends array

        private static hashtable ht = InitHashtable()
        private static rect rct
    
        private static method decTypes takes nothing returns nothing
            call SaveBoolean(.ht, 'vigi', 0, true)
            call SaveBoolean(.ht, 'hfoo', 0, true)
        endmethod
    
        private static method doInvul takes nothing returns nothing
            call SetUnitInvulnerable(GetEnumUnit(), LoadBoolean(.ht, GetUnitTypeId(GetEnumUnit()), 0))
        endmethod
    
        static method main takes nothing returns nothing
            local group g = CreateGroup()
            set rct = bj_mapInitialPlayableArea
            call GroupEnumUnitsInRect(g, rct, null)
            call .decTypes()
            call ForGroup(g, function thistype.doInvul)
            call FlushParentHashtable(.ht)
            set .ht = null
            call DestroyGroup(g)
            set g = null
        endmethod
    endstruct

    private function invul takes nothing returns nothing
        call InvulUnits.main()
    endfunction

    private function init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerAddAction(t, function invul)
        call TriggerRegisterTimerEvent(t, .5, false)
        set t = null
    endfunction
endlibrary
 
Last edited:
Level 9
Joined
Apr 23, 2011
Messages
460
Edit: Wrapped in a library, condensed coding into one trigger base. Redid variable names, function and method names and "cameled" the variable and function/method names. Also added an explanation and how to configure to the top of the library.
 
Last edited:
Level 23
Joined
Jan 1, 2009
Messages
1,615
I honestly don't see a really practicable use for this. It's a simple group loop with a small filter, written -if needed- in a few minutes by anyone.
Also you state in the description that you can change the filter & the event, but you don't distinguish it in the code (put the calibration function and the event/time at the top with information how to change what...).
If I have to "modify" your code in order to get what I want, I can just write this 20 lines myself.
Also what is the function "invul" for if you can just use main?
 
Top