[Spell help] Teleport to the nearest enemy hero

johnnymra

New Member
Reaction score
14
1)Exactly as the title says... i want to make a spell (actually an item with this spell) that when used it will teleport the caster right to the nearest enemy hero, even tough you don't see the target enemy hero.
I realize it's by triggers, and i hope it can be done in GUI because i don't know JASS.
The thing is that i somehow want to pick every enemy hero and check the distance between the caster and that picked hero, then see which distance is the shortest and move the caster to the target. Can you help me make this trigger?

2)And by the way, i would like the spell to be based on war stomp so that it will also stun the target when teleported. My question is: is the event "unit uses item" good if i set the spell's casting time 0.1? i mean will the trigger take effect before or after the spell itself is casted?
 

Necrach

You can change this now in User CP.
Reaction score
62
I guess you could find your nearest hero like this

Trigger:
  • Actions
    • For each (Integer A) from 1 to 100000000, do (Actions)
      • Loop - Actions
        • Set temp_point = (Position of (Triggering unit))
        • Set temp_group = (Units within (Real((Integer A))) of temp_point matching ((((Matching unit) is A Hero) Equal to True) and (((Matching unit) belongs to an enemy of (Owner of (Triggering unit))) Equal to True)))
        • Unit Group - Pick every unit in temp_group and do (Actions)
          • Loop - Actions
            • -------- YOUR TELEPORT & STUN TRIGGERS --------
        • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • (Number of units in temp_group) Greater than 0
          • Then - Actions
            • Custom script: call DestroyGroup (udg_temp_group)
            • Skip remaining actions
          • Else - Actions


And if you want a maximum range, just set the Integer A loop to something less than 100000000 :eek:

I think this won't even bug if there is two heroes at the exact same integer range from your caster, as it will activate for one of the heroes picked and then skip remaining actions (not sure about that though, don't remember how well Skip remaining actions works inside loops)
 

Inflicted

Currently inactive
Reaction score
63
I was going to suggest something else, but Necrach's idea is actually really good haha, unless there is a chance of lag possibly from running too many times?
I don't know, but very clever:)
 

johnnymra

New Member
Reaction score
14
I will try this :) thanks a lot... it seems very good yet inflicted is right... would't it lag if running so many times?(my map is 256x256) I will try with 1000000000 and if it lags i will induce a maximum range (even tough it will ruin the idea a bit... it was an special item so that some hunters can teleport near they're prey instantly without the condition of being in X range of the target)
 

Necrach

You can change this now in User CP.
Reaction score
62
I don't think it will lag if the Skip Remaining action works as intended, as it doesn't really do anything until it finds a nearby hero and then it will not run anymore.

EDIT: But then again, that's a hundred million integers it counts to, so I see your concern :D
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Isn't there a *break* action or something in loops? I don't think Skip Remaining Actions works in this case.

Also, why not just put all enemy heroes into a unit group, then check through each one to see if its distance from the caster is the shortest? If it's less than the current TempUnit's distance/it's the first unit picked, then set it to be TempUnit. At the end of the loop, do the action onto TempUnit.
 

johnnymra

New Member
Reaction score
14
That's more work than is needed to be done, although I would approach it differently.

Care to explain how you would approach it? In GUI i hope... I don't mean to be rude but if you think there is a easier method i would like to see it.
 

NeuroToxin

New Member
Reaction score
46
Well, What I would do, is do the looping method, just, instead of picking the units, I'd set the group, if the group is larger than 0, then I'd do another if nested in that one, and if its greater than 1, then I'd pick a random unit, if its not, then I'd pick the units in the group (Unit in this case) and do what you want. If theres nothing then I'd remove the group.
 

johnnymra

New Member
Reaction score
14
Yes but i don't want the unit to be random... i want it to be the closest to the caster. Anyway thanks to everyone :)
 

SanKakU

Member
Reaction score
21
you should save heroes to variables of some sort when player picks them.
you can then check the distance between points for the caster and each enemy hero. then you compare to find which is the lowest. that's my thought.
 

johnnymra

New Member
Reaction score
14
you should save heroes to variables of some sort when player picks them.
you can then check the distance between points for the caster and each enemy hero. then you compare to find which is the lowest. that's my thought.

You basically united necrach's and neurotoxin's ideas... Did you even read what they said before posting? No offence.
 

Necrach

You can change this now in User CP.
Reaction score
62
Isn't there a *break* action or something in loops? I don't think Skip Remaining Actions works in this case.

What do you mean? :nuts: Loops are what they sound like, running one at a time for each picked unit, first one, then the next, etc, although in game it all happens in the same time. But it still reads one loop first, then repeats it, etc. And the skip remaining actions should affect the whole trigger, so.. :eek:

And if it doesn't work, maybe you could
- Run another trigger
- Turn off this trigger

and the other trigger is like
- Wait 0.00 seconds.
- Turn on "check nearest hero <gen>

(I think the 0 second wait should make it run after the first trigger actually have been turned of, otherwise I guess a 0.01 seconds wait wouldn't be too much of a deal)
 

KaerfNomekop

Swim, fishies. Swim through the veil of steel.
Reaction score
613
Oof. Tried it - Skip Remaining Actions does break the loop. But,
1). The loop would be more efficient if there was a check to see if there was any unit in the group before even doing anything.
2). TempPoint and TempUnitGroup should be cleared at the end of the For Loop, not only when a target is found.
3). Pick Every Unit means that if more than 1 enemy Hero is within the same range, then it would happen for both of them, not just one. It should be Random Unit From TempUnitGroup that the effects happen on - if there's only 1 unit, it will always be that unit no matter what.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • WildTurkey WildTurkey:
    is there a stephen green in the house?
    +1
  • The Helper The Helper:
    What is up WildTurkey?
  • The Helper The Helper:
    Looks like Google fixed whatever mistake that made the recipes on the site go crazy and we are no longer trending towards a recipe site lol - I don't care though because it motivated me to spend alot of time on the site improving it and at least now the content people are looking at is not stupid and embarrassing like it was when I first got back into this like 5 years ago.
  • The Helper The Helper:
    Plus - I have a pretty bad ass recipe collection now! That section of the site is 10 thousand times better than it was before
  • The Helper The Helper:
    We now have a web designer at my job. A legit talented professional! I am going to get him to redesign the site theme. It is time.
  • Varine Varine:
    I got one more day of community service and then I'm free from this nonsense! I polished a cop car today for a funeral or something I guess
  • Varine Varine:
    They also were digging threw old shit at the sheriff's office and I tried to get them to give me the old electronic stuff, but they said no. They can't give it to people because they might use it to impersonate a cop or break into their network or some shit? idk but it was a shame to see them take a whole bunch of radios and shit to get shredded and landfilled
  • The Helper The Helper:
    whatever at least you are free
  • Monovertex Monovertex:
    How are you all? :D
    +1
  • Ghan Ghan:
    Howdy
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top