TriggerRegister<...> to Reg

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62




Warcraft 3 The Frozen Throne has 126 events [if you count that the​
unitevent(s) are different from the their corresponding playerunitevent(s),​
if not then 85 and of course if I've counted them correctly =)]. They are​
pretty much the same except that unitevent(s) have 4 more events than the​
playerunitevent(s) called EVENT_UNIT_STATE_LIMIT, EVENT_WIDGET_DEATH, EVENT_UNIT_ACQUIRED_TARGET and​
the infamous EVENT_UNIT_DAMAGED.​
-
They are organized in 5 types of events all of which extend the eventid type which extends the handle type:​
1: gameevent [ex: EVEMT_GAME_VARIABLE_LIMIT (and also the trackable events and the timer expire event )]​
2: playerevent [ex: EVENT_PLAYER_END_CINEMATIC aka EVENT_PLAYER_ESC_UP]​
3: playerunitevent [ex: EVENT_PLAYER_UNIT_SPELL_EFFECT (spells anyone?)]​
4: unitevent [ex: EVENT_UNIT_SPELL_EFFECT (and also the widget death event]​
5: dialogevent [EVENT_DIALOG_BUTTON_CLICK and EVENT_DIALOG_CLICK]​
-
What I tried to do is to wrap all the TriggerRegister<...> native calls​
in 1 function so that people don't have to remember both the event's name​
and it's native function but only the event's name [and 1 function =)].​
When I wrote all I really ment all - 1. The one event that is not covered by​
the function is the EVENT_PLAYER_CHAT. The reason is that the boolean parameter​
will only be used for this 1 case and it is rather mysterious seeing a ", true/false"​
(by mysterious I mean meaningless), so if people intend to write some player​
commands like "-clear" then they won't be able to use this function.​
-
The function's signature (return type, function name and the type of the parameters) is the following:​
-
[ljass]function Reg takes eventid e, code condition, code action, handle o1, handle o2, handle o3 real r, string s returns trigger[/ljass]​
-
It returns a trigger so that people could disable the event if it's required.​
-
The first parameter eventid e is the name of the event (ex: EVENT_TIMER_EXPIRED, EVENT_GAME_ENTER_REGION, EVENT_PLAYER_UNIT_SPELL_EFFECT, EVENT_PLAYER_CHAT, etc... [you can of course find all of them in the common.j file])​
The next two code parameters code condition and code action are the condition and the action that will be called when the event happens.​
The next parameter o1 is used when a native takes a single handle parameter (very ofen), ex:​
all the playerevent(s), EVENT_WIDGET_DEATH, all the unitevent(s) the dialog events, the trackable events etc.​
The next parameter o2 is used when a second parameter is required, ex:​
in the region enter/leave events it holds the boolexpr filter, in the gamestate event the limitop comparator.​
The third and last handle parameter o3 is used for the unitstate limit and playerstate limit events.​
The next parameter real r when real values are required by a native, ex:​
in variable limit event, in the games/player/unitstate limit events)​
The last parameter string s is used with the playerunitevent(s).​
It takes hex digits([0-9A-F], each digit represents the id of the player. The "0-F" means all players and the "0-B" means all​
playable players. Note that "0123456789AB" is the same as "0-B". You can include multiple ranges "0-46-8AB" and the​
event will be registered for player 0 through 4 then skip 5, then register for player 6, 7 and 8, then skip​
player 9, and finally register for player 10 and 11 if it's required.​
-
-
-
[ljass]function eid2ge takes eventid e returns gameevent[/ljass]
[ljass] return e[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function eid2pe takes eventid e returns playerevent[/ljass]
[ljass] return e[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function eid2pue takes eventid e returns playerunitevent[/ljass]
[ljass] return e[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function eid2ue takes eventid e returns unitevent[/ljass]
[ljass] return e[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2lop takes handle h returns limitop[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2gs takes handle h returns gamestate[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2ps takes handle h returns playerstate[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2us takes handle h returns unitstate[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2player takes handle h returns player[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2unit takes handle h returns unit[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2widget takes handle h returns widget[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2timer takes handle h returns timer[/ljass]
[ljass] return h[/ljass]
[ljass]endfunction[/ljass]

[ljass]function h2boolexpr takes handle h returns boolexpr[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2region takes handle h returns region[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2trackable takes handle h returns trackable[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2dialog takes handle h returns dialog[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function h2dialogbutton takes handle h returns button[/ljass]
[ljass] return h[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function hex_digit_to_integer takes string hd returns integer[/ljass]
[ljass] local integer result = 0[/ljass]​

[ljass] set hd = StringCase(hd, true)[/ljass]​
[ljass] if "0" == hd then[/ljass]​
[ljass] set result = 0[/ljass]​
[ljass] elseif "1" == hd then[/ljass]​
[ljass] set result = 1[/ljass]​
[ljass] elseif "2" == hd then[/ljass]​
[ljass] set result = 2[/ljass]​
[ljass] elseif "3" == hd then[/ljass]​
[ljass] set result = 3[/ljass]​
[ljass] elseif "4" == hd then[/ljass]​
[ljass] set result = 4[/ljass]​
[ljass] elseif "5" == hd then[/ljass]​
[ljass] set result = 5[/ljass]​
[ljass] elseif "6" == hd then[/ljass]​
[ljass] set result = 6[/ljass]​
[ljass] elseif "7" == hd then[/ljass]​
[ljass] set result = 7[/ljass]​
[ljass] elseif "8" == hd then[/ljass]​
[ljass] set result = 8[/ljass]​
[ljass] elseif "9" == hd then[/ljass]​
[ljass] set result = 9[/ljass]​
[ljass] elseif "A" == hd then[/ljass]​
[ljass] set result = 10[/ljass]​
[ljass] elseif "B" == hd then[/ljass]​
[ljass] set result = 11[/ljass]​
[ljass] elseif "C" == hd then[/ljass]​
[ljass] set result = 12[/ljass]​
[ljass] elseif "D" == hd then[/ljass]​
[ljass] set result = 13[/ljass]​
[ljass] elseif "E" == hd then[/ljass]​
[ljass] set result = 14[/ljass]​
[ljass] elseif "F" == hd then[/ljass]​
[ljass] set result = 15[/ljass]​
[ljass] endif[/ljass]​

[ljass] return result[/ljass]​
[ljass]endfunction[/ljass]

[ljass]function Reg takes eventid e, code condition, code action, handle o1, handle o2, handle o3, real r, string s returns trigger[/ljass]
[ljass] local trigger t = CreateTrigger()[/ljass]​
[ljass] local integer eid = GetHandleId(e)[/ljass]​
[ljass] local integer i = 0[/ljass]​
[ljass] local string ch = ""[/ljass]​
[ljass] local integer a = 0 [/ljass]​
[ljass] local integer b = 0[/ljass]​

[ljass] if eid >= 0 and eid <= 1 or eid >= 256 and eid <= 259 then[/ljass]​
[ljass] call TriggerRegisterGameEvent(t, eid2ge(e))[/ljass]​

[ljass] elseif eid == 2 then[/ljass]​
[ljass] call TriggerRegisterVariableEvent(t, s, h2lop(o1), r)[/ljass]​
[ljass] elseif eid == 3 then[/ljass]​
[ljass] call TriggerRegisterGameStateEvent(t, h2gs(o1), h2lop(o2), r)[/ljass]​
[ljass] elseif eid == 4 then[/ljass]​
[ljass] call TriggerRegisterTimerExpireEvent(t, h2timer(o1))[/ljass]​
[ljass] elseif eid == 5 then[/ljass]​
[ljass] call TriggerRegisterEnterRegion(t, h2region(o1), h2boolexpr(o2))[/ljass]​
[ljass] elseif eid == 6 then[/ljass]​
[ljass] call TriggerRegisterLeaveRegion(t, h2region(o1), h2boolexpr(o2))[/ljass]​
[ljass] elseif eid == 7 then[/ljass]​
[ljass] call TriggerRegisterTrackableHitEvent(t, h2trackable(o1))[/ljass]​
[ljass] elseif eid == 8 then[/ljass]​
[ljass] call TriggerRegisterTrackableTrackEvent(t, h2trackable(o1))[/ljass]​
[ljass] elseif eid >= 9 and eid <= 10 then[/ljass]​
[ljass] call TriggerRegisterGameEvent(t, eid2ge(e))[/ljass]​

[ljass] elseif eid == 11 then[/ljass]​
[ljass] call TriggerRegisterPlayerStateEvent(t, h2player(o1), h2ps(o2), h2lop(o3), r)[/ljass]​

[ljass] elseif eid >= 12 and eid <= 15 or eid >= 261 and eid <= 268 then[/ljass]​
[ljass] call TriggerRegisterPlayerEvent(t, h2player(o1), eid2pe(e))[/ljass]​
[ljass] //elseif eid == 16 then[/ljass]​
[ljass] // call TriggerRegisterPlayerChatEvent(t, o1, s, b)[/ljass]​
[ljass] elseif eid == 17 then[/ljass]​
[ljass] call TriggerRegisterPlayerEvent(t, h2player(o1), eid2pe(e))[/ljass]​
[ljass] elseif eid >= 18 and eid <= 51 or eid >= 269 and eid <= 277 then[/ljass]​

[ljass] loop [/ljass]​
[ljass] exitwhen i >= StringLength(s)[/ljass]​

[ljass] set ch = SubString(s, i, i + 1)[/ljass]​
[ljass] if SubString(s, i + 1, i + 2) != "-" then[/ljass]​
[ljass] call TriggerRegisterPlayerUnitEvent(t, Player(hex_digit_to_integer(ch)), eid2pue(e), h2boolexpr(o1))[/ljass]​
[ljass] else[/ljass]​
[ljass] set a = hex_digit_to_integer(ch)[/ljass]​
[ljass] set b = hex_digit_to_integer(SubString(s, i + 2, i + 3)) [/ljass]​

[ljass] loop[/ljass]​
[ljass] exitwhen a > b[/ljass]​
[ljass] call TriggerRegisterPlayerUnitEvent(t, Player(a), eid2pue(e), h2boolexpr(o1))[/ljass]​
[ljass] set a = a + 1[/ljass]​
[ljass] endloop[/ljass]​
[ljass] set i = i + 2[/ljass]​
[ljass] endif[/ljass]​

[ljass] set i = i + 1[/ljass]​
[ljass] endloop[/ljass]​

[ljass] elseif eid >= 52 and eid <= 58 or eid >= 286 and eid <= 294 then[/ljass]​
[ljass] call TriggerRegisterUnitEvent(t, h2unit(o1), eid2ue(e))[/ljass]​
[ljass] elseif eid == 59 then[/ljass]​
[ljass] call TriggerRegisterUnitStateEvent(t, h2unit(o1), h2us(o2), h2lop(o3), r)[/ljass]​
[ljass] elseif eid >= 60 and eid <= 88 then[/ljass]​
[ljass] call TriggerRegisterUnitEvent(t, h2unit(o1), eid2ue(e))[/ljass]​
[ljass] elseif eid == 89 then[/ljass]​
[ljass] call TriggerRegisterDeathEvent(t, h2widget(o1))[/ljass]​
[ljass] elseif eid == 90 then[/ljass]​
[ljass] call TriggerRegisterDialogEvent(t, h2dialog(o1))[/ljass]​
[ljass] elseif eid == 91 then[/ljass]​
[ljass] call TriggerRegisterDialogButtonEvent(t, h2dialogbutton(o1))[/ljass]​
[ljass] endif[/ljass]​


[ljass] if condition != null then[/ljass]​
[ljass] call TriggerAddCondition(t, Condition(condition))[/ljass]​
[ljass] endif[/ljass]​
[ljass] if action != null then[/ljass]​
[ljass] call TriggerAddAction(t, action)[/ljass]​
[ljass] endif[/ljass]​

[ljass] return t[/ljass]​
[ljass]endfunction[/ljass]


Unfortunately there is one BIG caveat, it's return bug dependent due to type casting and what this means is that it can't be used after patch 1.24+. Some of the type casting could be fixed with the fogstate trick but not all, so yeah it kinda sucks.




 

dudeim

New Member
Reaction score
22
Uhm if this is return bug depended how is this usefull in anyway? 99% of the people play at v 1.26x so people can't use this in their maps...
Also not sure but isn't GetHandleId the same as return bug only working? You could try using that instead.
 

luorax

Invasion in Duskwood
Reaction score
67
[ljass]GetHandleId()[/ljass] converts a handle to an integer, whilst we need to convert a handle to another handle type.
I guess this thread is supposed to be a discussion thread, so it's supposed to help OP to figure out a way to get this work (and to hear our opinion about it; is it worth to continue working on this or not)

Are you sure that the fogstate trick doesn't work? That's the only way to typecast that I can imagine.
 

PurgeandFire

zxcvmkgdfg
Reaction score
509
@OP: Check out kingking's Typecasting Library and Bribe's Handle library, and that will probably handle all the typecasting you need to do. (it only excludes terraindeformation and like some other handle iirc)
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Well this is now 1.24+ compatable. It's really neat how this inheritance​
thing works. The trick was to just use the Convert<...> functions =)​
[really simple, but I thought about it late].​


JASS:

// some boilerplate that the type casting requires =)
globals
    hashtable DUMMY = InitHashtable()
endglobals

function h2player takes handle h returns player
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadPlayerHandle(DUMMY, 0, 0)
endfunction

function h2unit takes handle h returns unit
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadUnitHandle(DUMMY, 0, 0)
endfunction

function h2widget takes handle h returns widget
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadWidgetHandle(DUMMY, 0, 0)
endfunction

function h2timer takes handle h returns timer
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadTimerHandle(DUMMY, 0, 0)
endfunction

function h2boolexpr takes handle h returns boolexpr
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadBooleanExprHandle(DUMMY, 0, 0)
endfunction

function h2region takes handle h returns region
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadRegionHandle(DUMMY, 0, 0)
endfunction

function h2trackable takes handle h returns trackable
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadTrackableHandle(DUMMY, 0, 0)
endfunction

function h2dialog takes handle h returns dialog
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadDialogHandle(DUMMY, 0, 0)
endfunction

function h2dialogbutton takes handle h returns button
    call SaveFogStateHandle(DUMMY, 0, 0, ConvertFogState(GetHandleId(h)))
    return LoadButtonHandle(DUMMY, 0, 0)
endfunction

function hex_digit_to_integer takes string hd returns integer
    local integer result = 0

    set hd = StringCase(hd, true)
    if &quot;0&quot; == hd then
        set result = 0
    elseif &quot;1&quot; == hd then
        set result = 1
    elseif &quot;2&quot; == hd then
        set result = 2
    elseif &quot;3&quot; == hd then
        set result = 3
    elseif &quot;4&quot; == hd then
        set result = 4
    elseif &quot;5&quot; == hd then
        set result = 5
    elseif &quot;6&quot; == hd then
        set result = 6
    elseif &quot;7&quot; == hd then
        set result = 7
    elseif &quot;8&quot; == hd then
        set result = 8
    elseif &quot;9&quot; == hd then
        set result = 9
    elseif &quot;A&quot; == hd then
        set result = 10
    elseif &quot;B&quot; == hd then
        set result = 11
    elseif &quot;C&quot; == hd then
        set result = 12
    elseif &quot;D&quot; == hd then
        set result = 13
    elseif &quot;E&quot; == hd then
        set result = 14
    elseif &quot;F&quot; == hd then
        set result = 15
    endif

    return result
endfunction

function Reg takes eventid e, code condition, code action, handle o1, handle o2, handle o3, real r, string s returns trigger
    local trigger t    = CreateTrigger()
    local integer eid  = GetHandleId(e)
    local integer o1id = GetHandleId(o1)
    local integer o2id = GetHandleId(o2)
    local integer o3id = GetHandleId(o3)
    local integer i    = 0
    local string  ch   = &quot;&quot;
    local integer a    = 0   
    local integer b    = 0
    
    //              ROC            |             TFT
    if     eid &gt;= 0 and eid &lt;= 1  or eid &gt;= 256 and eid &lt;= 259 then
        call TriggerRegisterGameEvent(t, ConvertGameEvent(eid))

    elseif eid == 2 then
        call TriggerRegisterVariableEvent(t, s, ConvertLimitOp(o1id), r)
    elseif eid == 3 then

        if o1id &gt;= 0 and o1id &lt;= 1 then
            call TriggerRegisterGameStateEvent(t, ConvertIGameState(o1id), ConvertLimitOp(o2id), r)
        elseif o1id == 2 then
            call TriggerRegisterGameStateEvent(t, ConvertFGameState(o1id), ConvertLimitOp(o2id), r)
        endif

    elseif eid == 4 then
        call TriggerRegisterTimerExpireEvent(t, h2timer(o1))
    elseif eid == 5 then
        call TriggerRegisterEnterRegion(t, h2region(o1), h2boolexpr(o2))
    elseif eid == 6 then
        call TriggerRegisterLeaveRegion(t, h2region(o1), h2boolexpr(o2))
    elseif eid == 7 then
        call TriggerRegisterTrackableHitEvent(t, h2trackable(o1))
    elseif eid == 8 then
        call TriggerRegisterTrackableTrackEvent(t, h2trackable(o1))
    elseif eid &gt;= 9 and eid &lt;= 10 then
        call TriggerRegisterGameEvent(t, ConvertGameEvent(eid))

    elseif eid == 11 then
        call TriggerRegisterPlayerStateEvent(t, h2player(o1), ConvertPlayerState(o2id), ConvertLimitOp(o3id), r)

    elseif eid &gt;= 12 and eid &lt;= 15 or eid &gt;= 261 and eid &lt;= 268 then
        call TriggerRegisterPlayerEvent(t, h2player(o1), ConvertPlayerEvent(eid))
    //elseif eid == 16 then
    //    call TriggerRegisterPlayerChatEvent(t, h2player(o1), s, b)
    elseif eid == 17 then
        call TriggerRegisterPlayerEvent(t, h2player(o1), ConvertPlayerEvent(eid))
    elseif eid &gt;= 18 and eid &lt;= 51 or eid &gt;= 269 and eid &lt;= 277 then
        
        loop 
            exitwhen i &gt;= StringLength(s)
            
            set ch = SubString(s, i, i + 1)
            if SubString(s, i + 1, i + 2) != &quot;-&quot; then
                call TriggerRegisterPlayerUnitEvent(t, Player(hex_digit_to_integer(ch)), ConvertPlayerUnitEvent(eid), h2boolexpr(o1))
            else
                set a = hex_digit_to_integer(ch)
                set b = hex_digit_to_integer(SubString(s, i + 2, i + 3)) 

                loop
                    exitwhen a &gt; b
                    call TriggerRegisterPlayerUnitEvent(t, Player(a), ConvertPlayerUnitEvent(eid), h2boolexpr(o1))
                    set a = a + 1
                endloop
                set i = i + 2
            endif
        
            set i = i + 1
        endloop

    //              ROC            |             TFT
    elseif eid &gt;= 52 and eid &lt;= 58 or eid &gt;= 286 and eid &lt;= 294 then
        call TriggerRegisterUnitEvent(t, h2unit(o1), ConvertUnitEvent(eid))
    elseif eid == 59 then
        call TriggerRegisterUnitStateEvent(t, h2unit(o1), ConvertUnitState(o2id), ConvertLimitOp(o3id), r)
    elseif eid &gt;= 60 and eid &lt;= 88 then
        call TriggerRegisterUnitEvent(t, h2unit(o1), ConvertUnitEvent(eid))
    elseif eid == 89 then
        call TriggerRegisterDeathEvent(t, h2widget(o1))
    elseif eid == 90 then
        call TriggerRegisterDialogEvent(t, h2dialog(o1))
    elseif eid == 91 then
        call TriggerRegisterDialogButtonEvent(t, h2dialogbutton(o1))
    endif
    
    
    if condition != null then
        call TriggerAddCondition(t, Condition(condition))
    endif
    if action != null then
        call TriggerAddAction(t, action)
    endif

    return t
endfunction

[ljass] I think there should be no bugs, but if someone finds any, then just leave[/ljass]​
[ljass] a reply.[/ljass]​

[ljass] Examples of using the Reg[ister] function:[/ljass]​

JASS:



        Reg(EVENT_PLAYER_END_CINEMATIC, null, function test, Player(0), null, null, 0, &quot;&quot;)
        Reg(EVENT_PLAYER_ARROW_DOWN_DOWN, null, function test, Player(0), null, null, 0, &quot;&quot;)
        Reg(EVENT_PLAYER_UNIT_DEATH, null, function test, null, null, null, 0, &quot;01&quot;)
        Reg(EVENT_GAME_STATE_LIMIT, null, function test, GAME_STATE_DIVINE_INTERVENTION, EQUAL, null, 0x666, &quot;&quot;)
        Reg(EVENT_GAME_STATE_LIMIT, null, function test2, GAME_STATE_TIME_OF_DAY, EQUAL, null, 0.5, &quot;&quot;)
        Reg(EVENT_GAME_ENTER_REGION, null, function test2, gg_rct_Region_000, null, null, 0, &quot;&quot;)
 

Jedi

New Member
Reaction score
63
That is just horrible(more horrible than Captain griffin's LoopHelper), it has too much parameters that you need to remember - won't need and do lots of checks.Divide and conquer is your best friend while coding.
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62
Jedi: Divide and conquer is your best friend while coding.
A: I don't understand. What do You mean by that?

Jedi: That is just horrible(more horrible than Captain griffin's LoopHelper).
A: I really don't know how one can compare scripts that do different things.
If you don't like it then just say I don't like it but don't make meaningless statements like "This/That is <...>".

Jedi: it has to much parameters that you need to remember.
A: Well the first 3 parameters are "conventional", the 1st: event, 2nd: condition and the 3rd: action.
So if you leave them you end up with 5 which is reasonable I think.
 

Dirac

22710180
Reaction score
147
what's with the awful font

IMO there's always a way to avoid handle2X when coding, why is this necessary?
 

Sgqvur

FullOfUltimateTruthsAndEt ernalPrinciples, i.e shi
Reaction score
62




Update:

All natives are now supported (including TriggerRegisterPlayerChatEvent).
Now all the events that require a player handle (playerevent, playerunitevent, the player chat event) use the "[0-9A-B]" format (the s1 parameter).

The new signature of the Reg function is:

[ljass]function Reg takes eventid e, code condition, code action, handle o1, handle o2, string s, string s2, real r returns trigger[/ljass]

The parameters have changed:
- a new string s2 parameter was added to replace the old handle o3 parameter because it was used just for limitop(s)
- s2 is now in it's place with the comparison operators (">", "!=", "==", etc.)e
- the real parameter r is also used now with the EVENT_PLAYER_CHAT and it values determines if the string needs to be exact match (r = 1) or not (r = 0 [or any other value but 1])

JASS:
function Reg takes eventid e, code condition, code action, handle o1, handle o2, string s, string s2, real r returns trigger
    local trigger t           = CreateTrigger()
    local integer eid         = H2I(e)
    local integer o1id        = H2I(o1)
    local integer o2id        = H2I(o2)
    local integer i           = 0
    local string  ch          = &quot;&quot;
    local integer a           = 0   
    local integer b           = 0
    local limitop lop         = null
    local boolean exact_match = false

    if     &quot;&lt;&quot;  == s2 then
        lop = LESS_THAN
    elseif &quot;&lt;=&quot; == s2 then
        lop = LESS_THAN_OR_EQUAL
    elseif &quot;==&quot; == s2 then
        lop = EQUAL
    elseif &quot;&gt;=&quot; == s2 then
        lop = GREATER_THAN_OR_EQUAL
    elseif &quot;&gt;&quot;  == s2 then
        lop = GREATER_THAN
    elseif &quot;!=&quot; == s2 then
        lop = NOT_EQUAL
    endif

    if  r == 1.0 then
        exact_match = true
    else // if r == 0 then
        exact_match = false
    endif
    
    //              ROC            |            TFT
    if     eid &gt;= 0 and eid &lt;= 1  or eid &gt;= 256 and eid &lt;= 259 then
        call TriggerRegisterGameEvent(t, ConvertGameEvent(eid))

    elseif eid == 2 then
        call TriggerRegisterVariableEvent(t, s, lop, r)
    elseif eid == 3 then

        if o1id &gt;= 0 and o1id &lt;= 1 then
            call TriggerRegisterGameStateEvent(t, ConvertIGameState(o1id), lop, r)
        elseif o1id == 2 then
            call TriggerRegisterGameStateEvent(t, ConvertFGameState(o1id), lop, r)
        endif

    elseif eid == 4 then
        call TriggerRegisterTimerExpireEvent(t, h2timer(o1))
    elseif eid == 5 then
        call TriggerRegisterEnterRegion(t, h2region(o1), h2boolexpr(o2))
    elseif eid == 6 then
        call TriggerRegisterLeaveRegion(t, h2region(o1), h2boolexpr(o2))
    elseif eid == 7 then
        call TriggerRegisterTrackableHitEvent(t, h2trackable(o1))
    elseif eid == 8 then
        call TriggerRegisterTrackableTrackEvent(t, h2trackable(o1))
    elseif eid &gt;= 9 and eid &lt;= 10 then
        call TriggerRegisterGameEvent(t, ConvertGameEvent(eid))

    elseif eid == 11 then

        loop 
            exitwhen i &gt;= StringLength(s)
            
            set ch = SubString(s, i, i + 1)
            if SubString(s, i + 1, i + 2) != &quot;-&quot; then
                call TriggerRegisterPlayerStateEvent(t, Player(hex(ch)), ConvertPlayerState(o1id), lop, r)
            else
                set a = hex(ch)
                set b = hex(SubString(s, i + 2, i + 3)) 

                loop
                    exitwhen a &gt; b
                    call TriggerRegisterPlayerStateEvent(t, Player(a), ConvertPlayerState(o1id), lop, r)
                    set a = a + 1
                endloop
                set i = i + 2
            endif
        
            set i = i + 1
        endloop

    elseif eid &gt;= 12 and eid != 16 and eid &lt;= 17 or eid &gt;= 261 and eid &lt;= 268 then

        loop 
            exitwhen i &gt;= StringLength(s)
            
            set ch = SubString(s, i, i + 1)
            if SubString(s, i + 1, i + 2) != &quot;-&quot; then
                call TriggerRegisterPlayerEvent(t, Player(hex(ch)), ConvertPlayerEvent(eid))
            else
                set a = hex(ch)
                set b = hex(SubString(s, i + 2, i + 3)) 

                loop
                    exitwhen a &gt; b
                    call TriggerRegisterPlayerEvent(t, Player(a), ConvertPlayerEvent(eid))
                    set a = a + 1
                endloop
                set i = i + 2
            endif
        
            set i = i + 1
        endloop

    elseif eid == 16 then

        loop 
            exitwhen i &gt;= StringLength(s)
            
            set ch = SubString(s, i, i + 1)
            if SubString(s, i + 1, i + 2) != &quot;-&quot; then
                call TriggerRegisterPlayerChatEvent(t, Player(hex(ch)), s, exact_match)
            else
                set a = hex(ch)
                set b = hex(SubString(s, i + 2, i + 3)) 

                loop
                    exitwhen a &gt; b
                    call TriggerRegisterPlayerChatEvent(t, Player(a), s, exact_match)
                    set a = a + 1
                endloop
                set i = i + 2
            endif
        
            set i = i + 1
        endloop

    elseif eid &gt;= 18 and eid &lt;= 51 or eid &gt;= 269 and eid &lt;= 277 then
        
        loop 
            exitwhen i &gt;= StringLength(s)
            
            set ch = SubString(s, i, i + 1)
            if SubString(s, i + 1, i + 2) != &quot;-&quot; then
                call TriggerRegisterPlayerUnitEvent(t, Player(hex(ch)), ConvertPlayerUnitEvent(eid), h2boolexpr(o1))
            else
                set a = hex(ch)
                set b = hex(SubString(s, i + 2, i + 3)) 

                loop
                    exitwhen a &gt; b
                    call TriggerRegisterPlayerUnitEvent(t, Player(a), ConvertPlayerUnitEvent(eid), h2boolexpr(o1))
                    set a = a + 1
                endloop
                set i = i + 2
            endif
        
            set i = i + 1
        endloop

    //               ROC            |            TFT
    elseif eid &gt;= 52 and eid &lt;= 58 or eid &gt;= 286 and eid &lt;= 294 then
        call TriggerRegisterUnitEvent(t, h2unit(o1), ConvertUnitEvent(eid))
    elseif eid == 59 then
        call TriggerRegisterUnitStateEvent(t, h2unit(o1), ConvertUnitState(o2id), lop, r)    
    elseif eid &gt;= 60 and eid &lt;= 88 then
        call TriggerRegisterUnitEvent(t, h2unit(o1), ConvertUnitEvent(eid))
    elseif eid == 89 then
        call TriggerRegisterDeathEvent(t, h2widget(o1))
    elseif eid == 90 then
        call TriggerRegisterDialogEvent(t, h2dialog(o1))
    elseif eid == 91 then
        call TriggerRegisterDialogButtonEvent(t, h2dialogbutton(o1))
    endif
    
    
    if condition != null then
        call TriggerAddCondition(t, Condition(condition))
    endif
    if action != null then
        call TriggerAddAction(t, action)
    endif

    return t
endfunction


Examples of using it (cond and act are predeclared functions [they can also be null of course]):

[ljass] Reg(EVENT_GAME_VICTORY, function cond, function act, null, null, "", "", 0)[/ljass]
[ljass] Reg(EVENT_GAME_VARIABLE_LIMIT, function cond, function act, null, null, "my_variable_of_type_real", ">=", 0xBADB007)[/ljass]
[ljass] Reg(EVENT_GAME_ENTER_REGION, function cond, function act, gg_rct_Region_000, Filter(function footies_only), "", "", 0)[/ljass]
[ljass] Reg(EVENT_GAME_TRACKABLE_HIT, function cond, function act, my_trackable, null, "", "", 0)[/ljass]
[ljass] Reg(EVENT_PLAYER_STATE_LIMIT, function cond, function act, PLAYER_STATE_RESOURCE_GOLD, null, "01", ">", 0xDEADFA11)[/ljass]
[ljass] Reg(EVENT_PLAYER_LEAVE, function cond, function act, null, null, "0-B", "", 0)[/ljass]
[ljass] Reg(EVENT_PLAYER_CHAT, function cond, function act, null, null, "02468A", "-clear", 1)[/ljass]
[ljass] Reg(EVENT_PLAYER_ARROW_LEFT_UP, function cond, function act, null, null, "13579B", "", 0)[/ljass]
[ljass] Reg(EVENT_PLAYER_END_CINEMATIC, function cond, function act, null, null, "0", "", 0)[/ljass]
[ljass] Reg(EVENT_PLAYER_UNIT_SPELL_EFFECT, function cond, function act, null, null, "0-24-57-9", "", 0)[/ljass]
[ljass] Reg(EVENT_UNIT_STATE_LIMIT, function cond, function act, my_unit_var, UNIT_STATE_MAX_LIFE, "", "<", 0.406)[/ljass]
[ljass] Reg(EVENT_WIDGET_DEATH, function cond, function act, my_tree, null, "", "", 0)[/ljass]

 

Bribe

vJass errors are legion
Reaction score
67
The API looks worse than textmacro API, it adds a library requirement,
the most important thing you'd use something like this for would be for
is...

If you forget what the native name is. It's not a good resource for such
a silly thing. We all have API browsers at this point in at least one form
or another.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top