[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.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top