[Snippet] AutocastOrderEvent

Level 8
Joined
Oct 3, 2008
Messages
367
This detects when you turn on or off autocast. You know, by right clicking the ability icon. Yep.

If you encounter an autocast order that is unresponsive, please tell me.

Six functions available to you:
JASS:
TriggerRegisterAutocastOnEvent takes trigger whichTrigger returns nothing
//Readies a trigger to fire when autocast is turned on.

TriggerRegisterAutocastOffEvent takes trigger whichTrigger returns nothing
//Same as above, but for when autocast is turned off.

TriggerRegisterAutocastEvent takes trigger whichTrigger, boolean on returns nothing
//If true, it does the first function. If false, it does the second.

AutocastOnEvent takes code func returns nothing
//Like TriggerRegisterAutocastOnEvent but takes a code. Is faster.

AutocastOffEvent takes code func returns nothing
//Like TriggerRegisterAutocastOffEvent but takes a code. Is faster.

AutocastEvent takes code func, boolean on returns nothing
//Like TriggerRegisterAutocastEvent but takes a code. Is faster.

Requirements:
Jesus4Lyf's Event OR Nestharus' Event
RegisterPlayerUnitEvent

There are no configurables.
JASS:
library AutocastOrderEvent requires Event, RegisterPlayerUnitEvent
            
globals
    private constant integer OFFSET = 0xD0000
    private Event array Data
    private Event On
    private Event Off
endglobals

static if Event.registerTrigger.exists then
//Nestharus' Event

function TriggerRegisterAutocastOnEvent takes trigger whichTrigger returns nothing
    call On.registerTrigger(whichTrigger)
endfunction

function TriggerRegisterAutocastOffEvent takes trigger whichTrigger returns nothing
    call Off.registerTrigger(whichTrigger)
endfunction

function AutocastOnEvent takes code func returns nothing
    call On.register(Filter(func))
endfunction

function AutocastOffEvent takes code func returns nothing
    call Off.register(Filter(func))
endfunction
    
else
//Jesus4Lyf's Event

private struct cGlobal extends array
    static trigger cOnTrig = CreateTrigger()
    static trigger cOffTrig = CreateTrigger()
    static trigger array cTrig
endstruct

function TriggerRegisterAutocastOnEvent takes trigger whichTrigger returns nothing
    call On.register(whichTrigger)
endfunction

function TriggerRegisterAutocastOffEvent takes trigger whichTrigger returns nothing
    call Off.register(whichTrigger)
endfunction

function AutocastOnEvent takes code func returns nothing
    call TriggerAddCondition(cGlobal.cOnTrig, Filter(func))
endfunction

function AutocastOffEvent takes code func returns nothing
    call TriggerAddCondition(cGlobal.cOffTrig, Filter(func))
endfunction

endif

function TriggerRegisterAutocastEvent takes trigger whichTrigger, boolean on returns nothing
    if on then
        call TriggerRegisterAutocastOnEvent(whichTrigger)
    else
        call TriggerRegisterAutocastOffEvent(whichTrigger)
    endif
endfunction

function AutocastEvent takes code func, boolean on returns nothing
    if on then
        call AutocastOnEvent(func)
    else
        call AutocastOffEvent(func)
    endif
endfunction

private function Fire takes nothing returns boolean
    static if (Event.registerTrigger.exists) then
        call Data[GetIssuedOrderId() - OFFSET].fire()
    else
        local integer i = GetIssuedOrderId() - OFFSET
        call Data[i].fire()
        call TriggerEvaluate(cGlobal.cTrig[i])
    endif
    return false
endfunction

private function RegisterOrder takes integer i returns nothing
    set Data[i] = On
    set Data[i + 1] = Off
    static if (not Event.registerTrigger.exists) then
        set cGlobal.cTrig[i] = cGlobal.cOnTrig
        set cGlobal.cTrig[i + 1] = cGlobal.cOffTrig
    endif
endfunction

