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