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.