private module Superhack
    private static method onInit takes nothing returns nothing
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function Fire)
    
        set On = Event.create()
        set Off = Event.create()
    
        //Register all autocast orders. Oh God.
        call RegisterOrder(0x060) //Heal
        call RegisterOrder(0x063) //Inner Fire
        call RegisterOrder(0x06C) //Slow
        call RegisterOrder(0x204) //Spell Steal
        call RegisterOrder(0x086) //Bloodlust
        call RegisterOrder(0x0F4) //Web
        call RegisterOrder(0x0DF) //Curse
        call RegisterOrder(0x0E6) //Raise Dead
        call RegisterOrder(0x242) //Essence of Blight
        call RegisterOrder(0x245) //Spirit Touch
        call RegisterOrder(0x1EA) //Frost Armor
        call RegisterOrder(0x0B6) //Faerie Fire
        call RegisterOrder(0x0A5) //Abolish Magic
        call RegisterOrder(0x0CE) //Searing Arrows
        call RegisterOrder(0x114) //Cold Arrows
        call RegisterOrder(0x27A) //Parasite
        call RegisterOrder(0x039) //Repair
        call RegisterOrder(0x0EB) //Restore
        call RegisterOrder(0x0C2) //Renew
        call RegisterOrder(0x0BE) //Recharge
        call RegisterOrder(0x248) //Carrion Beetles
        call RegisterOrder(0x262) //Black Arrow
        call RegisterOrder(0x23C) //Orb of Annihilation
        call RegisterOrder(0x053) //Get Corpse
        call RegisterOrder(0x049) //Kaboom!
        call RegisterOrder(0x11F) //Poison Arrows
        call RegisterOrder(0x2BF) //Incinerate Arrows...?
    endmethod
endmodule

private struct Hack extends array
    implement Superhack
endstruct

endlibrary
 
Last edited:
Level 16
Joined
Oct 12, 2008
Messages
1,570
Pretty Awesome!
but why, oh why, does TriggerHappy not say anything about you inlining the Events?
He is always saying it isnt anything more efficient, and it makes it less readable, etc. etc.
No offense, but why bug other people about inlining it, while you approve this (well ok, approve isnt the problem, not say anything about it is) with an inlined event?

nice system!
 
Level 7
Joined
Dec 3, 2006
Messages
342
JASS:
library AutocastOrderEvent requires Event, RegisterPlayerUnitEvent
            
globals
    private constant integer OFFSET = 0xD0000
    private integer array Data
    private Event On
    private Event Off
endglobals

function TriggerRegisterAutocastOnEvent takes trigger t returns nothing
    call On.registerTrigger(t)
endfunction

function TriggerRegisterAutocastOffEvent takes trigger t returns nothing
    call Off.registerTrigger(t)
endfunction

function TriggerRegisterAutocastEvent takes trigger t, boolean on returns nothing
    if on then
        call TriggerRegisterAutocastOnEvent(t)
    else
        call TriggerRegisterAutocastOffEvent(t)
    endif
endfunction

private function Fire takes nothing returns boolean
    call Event(Data[GetIssuedOrderId() - OFFSET]).fire()
    return false
endfunction

private function RegisterOrder takes integer i returns nothing
    set Data[i] = On
    set Data[i + 1] = Off
endfunction

private module Superhack
    private static method onInit takes nothing returns nothing
        call RegisterPlayerUnitEvent(EVENT_PLAYER_UNIT_ISSUED_ORDER, function Fire)
    
        set On = Event.create()
        set Off = Event.create()

        //Register all autocast orders. Oh God.
        call RegisterOrder(0x060) //Heal
        call RegisterOrder(0x063) //Inner Fire
        call RegisterOrder(0x06C) //Slow
        call RegisterOrder(0x204) //Spell Steal
        call RegisterOrder(0x086) //Bloodlust
        call RegisterOrder(0x0F4) //Web
        call RegisterOrder(0x0DF) //Curse
        call RegisterOrder(0x0E6) //Raise Dead
        call RegisterOrder(0x242) //Essence of Blight
        call RegisterOrder(0x245) //Spirit Touch
        call RegisterOrder(0x1EA) //Frost Armor
        call RegisterOrder(0x0B6) //Faerie Fire
        call RegisterOrder(0x0A5) //Abolish Magic
        call RegisterOrder(0x0CE) //Searing Arrows
        call RegisterOrder(0x114) //Cold Arrows
        call RegisterOrder(0x27A) //Parasite
        call RegisterOrder(0x039) //Repair
        call RegisterOrder(0x0EB) //Restore
        call RegisterOrder(0x0C2) //Renew
        call RegisterOrder(0x0BE) //Recharge
        call RegisterOrder(0x248) //Carrion Beetles
        call RegisterOrder(0x262) //Black Arrow
        call RegisterOrder(0x23C) //Orb of Annihilation
        call RegisterOrder(0x053) //Get Corpse
        call RegisterOrder(0x049) //Kaboom!
        call RegisterOrder(0x11F) //Poison Arrows
        call RegisterOrder(0x2BF) //Incinerate Arrows...?
    endmethod
endmodule

private struct Hack
    implement Superhack
endstruct

endlibrary
A quick rewrite of this to work with Nesthareus's event instead of Jesus4lyf's instead. Thought i'd post it on the thread if anyone uses Nes's event instead.
 
Last edited:

BBQ

BBQ

Level 4
Joined
Jun 7, 2011
Messages
97
private struct Hack

An array struct should be used instead. Even so, I see no point in initializing this from a module.
 
Top