Detect Units @ Left/Right/Above/Below

Exuro.

New Member
Reaction score
5
Hello again young helpers.. :D



As some off you may know i made a snippet to avoid peasants to trough gaps and such.. anyway i got a new idea to improve it..

so my question is:

Is there a way to detect if there´s a unit present at each side of the "building" unit?

like:

Event:
Unit Begins Constructing
Condtion:
Action:
If/Then/else
Condition:
(This is the place the detecting will be) something like:
If unit is present at X,Y postion of building unit equal True (If you know what i mean)
Action:
Do what i want hehe



Something like this possible?
 

darkbeer

Beer is Good!
Reaction score
84
a lot of things are possible, so is yours, but its a bit complicated:

youll have to use groups:

Code:
Events - blablabla
Actions
- Set UnitPoint = Position of < whatever unit ( triggering unit, constructing unit, constructed unit ....)> 
- Set TempPoint = UnitPoint offset by <xxxxx> towards <0, 90, 180, 270> degrees  //a loop can be used to check for all 4 directions
-Set TempGroup = Units in within <Radius> of TempPoint matching <Conditions ( UnitType = ??, Unit is alive ..)
- If Number of units in TempGroup > 0 then ..... HERE ALL YOU WANT
- CustomScript: call RemoveLocation( udg_UnitPoint) 
//clean TempPoint and the group as well
 

Gravit

New Member
Reaction score
6
What if you had 4-8 regions around the unit, depending on how specific you wanted to be. Just have a periodic event moving the regions to the position of your unit, offset by wherever you want them placed. It would look something like this:
_______
l__l__l__l
l__l__l__l
l__l__l__l

Your unit would be the middle square, the rest being your regions. You would then use the condition checking if a unit is in the regions.

Hope this helps.
 

Exuro.

New Member
Reaction score
5
Does that check the exact point i give out if there is a unit?



Gravit: That will be problematic as i have 8 area´s with 50x50 units.. hehe.. lots of regions
 

Exuro.

New Member
Reaction score
5
am i correct that this will be above the constructing unit?

Code:
Untitled Trigger 001
    Events
        Unit - A unit Begins construction
    Conditions
    Actions
        Set Above = ((Position of (Triggering unit)) offset by (25.00, 0.00))


And it was possible to detect if there´s a unit/Destructible at that point?
 

darkbeer

Beer is Good!
Reaction score
84
Set Above = ((Position of (Triggering unit)) offset by (25.00, 0.00))

you set a point right to the position of triggering unit but 25.00 is a very small offset.... i suggest using 200 or at least 128 (90.0 degrees would be above)

now you set a group TempGroup = Units withing 150. of Above matching ( matching unit is Type Peon) and (matching unit is alive)

so you know if there are any living units of type Peon around if the number of units in TempGroup > 0
 

Exuro.

New Member
Reaction score
5
Just quickly made this:

Code:
Untitled Trigger 001
    Events
        Unit - A unit Begins construction
    Conditions
    Actions
        Wait 0.50 seconds
        -------- Makes Points around the Constructing Peasant --------
        Set Above = ((Position of (Triggering unit)) offset by (25.00, 0.00))
        Set Below = ((Position of (Triggering unit)) offset by (-25.00, 0.00))
        Set Left = ((Position of (Triggering unit)) offset by (0.00, -25.00))
        Set Right = ((Position of (Triggering unit)) offset by (0.00, 25.00))
        -------- - --------
        -------- Picks units at each point and adds +1 to integer for each destructible picked --------
        Destructible - Pick every destructible within 1.00 of Above and do (Actions)
            Loop - Actions
                Set NumberofBoxs = (NumberofBoxs + 1)
        Destructible - Pick every destructible within 1.00 of Below and do (Actions)
            Loop - Actions
                Set NumberofBoxs = (NumberofBoxs + 1)
        Destructible - Pick every destructible within 1.00 of Left and do (Actions)
            Loop - Actions
                Set NumberofBoxs = (NumberofBoxs + 1)
        Destructible - Pick every destructible within 1.00 of Right and do (Actions)
            Loop - Actions
                Set NumberofBoxs = (NumberofBoxs + 1)
        -------- - --------
        If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            If - Conditions
                NumberofBoxs Equal to 4
            Then - Actions
                Game - Display to (All players) the text: Not Allowed
            Else - Actions


Would something like that work? (I will ofc raise the (within) with some testing)
 

darkbeer

Beer is Good!
Reaction score
84
hm, youre getting the angle wrong at the polar projection but the way is right:

For the polar projection: the first value called offset is the distance to the point, e.g an offset of 128. would be one square
the second value called angle is (yea how strange) the angle taken in degrees with 0 facing east (or right if you want), so an angle of 90. degrees would be north or above

i made an example trigger:
using units instead of destructibles

Code:
Test
    Ereignisse
        Einheit - A unit Fängt an zu bauen
    Bedingungen
    Aktionen
        Set TempPoint[0] = (Position of (Triggering unit))
        For each (Integer A) from 1 to 4, do (Actions)
            Schleifen - Aktionen
                Set TempPoint[(Integer A)] = (TempPoint[0] offset by 128.00 towards ((Real((Integer A))) x 90.00) degrees)
                Set TempGroup = (Units within 128.00 of TempPoint[(Integer A)] matching (((Matching unit) is Ein Gebäude) Gleich True))
                If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                    'IF'-Bedingungen
                        (Number of units in TempGroup) Größer als 0
                    'THEN'-Aktionen
                        Spiel - Display to (All players) the text: (THERE ARE BUILDINGS AROUND POINT  + (String((Integer A))))
                    'ELSE'-Aktionen
                Custom script:   call RemoveLocation(udg_TempPoint[bj_forLoopAIndex])
                Custom script:   call DestroyGroup(udg_TempGroup)
        Custom script:   call RemoveLocation(udg_TempPoint[0])

