# SnippetUnits in sector

#### AceHart

Sector:
Imagine a cake, the round type,
cut it into pieces, taking care to cut through the center,
take one piece,
look at it from the top.
That's a sector.

Still not seeing it? Here's an image.

JASS:
``````library FILTERS initializer Init
globals
boolexpr FILTER_True
endglobals
private function ReturnTrue takes nothing returns boolean
return true
endfunction
private function Init takes nothing returns nothing
set FILTER_True = Condition(function ReturnTrue)
endfunction
endlibrary``````
JASS:
``````// whichGroup: the group the units will be added to
// xc, yc: the starting point, sort of like the center of the circle
// facing: the direction the &quot;middle&quot; of the sector goes to, in radians
// radius: the &quot;length&quot; of the sector
// angle: the maximum opening angle of the sector, in radians
// filter: the condition function to apply to the units in the sector.
function GroupEnumUnitsInSector takes group whichGroup,real xc,real yc,real facing,real radius,real angle,boolexpr filter returns nothing
local group g = CreateGroup()
local unit u
local real x
local real y
local real x1
local real y1
local real x2
local real y2

call GroupEnumUnitsInRange(g, xc, yc, radius, filter)

set angle = angle * 0.5
set x1 = Cos(facing - angle)
set y1 = Sin(facing - angle)
set x2 = Cos(facing + angle)
set y2 = Sin(facing + angle)

loop
set u = FirstOfGroup(g)
exitwhen u == null
call GroupRemoveUnit(g, u)

set x = GetUnitX(u) - xc
set y = GetUnitY(u) - yc
if y * x1 &gt;= x * y1 and y * x2 &lt;= x * y2 then
endif
endloop

call DestroyGroup(g)
set g = null
endfunction

// point: the starting point, sort of like the center of the circle
// facing: the direction the &quot;middle&quot; of the sector goes to, in degrees
// radius: the &quot;length&quot; of the sector
// angle: the maximum opening angle of the sector, in degrees
// filter: the condition function to apply to the units in the sector. Pass null for all units
function GetUnitsInSector takes location point,real facing,real radius,real angle,boolexpr filter returns group
local group g = CreateGroup()
if filter == null then
set filter = FILTER_True
endif
return g
endfunction``````

Yes, I actually think it works...

The demo map is simple to use, select the Blood Mage, move somewhere, press "escape".
The list of names you get would be the units within 400 distance and 60 degrees in front.
Yes, it includes the Mage... that's because the filter function simply picks anything...

#### Attachments

• 14.8 KB Views: 231

#### PureOwnage

##### Minecraft Server OP, Inactive.
Awesome!
To much math though...

#### Samael88

##### Evil always finds a way
Thanks Acehart This will really come in handy
Keep up the good work:thup:

Edit: Does this require vJass or is it standard Jass?

#### AceHart

As standard as it gets. No fancy tools needed.

#### Dameon

##### "All the power in the world resides in the eyes"
So put simply this enables you to chose unit's in certain view points, mainly in front, to the left, to the right and behind. I would have never thought of doing a trigger like this but I can think of a lot of uses for it, thanks ace.

By the way is this possible in MUI?

#### AceHart

The function has no problems with MUI, MPI, WTHI, ...
It only depends on what you're doing with your group.

#### Dr.Jack

##### That's Cap'n to you!
Refreshingly simple and useful, good job, thanks for sharing.

A small question if you don't mind.
As I see it ReturnTrue serves as the conditions when the group is created. That make sense, but how about letting the players give their own set of conditions? You could always take another boolexpr parameter. Obviously one could always simply loop and use If/Then/Else action, but I believe just giving boolexpr parameter would ease things.

Do correct me if I'm wrong.

#### AceHart

Given I personally prefer condition functions over "if"s that do work that isn't exactly their job... updated.

#### Don

##### Rise with the Fallens!
Nice system, this surely will make it into one of my map, i love it, good job!

#### black.sheep

##### Active Member
I copy and paste it in, it comes up with 370 errors.
Problem?

#### AceHart

Just the sector functions, or the library too?

The library is only there to provide "FILTER_True".
Unfortunately, that means you need NewGen.

Alternatively, if you don't want, or can not, use NewGen, add a function like
JASS:
``````function ReturnTrue takes nothing returns boolean
return true
endfunction``````

And replace "FILTER_True" with "Condition(function ReturnTrue)".

#### black.sheep

##### Active Member
So is supposed to look like this? Tell me what im doing wrong
Code:
``````function GetUnitsInSector takes location point,real facing,real radius,real angle,boolexpr filter returns group
local group g = CreateGroup()
if filter == null then
Condition(function ReturnTrue)
endif
return g
endfunction

function ReturnTrue takes nothing returns boolean
return true
endfunction``````

#### AceHart

> Condition(function ReturnTrue)

set filter = Condition(function ReturnTrue)

And move the ReturnTrue function to the top.

#### black.sheep

##### Active Member
Ahh thanks, works fine now.

#### takethat

##### Active Member
is it possible this being done through gui?

#### Viikuna

##### No Marlo no game.
Your function creates groups every time its called, so its slower than it should be + it leaks.

This should be fixxed. I suggest to make it require GroupUtils, and use ENUM_GROUP for GroupEnum calls..

Also in that GetUnitsInSector function you should replace CreateGroup with NewGroup.

edit. Ok, this is thread pretty old. Just noticed. Well, anyways, I kinda wonder if AceHart is still around..

General chit-chat
Help Users
• No one is chatting at the moment.
• Ghan:
The old shoutbox wasn't supported anymore. We updated xenForo, so it had to be replaced.
• jonas:
let's see if everyone finds it... the nice thing about the shoutbox was I could check on it even while logged out, but the existence of this one is hidden when you're not logged in
• Ghan:
We can fix that.
• Ghan:
Chat should show on the sidebar when not logged in now.
• Ghan:
• Ghan:
Test!
• tom_mai78101:
I must be in a test server.
• tom_mai78101:
Nice, Twitter tweets embedding now works
• Wizard:
Yup.
• Ghan:
Excellent.
• Ghan:
@tom_mai78101 Hello there.
• Ghan:
Tagging works in the chat too.
• tom_mai78101:
@Ghan Missed it.
• Wizard:
Still fixing things here and there. Added widgets to the portal, will make it match the ones here on the forum index tomorrow.
• Ghan:
The venerable World Editor Tutorials site has been converted to HTTPS at last.
• jonas:
cool
• jonas:
and I can even edit my messages, nice
• seph ir oth:
GENERAL CHIT CHAT, YOU ARE A BOLD ONE
• Ghan:
Hello there
• The Helper:
this new chatbox is great and the forum software update is great too
+1
• The Helper:
upgrade has fixed forum registration spam problem
• tom_mai78101:
Something tells me we might be able to customize the chatbox a bit, considering that there's a gap under every message.
• Wizard:
Going to deploy a fix soon, just had to take some time for myself this weekend.
• Varine:
Unbelievable. Time for yourself? How dare you!

### Members online

No members online now.