/************************************************************** * * RegisterPlayerUnitEvent * v5.1.0.1 * By Magtheridon96 * * I would like to give a special thanks to Bribe, azlier * and BBQ for improving this library. For modularity, it only * supports player unit events. * * Functions passed to RegisterPlayerUnitEvent must either * return a boolean (false) or nothing. (Which is a Pro) * * Warning: * -------- * * - Don't use TriggerSleepAction inside registered code. * - Don't destroy a trigger unless you really know what you're doing. * * API: * ---- * * - function RegisterPlayerUnitEvent takes playerunitevent whichEvent, code whichFunction returns nothing * - Registers code that will execute when an event fires. * - function RegisterPlayerUnitEventForPlayer takes playerunitevent whichEvent, code whichFunction, player whichPlayer returns nothing * - Registers code that will execute when an event fires for a certain player. * - function GetPlayerUnitEventTrigger takes playerunitevent whichEvent returns trigger * - Returns the trigger corresponding to ALL functions of a playerunitevent. * **************************************************************/ library RegisterPlayerUnitEvent // Special Thanks to Bribe and azlier trigger array t public function registerPlayerUnitEvent takes playerunitevent p, code c returns nothing integer i = GetHandleId(p) integer k = 15 if t[i] == null then t[i] = CreateTrigger() loop TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null) exitwhen k == 0 k-- end end TriggerAddCondition(t[i], Filter(c)) end function registerPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing integer i = 16 * GetHandleId(p) + GetPlayerId(pl) if t[i] == null then t[i] = CreateTrigger() TriggerRegisterPlayerUnitEvent(t[i], pl, p, null) end TriggerAddCondition(t[i], Filter(c)) end function getPlayerUnitEventTrigger takes playerunitevent p returns trigger return t[GetHandleId(p)] end endlibrary