getEventHandlers
Client-side
Server-side
Shared
Manual Review Required
Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.
This function gets the attached functions from the event and attached element from current lua script.
Syntax
table getEventHandlers ( string eventName, element attachedTo )Required Arguments
- eventName: The name of the event. For example ( "onPlayerWasted" ).
- attachedTo: The element attached to.
Returns
- table: value
Returns table with attached functions, empty table otherwise.
Code Examples
shared
function isEventHandlerAdded( sEventName, pElementAttachedTo, func ) if type( sEventName ) == 'string' and isElement( pElementAttachedTo ) and type( func ) == 'function' then local aAttachedFunctions = getEventHandlers( sEventName, pElementAttachedTo ) if type( aAttachedFunctions ) == 'table' and #aAttachedFunctions > 0 then for i, v in ipairs( aAttachedFunctions ) do if v == func then return true end end end end return falseend
function onPlayerWasted() outputChatBox( getPlayerName( source ) .. ' died.' )endaddEventHandler( 'onPlayerWasted', root, onPlayerWasted )
addCommandHandler( 'removeOnPlayerWastedEvent', function() if isEventHandlerAdded( 'onPlayerWasted', root, onPlayerWasted ) then outputChatBox( 'onPlayerWasted succesfully removed!' ) removeEventHandler( 'onPlayerWasted', root, onPlayerWasted ) endend)