HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

scripting AOE damage without using a group

03-19-2008, 12:30 AM#1
wantok
When you need to deal damage in an area of effect you generally make a group, enumerate it with units within the area that meet certain conditions, and then loop through the group and damage each unit individually.

i.e.
Collapse JASS:
function cond takes nothing returns boolean
    return IsPlayerEnemy(GetOwningPlayer(GetFilterUnit()), Player(0)) and IsUnitType(GetFilterUnit(), UNIT_TYPE_GROUND) and GetWidgetLife(GetFilterUnit()) > .415
endfunction

function damage takes nothing returns nothing
   call UnitDamageTarget(UNIT, GetEnumUnit(), //damage stuff follows
endfunction

function abc takes nothing returns nothing
   //...
   call GroupEnumUnitsInRange(TARGET_GROUP, dat.x, dat.y, 85, Condition(function cond))
   call ForGroup(TARGET_GROUP, function damage)
   //or maybe you use FirstOfGroup
endfunction
   

I was making my submission for the latest spell contest and I needed to make my sheep deal area of effect damage when they exploded. I was feeling a bit lazy and didn't want to write all that code above, so I looked for an alternative. After some fiddling around, I gave my sheep an ability based off of Goblin Land Mine explode on death. Then at the appropriate time, I just killed the sheep. Using this method, I can accomplish the same AOE damage as the code above with just one line of code.

Collapse JASS:
call KillUnit(CreateUnit(Player(0), DUMMY_UNIT_WITH_ABILITY, x, y, 0))
//add a special effect here if you like

Obviously, you have to set up the ability in the object editor first. Use the Targets Allowed field to filter the units. The ability comes with primary and secondary damage and radius fields which are a lot more work to implement soley through triggers.

This method won't work for everything. There may be times when you need to filter units for specific buffs or you may need flexibility in the damage you want dealt. Even so, there should be times when this is useful.
03-19-2008, 01:07 AM#2
DioD
Also you can make dummy with attack, order\create it in single line of code, death and other options (like negative regen) type in OE.
03-19-2008, 01:45 AM#3
Rising_Dusk
Be forewarned, goblin land mine ability factors in a units armor when dealing damage. Typically, spells are scripted to deal spell damage, not physical damage.
03-19-2008, 01:54 AM#4
grim001
Or even simpler, you can make your own DamageUnitsInAoE function.
03-19-2008, 02:12 AM#5
wantok
Looking at this again, I don't really know why I thought it was a big enough deal to make a post about it.

I do wonder how efficient this is compared to using a group though.
03-19-2008, 03:59 AM#6
burningice95
Don't fix what isn't broken...
03-19-2008, 06:07 AM#7
chobibo
Quote:
I do wonder how efficient this is compared to using a group though.
AoE damage using Goblin land mines ability are easy to configure but are limited to what it can do, jass coded AoE damage requires much more effort in setting it up but is much more configurable.