unit in range?

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
How would I add a unit in range function to the middle of a spell like below? would I need to make a separate function outside of this one?

Code:
function
  local variables = blah blah
  local unit VarLastCreatedUnit = bj_lastCreatedUnit
  call stuff

  [B]if 
     any unit comes in range of VarLastCreatedUnit
  then
     explode
     kill
     replace
  endif[/B]
endfunction
 

Jazradel

Helping people do more by doing less.
Reaction score
102
Code:
loop
exitwhen number of units in units within range of VarLastCreatedUnit > 0
wait(0.5)
endloop
Would do it directly. A much better method would to create a timer and do the same check every so often. Or if it's stationary, you could also use the Unit in Range event. I recomend using atimer.
 
S

sinners_la_b

Guest
Timer means Handle Vars?

Yes or a better method would be to use structs. You can also use

JASS:


function End takes nothing returns nothing

    local unit killthisunit             = GetTriggerUnit()
    
        call // Do what ever you want with it

endfunction

function Start takes nothing returns nothing
    
    local trigger tr    = CreateTrigger()
    local group g
    local unit next
    
        call GroupEnumUnitsInRange(g, YourX, YourY, YourRadius, YourCondition)
        
                loop
                
                    set next = FirstOfGroup(g)
                            
                            exitwhen next = null
                            
                    call // Do what ever you want here to every unit within range
               endloop
        
call TriggerRegisterUnitInRange(tr, YourUnit, YourRange, YourCondition)
        call TriggerAddAction(tr, function End)

endfunction


The reason we use GroupEnumUnitsInRange() then loop through the group doing whatever we want to the next unit is that the trigger event we used does not recognise units already with range of YourUnit it aonly fires when a units comes in range. So we have to pick the units already in range of the caster when he starts the ability.
 

chovynz

We are all noobs! in different states of Noobism!
Reaction score
130
Oi oi oi. I was hoping to avoid Handle Vars or structs. I'm starting to think that I can't. :( Not for what I want to do.

Thanks Sinners. I'll post a more complete trigger later with some specific questions after trying some things first.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top