1. Updated Resource Submission Rules: All model & skin resource submissions must now include an in-game screenshot. This is to help speed up the moderation process and to show how the model and/or texture looks like from the in-game camera.
    Dismiss Notice
  2. DID YOU KNOW - That you can unlock new rank icons by posting on the forums or winning contests? Click here to customize your rank or read our User Rank Policy to see a list of ranks that you can unlock. Have you won a contest and still havn't received your rank award? Then please contact the administration.
    Dismiss Notice
  3. The Lich King demands your service! We've reached the 19th edition of the Icon Contest. Come along and make some chilling servants for the one true king.
    Dismiss Notice
  4. The 4th SFX Contest has started. Be sure to participate and have a fun factor in it.
    Dismiss Notice
  5. The poll for the 21st Terraining Contest is LIVE. Be sure to check out the entries and vote for one.
    Dismiss Notice
  6. The results are out! Check them out.
    Dismiss Notice
  7. Don’t forget to sign up for the Hive Cup. There’s a 555 EUR prize pool. Sign up now!
    Dismiss Notice
  8. The Hive Workshop Cup contest results have been announced! See the maps that'll be featured in the Hive Workshop Cup tournament!
    Dismiss Notice
  9. Check out the Staff job openings thread.
    Dismiss Notice
Dismiss Notice
60,000 passwords have been reset on July 8, 2019. If you cannot login, read this.

[Snippet] GetClosestUnit(s)

