Warcraft III: MapsModelsSkinsIconsSpellsToolsTutorials
WC3 JASS: Code SnippetsJASS and vJASS Spells and SystemsJass Tutorials
Chat @Discord

Author Topic: [snippet] Get Units in Line  (Read 11578 times)

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[snippet] Get Units in Line
« on: January 02, 2013, 11:27:45 PM »
Description

This small library allows users to get the units in a line. This line can be defined by 2 points or 2 widgets.

Requirements:

 - GeometryLibBase
 - Select Cohadar's jasshelper in JNGP 5e and up

Actual Code
Code: jass  [Select]
  1. /******************************************************************
  2. *                     GROUP UNITS IN LINE v1.0                    *
  3. *                           By moyack                             *
  4. *                              2012                               *
  5. *              ===================================                *
  6. *              Exclusive resource from wc3jass.com                *
  7. *              ===================================                *
  8. ******************************************************************/
  9. library GetUnitsInLine requires GeometryLibBase
  10. /* This library catch all the units in a line. This line however,
  11. can be defined in several ways, each one will offer a function for
  12. that purpose:
  13.  * Between 2 points:  GetUnitsInLine_byPoints()
  14.  * Between 2 widgets: GetUnitsInLine_byWidgets()
  15.  
  16.  The first function takes as arguments a group variable and 4 reals
  17.  which are the X/Y coordinates of the first and second point.
  18.  
  19.  The second function takes as arguments a group variable and 2 widgets,
  20.  these widgets can be any combination of units, items and destructables.
  21.  
  22.  The group variable for both functions will store the units catched in
  23.  the line defined by points or widgets, so it's advisable that this group
  24.  should be empty.
  25. */
  26. globals
  27.     private constant real SPREAD = 30. // this value defines how wide is the line of units selected
  28.     private group G = CreateGroup()
  29. endglobals
  30.  
  31. public function byPoints takes group g, real x1, real y1, real x2, real y2 returns nothing
  32.     local unit u
  33.     local real a
  34.     local real b
  35.     local real x = 0.5 * (x1 + x2)
  36.     local real y = 0.5 * (y1 + y2)
  37.     if g == null then
  38.         return
  39.     endif
  40.     call GroupEnumUnitsInRange(G, x, y, GetDistance(x, y, x1, y1) + SPREAD, null)
  41.     for u in G
  42.         if x2 - x1 == 0. then // manages vertical lines
  43.             set x = x1
  44.             set y = GetUnitY(u)
  45.         else
  46.             set x = GetUnitX(u)
  47.             set a = (y2 - y1) / (x2 - x1)
  48.             set b = -a * x1 + y1
  49.             set y = a * x + b
  50.         endif
  51.         if IsUnitInRangeXY(u, x, y, SPREAD) then
  52.             call GroupAddUnit(g, u)
  53.         endif
  54.     endfor
  55. endfunction
  56.  
  57. public function byWidgets takes group g, widget A, widget B returns nothing
  58.     call byPoints(g, GetWidgetX(A), GetWidgetY(A), GetWidgetX(B), GetWidgetY(B))
  59. endfunction
  60.  
  61. endlibrary

Changelog:
1.0: Initial release.

Feel free to comment.
« Last Edit: January 07, 2013, 07:42:22 AM by moyack »

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Your Awesome Site Director
  • Recognized User
  • Starter - level 1
  • *
  • Posts: 382
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 677
    • View Profile
[snippet] Get Units in Line
« Reply #1 on: January 03, 2013, 03:23:30 AM »
Hmm tested the map and its a hell of fun! (Just talking about the test system on the test map) actually you should make a mini-game map with those codes. XD

Anyway, where is the rating system? O.o
Chronicles of Darkness
by: SonofJay

A BlizzMod Hosted Project

They can hate, let them hate, make them hate.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[snippet] Get Units in Line
« Reply #2 on: January 03, 2013, 08:26:05 AM »
Hmm tested the map and its a hell of fun! (Just talking about the test system on the test map) actually you should make a mini-game map with those codes. XD
Sure!!! why not??

