• 🏆 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!

[JASS] Counting units hit by AoE

Status
Not open for further replies.
Level 14
Joined
Jul 26, 2008
Messages
1,009
So I'm making a spell that heals the caster depending on how many enemies were hit by the spell. It's a Point targeted AoE.

Problem is, as I'm triggering this I'm running through the function list and I can't seem to find the right Functions to do this. Likely it has to do with me not knowing the name is Add instead of Group or something like that.

Anyways, what's the best way of counting units so that A) You don't hit more than X units with the spell and B) You know how many units were hit by the spell.

I got this far in before I couldn't figure it out:

JASS:
    local unit caster = GetTriggerUnit()
    local unit targ
    local real rad = 350. + 100. * GetUnitAbilityLevel(caster, 'sang')
    local integer maxtargs = 2 + 1 * GetUnitAbilityLevel(caster, 'sang')
    local integer x
    local group SG = CreateGroup()
    set GroupEnumUnitsInRangeOfLocCounted(SG, GetSpellTargetLoc(), rad, Condition(function IsEnemy), maxtargs )
    
    loop
        call GroupAddUnit(SG, targ)
        set x = x + 1
    exitwhen x >= maxtargs
    set caster = null
    set SG = null
    set targ = null

See, GroupEnum...Counted() lets me set a max, but I don't believe it counts how many are in the group. whereas GroupAddUnit() with a loop will let me count it and to a limit, but I need booleans and a way to get if the Unit is in a range, only thing I found was a BJ to do that though.

I think damaging each unit in range that max the conditions would be the easiest way :\

Ahh, ahh, found it. FirstOfGroup(). Had to go back to a tutorial for that one :X
 
Status
Not open for further replies.
Top