(sorry german editor version...)

same trigger using destructibles:

Code:
Test
    Ereignisse
        Einheit - A unit Fängt an zu bauen
    Bedingungen
    Aktionen
        Set TempPoint[0] = (Position of (Triggering unit))
        For each (Integer A) from 1 to 4, do (Actions)
            Schleifen - Aktionen
                Set TempPoint[(Integer A)] = (TempPoint[0] offset by 128.00 towards ((Real((Integer A))) x 90.00) degrees)
                Set TempGroup = (Units within 128.00 of TempPoint[(Integer A)] matching (((Matching unit) is Ein Gebäude) Gleich True))
                Zerstörbar - Pick every destructible within 128.00 of TempPoint[(Integer A)] and do (Actions)
                    Schleifen - Aktionen
                        If ((Integer A) Gleich 1) then do (Spiel - Display to (All players) the text:  Trees above!) else do (Do nothing)
                        If ((Integer A) Gleich 2) then do (Spiel - Display to (All players) the text:  Trees left!) else do (Do nothing)
                        If ((Integer A) Gleich 3) then do (Spiel - Display to (All players) the text:  Trees below!) else do (Do nothing)
                        If ((Integer A) Gleich 4) then do (Spiel - Display to (All players) the text:  Trees right!) else do (Do nothing)
                Custom script:   call RemoveLocation(udg_TempPoint[bj_forLoopAIndex])
                Custom script:   call DestroyGroup(udg_TempGroup)
        Custom script:   call RemoveLocation(udg_TempPoint[0])

you have to play around a little with the radius and the offset!
 

Exuro.

New Member
Reaction score
5
ye but its destructibles which is around. so i cant use groups


EDIT: ok trying hehe
 

darkbeer

Beer is Good!
Reaction score
84
just tested it and i works fine for me^^

heres the demo map try to build farms aournd the trees:
also if you want to check for the unit whos being built youll ahve to change the first line to
Code:
Set TempPoint[0] = (Position of [COLOR="Red"](Constructing structure)[/COLOR])

else it will check for the builders position, just guesssing that you wanted the to check the position of the structure

EDIT: ah you can delete that^^, just forget to delete it myself xD (copy / paste first trigger) no need for the group now
 

Attachments

  • Test Map Tree Check.w3x
    18.5 KB · Views: 145

Exuro.

New Member
Reaction score
5
hah very nice.. just playing around with it so it fits my needs.. so i might come back here to ask more hehe
 

Exuro.

New Member
Reaction score
5
hmm Darkbeer

Is there a way of making this very exact? like only pick the destructible at the exact point.. i kinda want to have the "within" as low as possible so it only picks the unit the point is at.


EDIT: Or even better, check if the point is pathable/walkable
 

darkbeer

Beer is Good!
Reaction score
84
sure there is:

Code:
If ((Terrain pathing at TempPoint[(Integer A)] of type Begehbarkeit is off) Gleich True) then do (Spiel - Display to (All players) the text: Above not pathable!) else do (Do nothing)

its under boolean comparison
 

Exuro.

New Member
Reaction score
5
so if a building is placed at that point the area will not be pathable right?
 

darkbeer

Beer is Good!
Reaction score
84
if youcant walk there (building destructible cliff ....is there) it will do your actions
 

Exuro.

New Member
Reaction score
5
I cant get this working..

Code:
Tree Check
    Events
        Unit - A unit Begins construction
    Conditions
    Actions
        Wait 1.00 seconds
        Set BuildingPeasantPoint[0] = (Position of (Triggering unit))
        For each (Integer A) from 1 to 4, do (Actions)
            Loop - Actions
                Set BuildingPeasantPoint[(Integer A)] = (BuildingPeasantPoint[0] offset by 200.00 towards ((Real((Integer A))) x 90.00) degrees)
                If ((Terrain pathing at BuildingPeasantPoint[(Integer A)] of type Walkability is off) Equal to True) then do (Set AmountofBoxs = (AmountofBoxs + 1)) else do (Game - Display to (All players) the text: didnt work)

It just displays "Didnt Work" 4 times no matter where i build
 

darkbeer

Beer is Good!
Reaction score
84
hm, your thing will display didnt work if the terrain is walkable so change the true to false and it should work:

Code:
Tree Check
    Events
        Unit - A unit Begins construction
    Conditions
    Actions
        Wait 1.00 seconds
        Set BuildingPeasantPoint[0] = (Position of (Triggering unit))
        For each (Integer A) from 1 to 4, do (Actions)
            Loop - Actions
                Set BuildingPeasantPoint[(Integer A)] = (BuildingPeasantPoint[0] offset by 200.00 towards ((Real((Integer A))) x 90.00) degrees)
                If ((Terrain pathing at BuildingPeasantPoint[(Integer A)] of type Walkability is off) Equal to [COLOR="Red"]False[/COLOR]) then do (Set AmountofBoxs = (AmountofBoxs + 1)) else do (Game - Display to (All players) the text: didnt work)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top