1. The Melee Mapping Contest #4: 2v2 - Results are out! Step by to congratulate the winners!
    Dismiss Notice
  2. We're hosting the 15th Mini-Mapping Contest with YouTuber Abelhawk! The contestants are to create a custom map that uses the hidden content within Warcraft 3 or is inspired by any of the many secrets within the game.
    Dismiss Notice
  3. The 20th iteration of the Terraining Contest is upon us! Join and create exquisite Water Structures for it.
    Dismiss Notice
  4. Check out the Staff job openings thread.
    Dismiss Notice

[Solved] Why is unit not stopping?

Discussion in 'Triggers & Scripts' started by loktar, May 15, 2019.

  1. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    I'm trying to order a unit to stop:

    Code (vJASS):


        private function TankerOrderCndAcn takes nothing returns boolean
            local integer targetId = GetUnitTypeId(GetOrderTargetUnit())
            local string orderStr = OrderId2String(GetIssuedOrderId())
            local string targetStr = null
            local unit tanker = null
       
            if orderStr == "returnresources" and targetId != 'h000' then
                set targetStr = "Refinery"
            elseif orderStr == "harvest" and targetId != 'h001' then
                set targetStr = "Platform"
            endif
       
            if targetStr != null then
                set tanker = GetOrderedUnit()
                call DisplayTextToPlayer(GetOwningPlayer(tanker), 1, 1, "|cffffcc00Must target an Oil "+targetStr+".|r")
                call IssueImmediateOrder(tanker, "stop")
                call BJDebugMsg(GetUnitName(tanker)) // Correctly shows unit's name
                set tanker = null
            endif
       
            return false
        endfunction

    // .....

            call TriggerRegisterPlayerUnitEvent(trgTankerOrder, plr, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, function TankerFltr)

            call TriggerAddCondition(trgTankerOrder, function TankerOrderCndAcn)
     


    But it's not happening. Any idea why?
    The abilities with "returnresources"/"harvest" are custom Channel abilities, TankerFltr just filters by unit type.
     
  2. MyPad

    MyPad

    Spell Reviewer

    Joined:
    May 9, 2014
    Messages:
    1,242
    Resources:
    5
    Models:
    1
    Icons:
    1
    Spells:
    2
    JASS:
    1
    Resources:
    5
    Try pausing the unit first before issuing the stop command. Unpause the unit afterwards.

    The solution above is notable for overriding the current order of the unit, and may affect Shift-Queue orders.
     
  3. GhostHunter123

    GhostHunter123

    Joined:
    Oct 17, 2012
    Messages:
    434
    Resources:
    1
    Spells:
    1
    Resources:
    1
    Code (vJASS):
    call IssueImmediateOrderById(tanker, 851973)
    The order for stun might be a better alternative to stop. Prevent an Unit Order
     
  4. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Ah, so if the unit is paused first, it will not remove queued orders? :D
    Edit: just tested, queued orders still removed so I must've misunderstood. Unit is stopping now though!
    Is there a way to cancel the order without removing queued orders?

    Why is it better? The thread doesn't make that clear to me.
     
    Last edited: May 15, 2019
  5. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    I believe it's something like:

    stoporder is instant
    moveorder is not instant

    1. Unit gets move order, but does not instantly finish, comes in queue
    2. Unit gets stop order, gets processed right away and overrides move order, and is finished right after, no queue
      => stop order has finished, and now move order still comes from queue
    with pause:
    1. Unit gets move order, not instantly finishes, comes in queue
    2. Pause & Unpause unit -> clears the order queue
    3. Order stop, overrides move ordered move
    Waiting a short amount of time might maybe work, that the stop really gets ordered after the move order has really finished. (maybe timer with "0" is not long enough..)
     
  6. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Waiting before stopping still removes queued orders (queued with shift), but I had the idea to remove the ability and add it again, which appears to work, shift-queued orders are retained :D
    I tested it with 1s wait, but it will probably work with a shorter wait too (doesn't work without a wait).
     
  7. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    What queued order is actually in the context? Could you please explain the exact scenario what is done and wanted, with code, I'm interested, too.^^
     
  8. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Well, anything the player orders with shift-rightclick.
    So I want to cancel the order from the code above, without removing queued orders added by shift-rightclicking.

    Simply doing this:
    Code (vJASS):

            call UnitRemoveAbility(tanker, abilId)
            call TriggerSleepAction(0)
            call UnitAddAbility(tanker, abilId)
     


    Will cancel the order corresponding to that ability, while retaining shift-queued orders.

    The (mostly) complete example:
    Code (vJASS):

        private function TankerOrderCnd takes nothing returns boolean
            local string orderStr = OrderId2String(GetIssuedOrderId())
            local integer targetId = GetUnitTypeId(GetOrderTargetUnit())
            return (orderStr == "returnresources" and targetId != 'h000' and targetId != 'h002') or (orderStr == "harvest" and targetId != 'h001')
        endfunction
     
        private function TankerOrderAcn takes nothing returns nothing
            local string str = OrderId2String(GetIssuedOrderId())
            local unit tanker = GetOrderedUnit()
            local integer id
         
            if str == "returnresources" then
                set id = 'A001'
                set str = "a Shipyard or an Oil Refinery"
            elseif str == "harvest" then
                set id = 'A000'
                set str = "an Oil Platform"
            endif
         
            if not GetSoundIsPlaying(SND_ERR) then
                call StartSound(SND_ERR)
            endif
            call DisplayTimedTextToPlayer(GetOwningPlayer(tanker), 0.512, 0, 10, "|cffffcc00Must target "+str+".|r")
            call UnitRemoveAbility(tanker, id)
            call TriggerSleepAction(0)
            call UnitAddAbility(tanker, id)
         
            set tanker = null
        endfunction

    // ... initializer:


            call TriggerRegisterPlayerUnitEvent(trgTankerOrder, plr, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, function TankerFltr)
            call TriggerAddCondition(trgTankerOrder, function TankerOrderCnd)
            call TriggerAddAction(trgTankerOrder, function TankerOrderAcn)
     


    The downside is that you can see the ability disappear for a moment. It will probably also work if you disable the ability instead, and then you won't see it disappear.
     
  9. IcemanBo

    IcemanBo

    Joined:
    Sep 6, 2013
    Messages:
    6,098
    Resources:
    22
    Maps:
    3
    Spells:
    11
    Template:
    1
    Tutorials:
    4
    JASS:
    3
    Resources:
    22
    Ah ok, yes. Thanks for explanation.
    I don't know all prequities anymore, but I applied same method some time in some abilities in a map, example Trigger Viewer | HIVE. I remove ability onOrder, and add the ability again after 0 duration timer, and iirc it works without noticing the ability being removed. But yes if disable ability works it's probably better.
     
  10. loktar

    loktar

    Joined:
    Nov 2, 2004
    Messages:
    701
    Resources:
    24
    Models:
    2
    Icons:
    16
    Packs:
    1
    Tools:
    2
    Spells:
    2
    Tutorials:
    1
    Resources:
    24
    Hmm, you're using a timer there, maybe that would be better. It's noticeable when using TriggerSleepAction(0).
    This script is supposed to work for pre-1.29 patches though, so can't use Disable atm.