• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Preventing unit from casting spells outside Melee range

Status
Not open for further replies.
Level 7
Joined
Dec 28, 2009
Messages
257
Heya folks, another dumb question of mine..
Basically, ive got one unit with like 3 spells (sleep, shadow strike and shockwave-based spelld respectively), all of which have got range around 200 (thats bigger melee).
However, i cant figure out working trigger that would basically prevent this unit from using melee Shadow Strike or anything on unit that is at range more than 200, incriminated unit sometimes just runs across hall just to use that Shadow Strike or some spell on that unit, while i'd prefer it to spam spells on melee range only targets...

I had something basic like
  • Unit begins casting an ability
  • Ability being cast is equal to X /and/ Target of ability being cast belongs to unit within 200 of Casting unit equal to false
  • Order casting unit to Stop
PS: Ive got no idea how to write this trigger thing here

but that doesnt work, it prevents spells with cast range above 200 from being cast if you are further away from unit than 200, or something like that.

So, any help? I bet it isnt hard, and again im missing some small piece of trigger to make it work.. thanks :D
 
Level 8
Joined
Oct 12, 2011
Messages
483
Use this:
  • Check Distance
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(Order ID of Ability 1))
          • (Issued order) Equal to (Order(Order ID of Ability 2))
          • (Issued order) Equal to (Order(Order ID of Ability 3))
    • Actions
      • Set p_caster = (Position of (Triggering unit))
      • Set p_target = (Position of (Target unit of issued order))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Distance between p_caster and p_target) Greater than 200.00
        • Then - Actions
          • Unit - Order (Triggering unit) to Stop
        • Else - Actions
      • Custom script: call RemoveLocation(udg_p_caster)
      • Custom script: call RemoveLocation(udg_p_target)
Since you're using Shockwave which can target ground as well, you should make a second copy of the trigger that uses the
  • Unit - A unit Is issued an order targeting a point
event and has all the other stuff in the trigger set up for that as well.
 
Level 7
Joined
Dec 28, 2009
Messages
257
Mrhm, tried it, copied everything from your trigger and apparently it fails on first condition
  • (Issued order) Equal to (Order(AHtb)
*

* for testing i used Mountain King and his Storm Bolt spell with lowever range
* I replaced "(Order ID of Ability 1)" with AHtb, what should be storm bolts.. well raw data name or whatever its called------->

Doesnt work :/ No action happened, so the condition must be wrong.
I guess i shouldve written something different there, err, i dont like working with those raw data and jass stuff :D
help please? :D

whole trigger: (ive got no idea how to write triggers longer than 1 line here :D)
http://i44.tinypic.com/35k7a8h.jpg


Also, another question: Is it really necessary to have 2 variables for those 2 points, when you can just write more lengthy, but actually the same trigger without variables? Like
  • (Distance between (Position of (Triggering unit) and (Position of (Target unit of issued order)) Greater than 200.00
This bugged me for longer time, when it comes to short triggers like this one, it seems really unnecessary to have some variables there, yet you use them, so i ask, is there any difference in effectiveness? For example, can frickinly lengthy trigger command bug, fail or slow down the game (or, whatever), or it doesnt matter whether i use

  • (Distance between (Position of (Triggering unit) and (Position of (Target unit of issued order)) Greater than 200.00
or

  • Set p_caster = (Position of (Triggering unit))
  • Set p_target = (Position of (Target unit of issued order))
  • (Distance between p_caster and p_target Greater than 200.00
thanks again! hope you understood me :D
 
Last edited:
Level 8
Joined
Oct 12, 2011
Messages
483
The order id of an ability is not the same as it's raw code name, but is the value under Text - Order String Use/Turn On. For the second question, it is not actually required to set those two points, the trigger will run without, but the problem is that it will leak. Read more about leaks and how to fix them here.
 
Level 7
Joined
Dec 28, 2009
Messages
257
Yay, i changed that condition with proper name, added pause and instant unpause, and it works! so fixed!

And about leaks: Woah, i thought its the variables that can leak, and using non-variable stuff is harmless - variables store some info, if that piles up, you get leaks and lag, using more lengthy stuff shouldnt store any data!
But i guess i was wrong...


Well, anyway, i guess ive got shitloads of leaks in my map then, will be hard time fixing it without JASS skills and with no idea what exactly can leak (ill ask later for some more tutorials too, i guess, or ill recruit somebody to fix-it-all or fix-what-i-forget-to-fiix :D)


And thanks :D
 
Status
Not open for further replies.
Top