[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
612
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
612
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
  • Blackveiled Blackveiled:
    I wouldn't know, I'm in Joliet, Illinois right now working. I left Houston area about 2 weeks ago lol
  • Blackveiled Blackveiled:
    Not permanently of course, just a temporary job.
    +1
  • jonas jonas:
    Glad you're ok @tom_mai78101
  • jonas jonas:
    @Blackveiled you know another word for permanent? temporary
    +1
  • Varine Varine:
    Briefly, he'll only be there for the interim. Like a stopgap of sorts, he'll be back home in short time
  • O Old Mountain Shadow:
    Hurray! Tom has reappeared!
  • The Helper The Helper:
    Happy Thursday!
  • Blackveiled Blackveiled:
    Yep. Just another fun night at work.
  • Varine Varine:
    Broke the nozzle on my 3d printer and I don't have another heater block. So... I guess I'm fucked on that this weekend
  • The Helper The Helper:
    that sucks i bet they are expensive
  • Varine Varine:
    Not really
  • Varine Varine:
    The entire hot end is like 20 dollars, I just can't get anymore until next week
  • Varine Varine:
    I ordered like five blocks for 15 dollars. They're just little aluminum blocks with holes drilled into them
  • Varine Varine:
    They are pretty much disposable. I have shitty nozzles though, and I don't think these were designed for how hot I've run them
  • Varine Varine:
    I tried to extract it but the thing is pretty stuck. Idk what else I can use this for
  • Varine Varine:
    I'll throw it into my scrap stuff box, I'm sure can be used for something
  • Varine Varine:
    I have spare parts for like, everything BUT that block lol. Oh well, I'll print this shit next week I guess. Hopefully it fits
  • Varine Varine:
    I see that, despite your insistence to the contrary, we are becoming a recipe website
  • Varine Varine:
    Which is unique I guess.
  • The Helper The Helper:
    Actually I was just playing with having some kind of mention of the food forum and recipes on the main page to test and see if it would engage some of those people to post something. It is just weird to get so much traffic and no engagement
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top