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?
 
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?
 
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.
 
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?
 
>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.
 
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.
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    News portal has been retired. Main page of site goes to Headline News forum now
  • The Helper The Helper:
    I am working on getting access to the old news portal under a different URL for those that would rather use that for news before we get a different news view.
  • Ghan Ghan:
    Easily done
    +1
  • The Helper The Helper:
    https://www.thehelper.net/pages/news/ is a link to the old news portal - i will integrate it into the interface somewhere when i figure it out
  • Ghan Ghan:
    Need to try something
  • Ghan Ghan:
    Hopefully this won't cause problems.
  • Ghan Ghan:
    Hmm
  • Ghan Ghan:
    I have converted the Headline News forum to an Article type forum. It will now show the top 20 threads with more detail of each thread.
  • Ghan Ghan:
    See how we like that.
  • The Helper The Helper:
    I do not see a way to go past the 1st page of posts on the forum though
  • The Helper The Helper:
    It is OK though for the main page to open up on the forum in the view it was before. As long as the portal has its own URL so it can be viewed that way I do want to try it as a regular forum view for a while
  • Ghan Ghan:
    Yeah I'm not sure what the deal is with the pagination.
  • Ghan Ghan:
    It SHOULD be there so I think it might just be an artifact of having an older style.
  • Ghan Ghan:
    I switched it to a "Standard" article forum. This will show the thread list like normal, but the threads themselves will have the first post set up above the rest of the "comments"
  • The Helper The Helper:
    I don't really get that article forum but I think it is because I have never really seen it used on a multi post thread
  • Ghan Ghan:
    RpNation makes more use of it right now as an example: https://www.rpnation.com/news/
  • The Helper The Helper:
  • The Helper The Helper:
    What do you think Tom?
  • tom_mai78101 tom_mai78101:
    I will have to get used to this.
  • tom_mai78101 tom_mai78101:
    The latest news feed looks good

      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