Spell Blink Move

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
What is it?

"Blink Move" is a passive ability that automagically blinks you to some target point when you order your unit to move or attack-move.

Why would I want that?

- It's fun.
- It makes all the sense on epic maps :p
- You get the fastest unit around.
- Just because.

GUI

Trigger:
  • Blink Move GUI
    • Events
      • Unit - A unit Is issued an order targeting a point
    • Conditions
      • (Level of Blink for (Triggering unit)) Greater than 0
      • Or - Any (Conditions) are true
        • Conditions
          • (Issued order) Equal to (Order(smart))
          • (Issued order) Equal to (Order(attack))
    • Actions
      • Set Point1 = (Position of (Triggering unit))
      • Set Point2 = (Target point of issued order)
      • Set Distance = (Distance between Point1 and Point2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Distance Greater than 500.00
        • Then - Actions
          • Special Effect - Create a special effect at Point1 using Abilities\Spells\NightElf\Blink\BlinkCaster.mdl
          • Special Effect - Destroy (Last created special effect)
          • Special Effect - Create a special effect at Point2 using Abilities\Spells\NightElf\Blink\BlinkTarget.mdl
          • Special Effect - Destroy (Last created special effect)
          • Set Distance = (Distance - 200.00)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Distance Greater than 2000.00
            • Then - Actions
              • Set Distance = 2000.00
            • Else - Actions
          • Set Point3 = (Point1 offset by Distance towards (Angle from Point1 to Point2) degrees)
          • Unit - Move (Triggering unit) instantly to Point3
          • Custom script: call RemoveLocation( udg_Point3 )
          • Trigger - Turn off (This trigger)
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Issued order) Equal to (Order(smart))
            • Then - Actions
              • Unit - Order (Triggering unit) to Move To Point2
            • Else - Actions
              • Unit - Order (Triggering unit) to Attack-Move To Point2
          • Trigger - Turn on (This trigger)
        • Else - Actions
      • Custom script: call RemoveLocation( udg_Point1 )
      • Custom script: call RemoveLocation( udg_Point2 )


Usage:
Either enter the trigger yourself, or copy&paste it from the attached map.
For copy&paste to work correctly, make sure to have a check on "auto-create unknown variables" in menu: File / Preferences.
Edit the condition as needed.

JASS

JASS:
scope BlinkMove initializer Init
globals
    // Order ID of your ability
    private constant integer SPELL_ID = 'AEbl'
    // Adjust to taste
    private constant real MIN_DISTANCE = 500.0 // No blink if less than this
    private constant real MAX_DISTANCE = 2000.0 // Set to 99999.0 if you want this to work across the entire map
    private constant real END_DISTANCE = 200.0 // Blink this close to the end point
    // Effects to show on start and end points
    private constant string EFFECT_START = "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
    private constant string EFFECT_END = "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl"

    // Leave as is
    private trigger t = CreateTrigger()
    private integer ORDER_SMART
    private integer ORDER_ATTACK
endglobals

// The unit needs the spell and must have been ordered to move or attack-move (Right-click or "A")
private function Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), SPELL_ID) > 0 and (GetIssuedOrderId() == ORDER_SMART or GetIssuedOrderId() == ORDER_ATTACK)
endfunction

private function Actions takes nothing returns nothing
    local unit u = GetTriggerUnit() // Caster
    local real x1 = GetUnitX(u) // Position of caster
    local real y1 = GetUnitY(u)
    local real x2 = GetOrderPointX() // Point we want to go to
    local real y2 = GetOrderPointY()
    local real d = SquareRoot((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) // Distance from caster to target point
    local real a = Atan2(y2 - y1, x2 - x1) // Angle from caster's position to target point

    if d > MIN_DISTANCE then // Don't blink for too short a distance
        call DestroyEffect(AddSpecialEffect(EFFECT_START, x1, y1)) // Eye-candy starting point
        set d = d - END_DISTANCE // This close to the end point
        if d > MAX_DISTANCE then // but respect the maximum distance
            set d = MAX_DISTANCE
        endif
        set x1 = x1 + d * Cos(a) // Point that is nearly there
        set y1 = y1 + d * Sin(a)
        call DestroyEffect(AddSpecialEffect(EFFECT_END, x1, y1)) // Eye-candy target point
        call SetUnitX(u, x1) // Move caster "almost" there...
        call SetUnitY(u, y1)
        call DisableTrigger(t)
        if GetIssuedOrderId() == ORDER_SMART then // ...and order the unit to (attack-)move the rest
            call IssuePointOrder(u, "move", x2, y2)
        else
            call IssuePointOrder(u, "attack", x2, y2)
        endif
        call EnableTrigger(t)
    endif

    set u = null // Done
endfunction

private function Init takes nothing returns nothing
    set ORDER_SMART = OrderId("smart")
    set ORDER_ATTACK = OrderId("attack")
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER) // A unit is issued an order targeting a point
    call TriggerAddCondition(t, Condition(function Conditions))
    call TriggerAddAction(t, function Actions)
