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.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      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