How to run a unit through a filter without the filter taking anything

cleeezzz

The Undead Ranger.
Reaction score
268
think GroupEnumUnitsInRange, it takes group, range, and boolexpr, whats interesting is the boolexpr does not take anything so how does this function run the unit through this filter?
 

_whelp

New Member
Reaction score
54
GetFilterUnit() is the unit that is checked in the filter.

If what you desire is outside units, vJass [from the Jass NewGen Pack] is what you want.

[Declare some global and use it through the filter.]

Ex.

JASS:
scope Stupidity initializer Init

    globals
        private unit Caster
    endglobals

    public function Filt takes nothing returns nothing
         return IsUnitEnemy(GetFilterUnit(), GetOwningPlayer(Caster))
    endfunction

    private function Init takes nothing returns nothing
         set Caster = //....Some Unit Stuff
         //...Some Group Stuff
    endfunction
endscope
 

cleeezzz

The Undead Ranger.
Reaction score
268
no lets say, i wanted to create my own Group function that takes a condition. how would i do that

example GroupFilterUnit takes group g, group g2, boolexpr filter returns nothing

it takes units from group g, runs them through a filter and adds them to g2

it needs to work when the function GroupFilterUnit isnt inside the scope i want to use it in.

ex:

JASS:
scope Random initializer Init
function PrivateFilter takes nothing returns boolean
      return GetWidgetState(GetFilterUnit()) > .405
endfunction
function Actions takes nothing returns nothing
      local group g2 = CreateGroup()
      call GroupFilterUnit(g,g2,Condition(function PrivateFilter))
endfunction
//cut off, i dont care about the rest right now


the GroupFilterUnit function randomly somewhere else in the triggers
JASS:
function GroupFilterUnit takes group g, group g2, boolexpr filter returns nothing
//now whatt? how do i filter the units?
endfunction
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Wc3 passes the GetFilterUnit() into the filter functions as everyone above has pointed out.
 

cleeezzz

The Undead Ranger.
Reaction score
268
ok then how do i do the trigger posted above

>Wc3 passes the GetFilterUnit() into the filter functions as everyone above has pointed out.
i get it, but how do i pass units through filter functions through a custom function.
 

Rainther

I guess I should write something of value here...
Reaction score
61
I believe your solution would be best solved with a regular GroupEnum and add this group to Group 2 and have it run through a filter to get the unit in Group 1.
 

cleeezzz

The Undead Ranger.
Reaction score
268
>This one?
no i want to create a function i can use throughout the whole map, not just inside the scope EDIT: since its public i guess it can be used throughout the map but still, the problem below.
and all the GroupEnums are adding additional units, i just wanna filter it

plus if i did that, i would have to create a lot of public filters, i just want to create some private filters and plug them into a function.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
What do you want to filter? you need to tell us more if you want help, stop holing the information back.
 

cleeezzz

The Undead Ranger.
Reaction score
268
Huh what am I holding back? My function above clearly says I want a custom function to filter units from group g to group g2 based on whether unit is alive. The native geoup enums merely add units on the map with some filter but I want to filter mine taking group g and adding all alive units into group g2
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56

cleeezzz

The Undead Ranger.
Reaction score
268
=/ like i said, i want a custom function so i can literally plug in any filter i want

Rainther, GroupEnum function doesnt exist? if your talking about the other natives they dont work because like i said, those functions take units that are somewhere on the map and filters them into a group.

however, i want to take an EXISTING group (not units on the map) and filter it, think of it this way,

GroupAddGroupBJ with a filter.

yes frozenhelfir, at least the idea is correct but it would make my coding easier just to have a custom function that does it all rather than pasting a bunch of those and modifying them to work with the triggers, (as you may have guessed, i use filtering almost everywhere but the way i was doing it was..)

set u = FirstOfGroup(group)
exitwhen u == null
if GetWidgetState(u) >.405 then
call GroupAddUnit(g2,u)
endif

and if you ask me, this way just plain sucks.
then again, if this is somehow not possible, i guess ill have to stick with FirstOfGroup or ForGroup (as frozenhelfir said)

btw, if you guys didn't realize already, the reason why i asked how to filter a unit through a filter that takes nothing was an attempt to figure out how GroupEnumUnitsInRange worked, but i didn't find much about how it actually filters the unit. (yes i know it sets it as GetFilterUnit(), but how do you make the filter RUN???, that was my question)

since natives dont show any kind of process in how it actually works, i have no clue how it triggers the filter to run.
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
yes frozenhelfir, at least the idea is correct but it would make my coding easier just to have a custom function that does it all rather than pasting a bunch of those and modifying them to work with the triggers, (as you may have guessed, i use filtering almost everywhere but the way i was doing it was..)

You only need one of these

JASS:
library UnitAliveFilter
globals
private group g2 = CreateGroup()
endglobals

function UnitAlive takes group g returns group
local unit u
call GroupClear(g2) //not sure if this is the exact naming of it, this is freehand if you couldn&#039;t tell by lack of indent <img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" class="smilie smilie--sprite smilie--sprite7" alt=":p" title="Stick Out Tongue    :p" loading="lazy" data-shortname=":p" />
loop
set u = FirstOfGroup(g)
exitwhen u == null
if GetWidgetLife(u) &gt; .405 then
call GroupAddUnit(g2,u)
endif
call GroupRemoveUnit(g,u)
endloop
set u = null
return g2
endfunction
endlibrary


JASS:
call UnitAlive(g1)


You only need to write it once, I don't see the big deal >.>. This isn't the most efficient way. If you realllly can't stand using the firstofgroup loop there is another solution, but its used in the same way.
 

cleeezzz

The Undead Ranger.
Reaction score
268
Unit alive was an example. I need to be able to do other filter checks as well. (Who owns unit, unit is ally, unit type.. Anything. I don't want to be limited by a function that has a constant filter
 

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
Name the library something like "UnitFilters" and chock it full of them. Just copy/paste the first one changing the condition in the if. If that is too inconvenient, then I don't know what to say. I operate on a big map, and to me these kinds of functions come easy, so I just write them out for each individual case. It isn't inconvenient for me and it makes the map a lot more efficient.
 

saw792

Is known to say things. That is all.
Reaction score
280

Frozenhelfir

set Gwypaas = Guhveepaws
Reaction score
56
How about:
JASS:
function GroupRunFilter takes group g, boolexpr filter returns group
  local group g1 = CreateGroup()
  local group g2 = CreateGroup()
  local integer i = 0
  local unit u = null
  call GroupEnumUnitsInRect(g1, bj_mapInitialPlayableArea, filter)
  call GroupAddGroup(g, g2)
  loop
    set u = FirstOfGroup(g2)
    exitwhen u == null
    if IsUnitInGroup(u, g1) == false then
      call GroupRemoveUnit(g)
    endif
    call GroupRemoveUnit(u, g2)
  endloop
  return g
endfunction


Something like that?

Wont that leak with all the local handles that can't be nulled? That's the reason I used a global, correct me if I'm wrong. That function is crafty, though I would optimize it more before using it.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top