- Joined
- Dec 12, 2008
- Messages
- 7,379
This system was made to replace that cumbersome GTrigger by Jesus4Lyf.
Special thanks to Bribe, azlier and BBQ
Here's a vanilla Jass version:
Feel free to comment..
Special thanks to Bribe, azlier and BBQ
JASS:
/**************************************************************
*
* 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
globals
private trigger array t
endglobals
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if t[i] == null then
set t[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(t[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
local integer i = 16 * GetHandleId(p) + GetPlayerId(pl)
if t[i] == null then
set t[i] = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(t[i], pl, p, null)
endif
call TriggerAddCondition(t[i], Filter(c))
endfunction
function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
return t[GetHandleId(p)]
endfunction
endlibrary
Here's a vanilla Jass version:
JASS:
//**************************************************************
//*
//* RegisterPlayerUnitEvent (Vanilla Jass)
//* 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)
//*
//* Implementation:
//* ---------------
//*
//* - Copy all this script into a new trigger called "RegisterPlayerUnitEvent Jass"
//* - Create a trigger array variable called RPUE.
//* - Done.
//*
//* 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.
//*
//**************************************************************
function RegisterPlayerUnitEvent takes playerunitevent p, code c returns nothing
local integer i = GetHandleId(p)
local integer k = 15
if udg_RPUE[i] == null then
set udg_RPUE[i] = CreateTrigger()
loop
call TriggerRegisterPlayerUnitEvent(udg_RPUE[i], Player(k), p, null)
exitwhen k == 0
set k = k - 1
endloop
endif
call TriggerAddCondition(udg_RPUE[i], Filter(c))
endfunction
function RegisterPlayerUnitEventForPlayer takes playerunitevent p, code c, player pl returns nothing
local integer i = 16 * GetHandleId(p) + GetPlayerId(pl)
if udg_RPUE[i] == null then
set udg_RPUE[i] = CreateTrigger()
call TriggerRegisterPlayerUnitEvent(udg_RPUE[i], pl, p, null)
endif
call TriggerAddCondition(udg_RPUE[i], Filter(c))
endfunction
function GetPlayerUnitEventTrigger takes playerunitevent p returns trigger
return udg_RPUE[GetHandleId(p)]
endfunction
function InitTrig_RegisterPlayerUnitEvent_Jass takes nothing returns nothing
endfunction
Feel free to comment..
Last edited: