1. Join Texturing Contest #30 now in a legendary battle of mythological creatures!
    Dismiss Notice
  2. The Aftermath has been revealed for the 19th Terraining Contest! Be sure to check out the Results and see what came out of it.
    Dismiss Notice
  3. Melee Mapping Contest #3 - Results are out! Congratulate the winners and check plenty of new 4v4 melee maps designed for this competition!
    Dismiss Notice
  4. The winners of our cinematic soundtrack competition have been decided! Step by the Music Contest #11 - Results to check the entries and congratulate the winners!
    Dismiss Notice
  5. Check out the Staff job openings thread.
    Dismiss Notice

[Snippet] Order Event

Discussion in 'JASS Resources' started by Bribe, Mar 2, 2011.

  1. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Like SpellEffectEvent, but this one is for catching orders. Also like SpellEffectEvent, this is pretty much as lightweight as it gets.

    Update to version 3.0.0.0 - now requires Table due to some orders having very high indices. Thanks to Spellbound for pointing this out. Also, I improved the initialization by not auto-registering all three events unless the user specifically calls RegisterOrderEvent.

    Code (vJASS):

    //============================================================================
    // OrderEvent by Bribe, special thanks to Nestharus and Azlier, version 3.0.1.1
    //
    // API
    // ---
    //     RegisterOrderEvent(integer orderId, code eventFunc)
    //     RegisterAnyOrderEvent(code eventFunc) //Runs for point/target/instant for any order
    //
    // Requires
    // --------
    //     RegisterPlayerUnitEvent: http://www.hiveworkshop.com/threads/snippet-registerevent-pack.250266/
    //     Table: http://www.hiveworkshop.com/forums/showthread.php?t=188084
    //
    library OrderEvent requires RegisterPlayerUnitEvent, Table

    globals
        private Table t = 0
    endglobals

    //============================================================================
    function RegisterAnyOrderEvent takes code c returns nothing
        static if RPUE_VERSION_NEW then
            call RegisterAnyPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, c)
            call RegisterAnyPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, c)
            call RegisterAnyPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, c)
        else
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, c)
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, c)
            call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_POINT_ORDER, c)
        endif
    endfunction

    //============================================================================
    private function OnOrder takes nothing returns nothing
        call TriggerEvaluate(t.trigger[GetIssuedOrderId()])
    endfunction

    //============================================================================
    function RegisterOrderEvent takes integer orderId, code c returns nothing
        local trigger trig
        if integer(t) == 0 then
            set t = Table.create()
            call RegisterAnyOrderEvent(function OnOrder)
        endif
        set trig = t.trigger[orderId]
        if trig == null then
            set trig = CreateTrigger()
            set t.trigger[orderId] = trig
        endif
        call TriggerAddCondition(trig, Filter(c))
        set trig = null
    endfunction

    endlibrary
     
    Last edited: Nov 14, 2016
  2. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Made this thing really tight and added in Nestharus' wise input that I can just subtract 0xD0000 instead of hashing the values in a hashtable.

    Shortened the API significantly and this should be very easy to pick up on.
     
  3. Nestharus

    Nestharus

    Joined:
    Jul 10, 2007
    Messages:
    6,149
    Resources:
    8
    Spells:
    3
    Tutorials:
    4
    JASS:
    1
    Resources:
    8
    Add thanks to azlier for finding that number as well (I got it from him).

    Otherwise looks a lot better =)
     
  4. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    0XD00000? :D
    I was trying to find that number for days :D
    This snippet is very useful ^^
     
  5. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Updated to use RegisterPlayerUnitEvent.
     
  6. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    *Votes for approval*
    :ogre_hurrhurr:
     
  7. Dirac

    Dirac

    Joined:
    Jun 20, 2011
    Messages:
    249
    Resources:
    3
    JASS:
    3
    Resources:
    3
    It would be great if this library provided with something such as GetUnitCurrentOrderX() and Y() to know where the unit is heading.
     
  8. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    That has nothing to do with this library. That has more to do with the LastOrder library on wc3c.net.
     
  9. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    LastOrder? :D
    I have been inspired ^^
     
  10. azlier

    azlier

    Joined:
    Oct 3, 2008
    Messages:
    354
    Resources:
    4
    JASS:
    4
    Resources:
    4
    Like RegisterPlayerUnitEvent, I think this can benefit from this post.
     
  11. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Updated, code is much shorter now.
     
  12. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Re-Added RegisterAnyOrderEvent. Is this fit for approval?
     
  13. watermelon_1234

    watermelon_1234

    Joined:
    Nov 18, 2007
    Messages:
    1,066
    Resources:
    10
    Spells:
    9
    JASS:
    1
    Resources:
    10
    I can't think of a situation when I want to have an event detecting a specific order for all three cases of being immediate, point, or target and making me have to manually differentiate between them.
    Because of this, I'm not sure when I would want to use this over
    RegisterPlayerUnitEvent
    and just filter out specific order ids.

    Of course, I would be open to suggestions. :p
     
  14. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    What if you only wanted to detect Undefend, or only detect a "stop" or "attack" order?
     
  15. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I don't get why you talked about the stop and undefend order, i mean they obviously are a not target order.
    Now, it quite makes sense for the attack order, since it can be a target or point order.

    Or am i missing something ?
     
  16. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Well the "RegisterOrderEvent" fires whenever that order ID is matched for any of the three events. I don't see a point in making a "RegisterTarget/Point/ImmediateOrderEvent".
     
  17. Troll-Brain

    Troll-Brain

    Joined:
    Apr 27, 2008
    Messages:
    2,372
    Resources:
    1
    JASS:
    1
    Resources:
    1
    I had just read what watermelon_1234 had said and what you answered to him.
    But now, i've reading your code and it makes sense.
    Most of times we only need to check about a specific order, and if we have the need to check all point or all target, or no target orders, then you just don't need this resource.
     
  18. Switch33

    Switch33

    Joined:
    Dec 3, 2006
    Messages:
    334
    Resources:
    0
    Resources:
    0
    Small typo. . .

    function RegisterAnyOrderEvent takes code order returns nothing

    ->
    function RegisterAnyOrderEvent takes code c returns nothing
     
  19. Bribe

    Bribe

    Joined:
    Sep 26, 2009
    Messages:
    7,759
    Resources:
    25
    Maps:
    3
    Spells:
    10
    Tutorials:
    3
    JASS:
    9
    Resources:
    25
    Bah, thanks for spotting that. That's the problem when I make small edits. Maybe I just shouldn't edit it at all even if it's just a little thing like that, until I have time to compile it.
     
  20. Magtheridon96

    Magtheridon96

    Joined:
    Dec 12, 2008
    Messages:
    6,007
    Resources:
    26
    Maps:
    1
    Spells:
    8
    Tutorials:
    7
    JASS:
    10
    Resources:
    26
    This is pretty nifty, and people will find uses for it. (Spell Development)

    I vote for approval.

    edit

    One problem: A trigger evaluation per order + 12 Spam clicking players + 50 attacking units = Dead