Quote
Anyway, where is the rating system? O.o
When it gets approved you can rate it :)

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
[snippet] Get Units in Line
« Reply #3 on: January 06, 2013, 09:04:52 AM »
Nice.
This requires cohadar's JassHelper I see :o

Not a lot of people are using that, so I guess it should be mentioned at least :p

  • Your Awesome Site Director
  • Recognized User
  • Starter - level 1
  • *
  • Posts: 382
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 677
    • View Profile
[snippet] Get Units in Line
« Reply #4 on: January 06, 2013, 10:36:37 AM »
Hoho, nice to see you back Mag since your last visit was December 12..
Chronicles of Darkness
by: SonofJay

A BlizzMod Hosted Project

They can hate, let them hate, make them hate.

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
[snippet] Get Units in Line
« Reply #5 on: January 06, 2013, 01:35:03 PM »
Yeah, I apologize for that.
JASS Class on Hive is taking up a lot of time :v
I don't even have time to take shits now.

  • Site Owner
  • Administrator
  • Starter - level 4
  • *
  • Posts: 979
  • WC3 Models: 5
  • WC3 Tutorials: 11
  • WC3 Tools: 10
  • WC3 Maps: 11
  • WC3 Skins: 6
  • WC3 Icons: 2
  • WC3 Spells: 3
  • Reputation: 1153
  • Site Admin - I love fix things
    • View Profile
    • Blizzard Modding Information Center
[snippet] Get Units in Line
« Reply #6 on: January 07, 2013, 09:04:50 AM »
Nice.
This requires cohadar's JassHelper I see :o

Not a lot of people are using that, so I guess it should be mentioned at least :p
Added the requirement. And it's good to see you here around :)

We can give you full hosting for your projects, a complete page!!

A custom altered melee map where you can play Naga and Demons. Check it out!!
Use Dropbox...

  • Awesome Global Code Moderator
  • Recognized User
  • Rookie - level 2
  • *
  • Posts: 83
  • WC3 Models: 0
  • WC3 Tutorials: 0
  • WC3 Tools: 0
  • WC3 Maps: 0
  • WC3 Skins: 0
  • WC3 Icons: 0
  • WC3 Spells: 0
  • Reputation: 516
  • vJass Incarnate
    • View Profile
[snippet] Get Units in Line
« Reply #7 on: March 13, 2013, 12:45:00 PM »
Approved!

 

[Snippet] Single Player Detector

Started by moyackBoard Codes & Snippets

Replies: 12
Views: 20892
Last post March 13, 2013, 12:48:49 PM
by Magtheridon96
[Snippet] Simple Unit Indexer

Started by moyackBoard Codes & Snippets

Replies: 17
Views: 25701
Last post September 30, 2013, 08:07:19 AM
by moyack
[Snippet] Disable Transmission Skip

Started by PurgeandfireBoard Codes & Snippets

Replies: 2
Views: 8665
Last post July 02, 2013, 01:34:55 PM
by Purgeandfire
[Snippet] Timed Effects

Started by moyackBoard Codes & Snippets

Replies: 0
Views: 7320
Last post January 09, 2012, 07:03:32 PM
by moyack
[Snippet] Parabolic Function

Started by moyackBoard Codes & Snippets

Replies: 1
Views: 7008
Last post January 13, 2012, 12:11:45 PM
by Magtheridon96
Blizzard Modding Information Center Starcraft II Modding Information Center Wacraft III Modding Information Center WC3JASS.com - The JASS Vault Chronicles of Darkness - A Warcraft III mod Jetcraft - A Starcraft II mod Troll Smash - A Warcraft III Arena
  Mod DB - Change the Game Power of Corruption - A Warcraft III altered melee map Chaos Realm - The world of Game modders and wc3 addicts Follow us on Facebook!!