endfunction
endscope


Usage:
Create a new trigger, convert to custom script.
Replace whatever shows there with the above.
Adjust constants as needed.
Requires NewGen.


Enjoy.

Yours,
AceHart


Q: OMG, this has been done 1000003 times already!
A: So?

Q: It's MUI I take it?
A: Yep.

Q: The GUI version too?
A: Yep.

Q: Why is there a GUI version actually???
A: Yep.

Q: Looks simple...
A: Yep.

Q: Would be good to have a different max distance per level
A: Well, then get busy.

Q: My unit ended up in some weird spot!
A: Well, it has Blink Move, doesn't it?

Q: I WAITS JUST FOR TAHT!!!1one1LOL!
A: Coincidence

Q: Are there any leaks?
A: ...

Q: Why do you turn the trigger off near the end?
A: If remaining distance greater than minimum distance then call trigger again automatically

Q: ...
A: Me too



The map:
 

Attachments

  • BlinkMove_Demo_AceHart.w3x
    15.2 KB · Views: 592

D.V.D

Make a wish
Reaction score
73
I remember when I just got TFT and tried to make this spell. It worked but it leaked quite a bit. Anyways nice spell + rep. I don't see any mistakes or ways to improve.
 

saw792

Is known to say things. That is all.
Reaction score
280
If you are going to make them blink when they right-click and when they attack, why not when they move as well?
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
Well, I guess you have your reasons for actually using "move".
I don't really see how you could use it by accident...

But, if you really want to, just add an extra test to the conditions.
 

emjlr3

Change can be a good thing
Reaction score
395
what if my passive ability has a cooldown?
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
889
Approved.

Another simple function done perfectly and with all contingencies considered by AceHart.

Way to go Ace! :thup:
 

Romek

Super Moderator
Reaction score
963
JASS:
private integer ORDER_SMART
private integer ORDER_ATTACK

Can't you make these constant, with initial values? Would be faster.

Q: Why is there a GUI version actually???
A: Yep.
I lol'd :p
 

Romek

Super Moderator
Reaction score
963
> Anman64

JASS:
constant function Blink_Move_ID takes nothing returns integer
    return 'AEbl'
endfunction

constant function Blink_Move_MIN_DISTANCE takes nothing returns real
    return 500.0
endfunction

constant function Blink_Move_MAX_DISTANCE takes nothing returns real
    return 2000.
endfunction

constant function Blink_Move_END_DISTANCE takes nothing returns real
    return 200.
endfunction

constant function Blink_Move_EFFECT_START takes nothing returns string
    return "Abilities\\Spells\\NightElf\\Blink\\BlinkCaster.mdl"
endfunction

constant function Blink_Move_EFFECT_END takes nothing returns string
    return "Abilities\\Spells\\NightElf\\Blink\\BlinkTarget.mdl"
endfunction

function Blink_Move_Conditions takes nothing returns boolean
    return GetUnitAbilityLevel(GetTriggerUnit(), Blink_Move_ID()) > 0 and (GetIssuedOrderId() == OrderId("smart") or GetIssuedOrderId() == OrderId("attack"))
endfunction

function Blink_Move_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit() // Caster
    local real x1 = GetUnitX(u) // Position of caster
    local real y1 = GetUnitY(u)
    local real x2 = GetOrderPointX() // Point we want to go to
    local real y2 = GetOrderPointY()
    local real d = SquareRoot((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) // Distance from caster to target point
    local real a = Atan2(y2 - y1, x2 - x1) // Angle from caster's position to target point
    local trigger t = GetTriggeringTrigger()

    if d > Blink_Move_MIN_DISTANCE() then // Don't blink for too short a distance
        call DestroyEffect(AddSpecialEffect(Blink_Move_EFFECT_START(), x1, y1)) // Eye-candy starting point
        set d = d - Blink_Move_END_DISTANCE() // This close to the end point
        if d > Blink_Move_MAX_DISTANCE() then // but respect the maximum distance
            set d = Blink_Move_MAX_DISTANCE()
        endif
        set x1 = x1 + d * Cos(a) // Point that is nearly there
        set y1 = y1 + d * Sin(a)
        call DestroyEffect(AddSpecialEffect(Blink_Move_EFFECT_END(), x1, y1)) // Eye-candy target point
        call SetUnitX(u, x1) // Move caster "almost" there...
        call SetUnitY(u, y1)
        call DisableTrigger(t)
        if GetIssuedOrderId() == OrderId("smart") then // ...and order the unit to (attack-)move the rest
            call IssuePointOrder(u, "move", x2, y2)
        else
            call IssuePointOrder(u, "attack", x2, y2)
        endif
        call EnableTrigger(t)
    endif

    set t = null
    set u = null // Done
endfunction

function InitTrig_Blink_Move takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER) // A unit is issued an order targeting a point
    call TriggerAddCondition(t, Condition(function Blink_Move_Conditions))
    call TriggerAddAction(t, function Blink_Move_Actions)