Discussion in 'Graveyard' started by DiscipleOfLife, Feb 22, 2008.

  1. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    Guys, this uses vJass rit ?
     
  2. DiscipleOfLife

    DiscipleOfLife

    Joined:
    Mar 25, 2005
    Messages:
    252
    Resources:
    1
    Icons:
    1
    Resources:
    1
    The first keyword in the system is "library" so I guess it does.
     
  3. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    Is there a way to create a similar system without using vJass !? I know I could convert it, but that wouldn't be much efficient rit ?
     
  4. HappyTauren

    HappyTauren

    Joined:
    Nov 3, 2006
    Messages:
    8,413
    Resources:
    87
    Models:
    61
    Icons:
    23
    Packs:
    1
    Tutorials:
    2
    Resources:
    87
    Dude. Just use vJASS.
     
  5. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    Dude, my map can't use vJAss. VJass has a bug that prevents that. I already spoke to Vexorian and his team, they say they make no idea why that doesn't run. So therefore i can not use vJAss. That is why I am asking for help here.
     
  6. HappyTauren

    HappyTauren

    Joined:
    Nov 3, 2006
    Messages:
    8,413
    Resources:
    87
    Models:
    61
    Icons:
    23
    Packs:
    1
    Tutorials:
    2
    Resources:
    87
    vJASS bug? Try to disable war3err
     
  7. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    Already tried everything ... (or nearly everything, i will soon format my whole computer to try to locate the error)...
     
  8. DiscipleOfLife

    DiscipleOfLife

    Joined:
    Mar 25, 2005
    Messages:
    252
    Resources:
    1
    Icons:
    1
    Resources:
    1
    Untill you do that you can use the freshly coded "without vJass" version.

    I haven't tested if it works in game. I only renamed the global variables to use udg_GCU prefix, as well as removed all private keywords and the library so I highly doubt that it wouldn't work :).

    EDIT: About efficiency which you were wondering:

    The no-vJass version is almost identical to the vJass version. The only difference that affects performance is that the vJass version uses a precomputed boolexpr while the no-vJass version doesn't. This difference shouldn't be anything to worry about.
     
  9. Flame_Phoenix

    Flame_Phoenix

    Joined:
    May 4, 2007
    Messages:
    2,283
    Resources:
    11
    Tools:
    1
    Maps:
    1
    Spells:
    6
    Tutorials:
    3
    Resources:
    11
    wOW, THX really =)
    That will certainly prove useful for my lighting spells =) It has more logic to affect a close unit than a random unit 500 meters away :p

    Thx

    + rep
     
  10. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Also, Phoenix, don't forget to read the instructions above the code ;)
     
  11. apocalypse_dude

    apocalypse_dude

    Joined:
    Mar 12, 2006
    Messages:
    407
    Resources:
    0
    Resources:
    0
    sorry for digging this out but i would like to know if i can use this as a very frequent event lets say like every second
    how much would that influence the overall performance ? may it cause lagg along with other functions ?
    I dont know much about jass so i cant really guess it myself
     
  12. DiscipleOfLife

    DiscipleOfLife

    Joined:
    Mar 25, 2005
    Messages:
    252
    Resources:
    1
    Icons:
    1
    Resources:
    1
    Only once per second shouldn't be a problem at all, unless you have several hundreds of units that need to be searched through to find the closest one. Generally it is best to use the function that goes through the least amount of units possible, for example GetClosestUnitInRange instead of GetClosestUnit whenever the range limit doesn't bother you.

    EDIT:
    New version 1.3 is now up. Its GetClosestUnit most often avoids going through all units on the map unlike the old one, thus the new one should be a lot faster on maps with a lot of units in it.
     
    Last edited: May 24, 2008
  13. crl

    crl

    Joined:
    Mar 29, 2008
    Messages:
    114
    Resources:
    2
    Models:
    2
    Resources:
    2
    ROTFLOL

    closest unit=the closest unit to the point
    close=near
    unit=soldier/building/creep/worker/...
     
  14. Xeridanus

    Xeridanus

    Joined:
    Dec 13, 2004
    Messages:
    319
    Resources:
    0
    Resources:
    0
    this may be a dumb question but, what's the difference between vJassless and the normal one?
     
  15. DiscipleOfLife

    DiscipleOfLife

    Joined:
    Mar 25, 2005
    Messages:
    252
    Resources:
    1
    Icons:
    1
    Resources:
    1
    The normal version requires you to have jasshelper whereas the vJassless doesn't, but on the other hand when importing the vJassless version you have to create a few global variables with the Trigger Editor's variable editor.

    The current versions of both of the systems (1.3.1) are identical when it comes to performance and functionality, except that the normal version is in a library called GCU and thus can be required by other libraries.
     
  16. Herman

    Herman

    Joined:
    Aug 20, 2007
    Messages:
    877
    Resources:
    0
    Resources:
    0
    Damn, I made my own version of this using 3D, and just getclosestofgroup, as it seemed to be the most generic + efficient way to use the function for each situation

    I didn't even think about using ForGroup() :ugly:

    I think you might want to add in a 3D version too, just incase your working with projectiles and the such
     
  17. Silvenon

    Silvenon

    Joined:
    Nov 22, 2006
    Messages:
    1,233
    Resources:
    1
    Tutorials:
    1
    Resources:
    1
    Nobody cares for the third dimension in wc3 because there are many algorithms and calculations when working in 3D plus it's very possible that you'll never get it right...... it's just not worth it and it doesn't make much difference.

    But you can post your 3D version if you know how to make it :)
     
  18. Herman

    Herman

    Joined:
    Aug 20, 2007
    Messages:
    877
    Resources:
    0
    Resources:
    0
    For a 3-D GetClosestUnit, all you need to do is add another real parameter for the Z, and incorporate the Z calculations for the pythagorean theroem, instead of x*x + y*y = d*d, it becomes x*x + y*y + z*z = d*d

    Ok, I will post a 3D version, for this specific case, it is much more simple than using any crazy algorithms
     
  19. Slaydon

    Slaydon

    Joined:
    Jan 6, 2008
    Messages:
    2,432
    Resources:
    2
    Tutorials:
    2
    Resources:
    2
    sample map pl:cgrin:x
     
  20. Anachron

    Anachron

    Joined:
    Sep 9, 2007
    Messages:
    6,176
    Resources:
    66
    Icons:
    49
    Packs:
    2
    Tools:
    1
    Maps:
    3
    Spells:
    9
    Tutorials:
    1
    JASS:
    1
    Resources:
    66
    Code (vJASS):

    set CurrentPick = null
    set CenterX = x
    set CenterY = y
    set CurrentDistance = 100000
     

    Since you are using it in nearly every function, just make a new function and add the code to it. This system is ok, but far to less functionality I think.