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

Temporary units attacking closest enemy units

Status
Not open for further replies.
Level 5
Joined
Nov 14, 2007
Messages
161
ok, this is how i have it.
i have some temp units allied to a human player and some creep computer units attacking.
This skill will order the allied units to temporarily attack/move to the closest computer units.
Now the catch is the allied units have locust and are constantly being made with a temporary life so during the skill, they will be dying/being created. i would need this to repeat for ~20 seconds and include newly spawned units to also attack/move towards the computer.

my idea was to get2 unit groups, 1 the allied, 1 the near by computers, and loop a check of the first unit for allied to all the others to see which is closest and then order him to move to that one, then on to the next, etc etc. but im not sure if that is effecient or will make it lag to much for those 20 seconds.

i'd perfer jass but if it's a GUI way, i can change it over.

let me know i need to explain anything better.
thanks a bunch!
 
Level 5
Joined
Nov 14, 2007
Messages
161
So this is what i came up with and it does seem to work, BUT lags to shit every iteration of the loop, more specifically i think on the GetClosestUnitInRange() part. any ideas? there are quite a few units on the map i guess, but even when there are only ~ 30 it laggs just as bad.

JASS:
function Trig_Back_Draft_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A02C'
endfunction

function filterbackdraft takes nothing returns boolean
    return ( GetUnitTypeId(GetFilterUnit()) == 'h006' )
endfunction
      
function closefilter takes nothing returns boolean
    if GetUnitState(GetFilterUnit(), UNIT_STATE_LIFE) > 0 then    
        if GetOwningPlayer(GetFilterUnit()) == Player(10) then
            return true
        endif
        if GetOwningPlayer(GetFilterUnit()) == Player(11) then 
            return true
        endif
    endif
    return false
endfunction 

function Trig_Back_Draft_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local player p = GetOwningPlayer(u)
    local unit fire
    local unit target
    local group g = CreateGroup()
    local integer j = GetUnitAbilityLevel(u, 'A02C')
    local integer i = 0
    local real x 
    local real y
    local real x2
    local real y2 
    local real angle
    local real distance
    
    set j = j*2 + 5
    loop
        exitwhen i > j
        call GroupEnumUnitsOfPlayer(g, p, Filter(function filterbackdraft))
        loop
            set fire = FirstOfGroup(g)
            exitwhen fire == null
            if GetOwningPlayer(fire) != p then
                call GroupRemoveUnit(g, fire)
            endif
            set x = GetUnitX(fire)
            set y = GetUnitY(fire)
        
            set target = GetClosestUnitInRange(x, y, 2000, Filter(function closefilter))
            set y2 = GetUnitY(target)
            set x2 = GetUnitX(target)
            call IssuePointOrder(fire, "move", x2, y2)
// originally was going to knock the units back, but i thought that was the cuase of the lag, so i ordered them to move instead
//            set angle = Atan2(y2 - y, x2 - x) 
//            set distance = SquareRoot((y2-y)*(y2-y)+(x2-x)*(x2-x))
//            call Knockback.create(fire, angle , 400, distance)
             
            call GroupRemoveUnit(g, fire)
            set target = null
            set fire = null
        endloop
        call TriggerSleepAction(1.5)
        set i = i + 1
    endloop
    call DestroyGroup(g)
    set g = null                        
    set u = null
endfunction
 
Status
Not open for further replies.
Top