adding units that match conditions into group

W!†A_cRaft

Ultra Cool Member
Reaction score
28
I am roughly new to JASS and i wandered into this problem.

I need to pick every enemy, alive, non-building, non-dummy unit within 200 range around the caster (or dummy to be precise)

The function GetUnitsInRangeOfLocMatching doesnt allow me to put parameters into the matching function and i cannot check wheather the picked unit matches the above mentioned conditios. how should i do this?

I am making a spell that picks units around certain point every few seconds. Made it with a timer to which i bound the caster/dummy/damage/etc.
But it is suppose to damage only enemies and i cannot pick only enemies, how am i suppose to do that?
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
While trying to figgure this out i managed to find out that every time my timer picks units around me (0.03) seconds he picks the dummy (caster) as well as any other friendly units, i managed to get around the part when he ignores them with a loop liek this, but I think it still causes too much stress for RAM because units get picked every tiem even though they arent affected.

JASS:
local group temp = GetUnitsInRangeOfLocAll(140, GetUnitLoc(arrow))
set target = FirstOfGroup(temp)
    loop
        exitwhen (target == null)
        if(not(IsUnitEnemy(target, GetOwningPlayer(u)))) then
        else
            if(IsUnitDeadBJ(target)) then
            else
                call GroupAddUnit(grp, target)
            endif
        endif
    call GroupRemoveUnit(temp, target)
    set target = FirstOfGroup(temp)
    call BJDebugMsg("u loopu")
    endloop
    set target = FirstOfGroup(grp)
    if (target != null) then
//Ability code goes here
    endif


Is ther some better way to do this?
 

Flare

Stops copies me!
Reaction score
662
Global variable + GroupEnumUnitsInRange

JASS:
function GroupCallback takes nothing returns nothing
  ...
endfunction

function GroupFilter takes nothing returns boolean
  return IsUnitEnemy (GetFilterUnit (), GetOwningPlayer (udg_refUnit)) and ...
  //Alternatively, depending on how you plan to use the enumerated units, you may handle all the units in this function, without ever adding them to the group - removes the necessity for the ForGroup call, but it's not possible to do in EVERY situation
endfunction

function Test takes nothing returns nothing
  local group g = CreateGroup ()
  set udg_refUnit = GetTriggerUnit () //Since we need a global variable to reference in the filter function - if you have NewGen, just declare a globals block instead of using a Variable Editor global <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite8" alt=":D" title="Big Grin    :D" loading="lazy" data-shortname=":D" />
  call GroupEnumUnitsInRange (g, GetUnitX (unit), GetUnitY (unit), radius, Condition (function GroupFilter)) //replace the &#039;unit&#039; value for GetUnitX/Y with your desired unit, and &#039;radius&#039; with your desired radius

  call ForGroup (g, function GroupCallback)
endfunction


Assuming you don't have NewGen - if you do, that udg_ global can be replaced with a globals block if you so wish.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
if i use a global it is no longer MUI

Edit: what BJ's? the DebugMessage?
I do have NewGen but i dont know how exactly to reference a global block, and what is the difference between doing it like that and with variable editor?
 

saw792

Is known to say things. That is all.
Reaction score
280
>If I use a global it is no longer MUI
You don't understand how MUI works.
The global variable stores data for an instantaneous action, not a time delayed action, so it will not be overwritten.

The BJs you are using are the ones that show up in red text in the jass tags on thehelper. BJDebugMsgs are fine when used for debugging so don't remove those if you want to debug your script.

Globals blocks are declared with
JASS:
globals
...
endglobals


Read a vJASS tutorial, you sound like you need it.
 

W!†A_cRaft

Ultra Cool Member
Reaction score
28
when i said what BJ's i was being sarcastic because i am using them for debugging purposes of course....
The global variable stores data for an instantaneous action, not a time delayed action, so it will not be overwritten.[/qoute]

even if too units use the ability at same exact time (not that it is likly to happen but)??

is there any difference between the global block and regular global variables made throguh the editor
 
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