• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

Pick all units in a line?

Status
Not open for further replies.
Level 4
Joined
Jul 22, 2010
Messages
74
Hey,

how can i pick every unit behind (for example) a "point" or "unit" in a "line", not an AoE pick, just all units in a row behind it...?

i would prefer GUI ..


thats what i try to say/ask ^^

C => caster
P => point of ability being cast (or position of a unit)
>>>>> => casting a spell

---- => (that should be the units i want)

I want to pick all this units behind the P, in a row



C >>>> P--------------


....................................
Thank you for helping =)
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Well, you could copy and paste this library:

JASS:
library PointInRect

    // Returns a boolean that tells whether the point is inside a rectangle.
    // (px , py) = Point to check
    // (cx , cy) = lower left corner of the rect
    // (ax , ay) = upper left corner
    // (bx , by) = lower right corner
    function IsPointInRect takes real px , real py , real cx , real cy , real ax , real ay , real bx , real by returns boolean        
        local real dot1 = (px-cx)*(ax-cx) + (py-cy)*(ay-cy)
        local real dot2 = (ax-cx)*(ax-cx) + (ay-cy)*(ay-cy)
        local real dot3 = (px-cx)*(bx-cx) + (py-cy)*(by-cy)
        local real dot4 = (bx-cx)*(bx-cx) + (by-cy)*(by-cy)
        
        return dot1 >= 0 and dot1 <= dot2 and dot3 >= 0 and dot3 <= dot4
    endfunction
    
endlibrary

You can pick all units in range, where range is the length of the "line".

Upper left corner is position of caster offset by x towards facing of caster + 90.
Lower left corner is upper left corner offset by y towards facing of caster + 180.
Lower right corner is lower left corner offset by 2x towards facing of caster - 90.

You'll be picking units inside a box:
help1.jpg


Save the coordinates of each point into variables and save the result into a boolean
  • Custom script: set udg_SF_Boolean = IsPointInRect(GetUnitX(GetEnumUnit()) , GetUnitY(GetEnumUnit) , udg_r5 , udg_r6 , udg_r7 , udg_r8 , udg_r3 , udg_r4 )
 

Bannar

Code Reviewer
Level 26
Joined
Mar 19, 2008
Messages
3,140
Well you know.. or meaby you do not.. but rectangle has 4 corners..
Using 2 points create just line, so I don't how you would pick units within given area.
It'd much differend if we used dummy unit and move towards destination point. Then 2 points are enought, but we would need also a loop for checking units within small area around dummy to make proper spell.
 
Status
Not open for further replies.
Top