endfunction


An easy conversion. :p
The vJass one is obviously neater, nicer and more efficient. (Much less function calls)

Edit: Trigger must be called "Blink Move"
 

Builder Bob

Live free or don't
Reaction score
249
Issuing new orders in an order event actually doesn't do anything.

JASS:
call DisableTrigger(t)
if GetIssuedOrderId() == ORDER_SMART then // ...and order the unit to (attack-)move the rest
    call IssuePointOrder(u, "move", x2, y2)
else
    call IssuePointOrder(u, "attack", x2, y2)
endif
call EnableTrigger(t)


The spell functions exactly the same with this part removed.

It works very well already, so there's no problem really. Just unnecessary.
 

w00t22

CSS L4D DoD? Steam ID = w00t22
Reaction score
43
everytime i see a post from aceheart involing a system or spell i go straight to Q&A its fucking hilarous

Q: Would be good to have a different max distance per level
A: Well, then get busy.
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
> Can't you make these constant, with initial values? Would be faster.

If OrderId("order") worked in a globals block, I would have used it...
It doesn't though, so it's set in "Init".
Which is nearly the same after all. You lose a bit on readability.

As for faster, looking up an integer variable is just the same as looking up an integer variable.
 

vinkia

New Member
Reaction score
0
Vinkia

Nice spell..umm i just signed up for this site and wad is GUI??does it mean that spells are made of triggers?
 

emjlr3

Change can be a good thing
Reaction score
395
say I wanted my hero to blink instead of moving, but only once every X seconds....there is no contingency plan for that...
 

Kazuga

Let the game begin...
Reaction score
110
Ontopic:
Nice spell Ace, simple but yet useful. ^^

Offtopic:
Nice spell..umm i just signed up for this site and wad is GUI??does it mean that spells are made of triggers?
GUI = Graphical User Interface, it's the code where you select and click around instead of typing your code. Compare the codes in the first post, the upper one is in GUI.

Trigger = The file that contains the code. It can be either GUI, Jass (Blizzard's programming language) or vJass (a new and improved version of Jass).
 

Romek

Super Moderator
Reaction score
963
As for faster, looking up an integer variable is just the same as looking up an integer variable.

I believe constants are inlined into the code. (At either saving, or optimizing). So it does end up faster.
But, seeing as the function doesn't work at Map Init. I guess there isn't much we can do about that. :rolleyes:
 

Flare

Stops copies me!
Reaction score
662
Nice idea to actually post something like this, I recall seeing this (well, some variation of it) in a DnD map, much fun to be had fleeing from everyone and everything :D
If OrderId("order") worked in a globals block, I would have used it...
Works for me (well, at least it saves without any errors, not sure if there are any in-game effects) :p

But, seeing as the function doesn't work at Map Init.
But, ahm... aren't initializers called at Map Init? :p

Would be faster.
So it does end up faster.
Hmmm, seems I was misinformed when you said you didn't care about speed :D
 

Romek

Super Moderator
Reaction score
963
Hmmm, seems I was misinformed when you said you didn't care about speed :D

Well, if there's the option of increasing the speed of something by adding a single word, then why not? :D
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,497
> aren't initializers called at Map Init?

Yep. That's why the OrderId calls are there; not in the globals block where it saves just fine, but doesn't work.
And, yes, the entire point of having those order constants is speed.
It's faster to get them once than to convert those orders on every move.
After all, right-clicking somewhere tends to happen rather often...
('course, we're talking micro-seconds here... :p)

> I believe constants are inlined into the code.

'hfoo'? Yes. That's a true, real constant.
OrderId("smart")? That's a function call... if you inline that, you miss the entire point of just calling it once.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top