• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] Group in a line

Status
Not open for further replies.
Level 2
Joined
Jan 31, 2020
Messages
12
I am trying to deal all the units in line, but deal the damage only once to each target.
I am just wondering if there is better way of doing this because I am using two groups.
Any better way of doing this?

JASS:
    local unit u
    local group g = CreateGroup()
    local group tempGroup = CreateGroup()
    local integer i = 0
    local real x = GetUnitX(tu)
    local real y = GetUnitY(tu)
    local real r = 300
    local real distance = 150.0
    local real tx = GetSpellTargetX()
    local real ty = GetSpellTargetY()
    local real angle = Atan2(ty-y,tx-x)
    local real distX = distance * Cos(angle)
    local real distY = distance * Sin(angle)
    local real loopX = x + distX
    local real loopY = y + distY
    loop
        exitwhen i > 5
        set loopX = loopX + distX
        set loopY = loopY + distY
        call GroupEnumUnitsInRange(tempGroup, loopX, loopY, r, null)
        loop
            set u = FirstOfGroup(tempGroup)
            exitwhen u == null
            if IsUnitInGroup(u, g) == false then
                call GroupAddUnit(g, u)
            endif
            call GroupRemoveUnit(tempGroup, u)
        endloop
        set i = i + 1
    endloop
    loop
        set u = FirstOfGroup(g)
        exitwhen u == null
        // damage
        call GroupRemoveUnit(g, u)
    endloop
    call DestroyGroup(tempGroup)
    call DestroyGroup(g)
    set tempGroup = null
    set g = null
 
Status
Not open for further replies.
Top