Spell Blink Move

Builder Bob

Live free or don't
Reaction score
249
I like to set the orderId at map init just as Acehart did. It makes it more readable than the alternative in my opinion.

However, if you really want that constant, you can set it to the integer variable directly instead of going via OrderId(). Personally, I think it's overkill.

JASS:
globals
    private constant integer attack = 851983
    private constant integer smart = 851971
endglobals
 

AceHart

Your Friendly Neighborhood Admin
Reaction score
1,495
say I wanted my hero to blink instead of moving, but only once every X seconds....there is no contingency plan for that...

Well, in that case you need some kind of "cache" system to keep track of usage over time.
AFAIK, there is no way to set a cooldown or get its current state...

Basic version:
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
    // Will work at most once every this many seconds
    private constant integer COOLDOWN = 4
    // 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
    private group g = CreateGroup()
    private integer array cache
endglobals

private function H2I takes unit u returns integer
    return u
    return 0
endfunction
private function cache_get takes unit u returns integer
    return cache[H2I(u) - 0x100000]
endfunction
private function cache_set takes unit u returns nothing
    set cache[H2I(u) - 0x100000] = COOLDOWN
endfunction

// The unit needs the spell and must have been ordered to move or attack-move (Right-click or "A")
// Additionally, it only works once every COOLDOWN seconds
private function Conditions takes nothing returns boolean
    if IsUnitInGroup(GetTriggerUnit(), g) then
        return cache_get(GetTriggerUnit()) <= 0 // Cooldown check
    endif
    return GetUnitAbilityLevel(GetTriggerUnit(), SPELL_ID) > 0 and (GetIssuedOrderId() == ORDER_SMART or GetIssuedOrderId() == ORDER_ATTACK)
endfunction

private function CooldownUnit takes nothing returns nothing
    local integer u = H2I(GetEnumUnit()) - 0x100000
    set cache<u> = cache<u> - 1
endfunction
private function Cooldown takes nothing returns nothing
    call ForGroup(g, function CooldownUnit)
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&#039;s position to target point

    if IsUnitInGroup(u, g) == false then
        call GroupAddUnit(g, u)
    endif
    call cache_set(u)

    if d &gt; MIN_DISTANCE then // Don&#039;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 &gt; 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 &quot;almost&quot; 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, &quot;move&quot;, x2, y2)
        else
            call IssuePointOrder(u, &quot;attack&quot;, x2, y2)
        endif
        call EnableTrigger(t)
    endif

    set u = null // Done
endfunction

private function Init takes nothing returns nothing
    set ORDER_SMART = OrderId(&quot;smart&quot;)
    set ORDER_ATTACK = OrderId(&quot;attack&quot;)
    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)
    call TimerStart(CreateTimer(), 0.95, true, function Cooldown)
endfunction
endscope
</u></u>
 

Trollvottel

never aging title
Reaction score
262
it's solution should be orb of... slow? (+ searing arrows with no damage and with cooldown)
 

Builder Bob

Live free or don't
Reaction score
249
I don't know if you missed my post (#11) or if you just ignored it, but issuing a new order in a function triggered by an order event really doesn't work. The new order is totally ignored.

The reason for it is that the order that triggers the event is actually carried out after the code is run. (This is similar to how in damage events, damage is done after the code in the triggered function has been run.)

You can easily see this by trying to issue a stop order or us using SetUnitPosition(GetTriggerUnit(), x, y) in a function triggered by an order event. The result is that the unit won't stop, even though SetUnitPosition() always stops a unit's orders in other circumstances.
 
J

JaerN

Guest
How can i create so the unit can moveto a higer platform ?? like this

Please response :D

Happy coding :D:shades:
 
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