addDebugHook | Multi Theft Auto: Wiki Skip to content

addDebugHook

Client-side
Server-side
Shared
Needs checking

This function was partially migrated from the old wiki. Please review manually:

  • Missing section: Callback parameters

Manual Review Required

Please finish this page using the corresponding Old Wiki article. Go to Contribution guidelines for more information.


This function allows tracing of MTA functions and events. It should only be used when debugging scripts as it may degrade script performance.

Syntax

bool addDebugHook ( string hookType, function callbackFunction, table nameList )
Required Arguments
  • hookType: The type of hook to add. This can be: preEvent postEvent preFunction postFunction preEventFunction postEventFunction
  • callbackFunction: The function to call Returning the string "skip" from the callback function will cause the original function/event to be skipped
  • nameList: Table of strings for restricting which functions and events the hook will be triggered on addDebugHook and removeDebugHook will only be hooked if they are specified in the name list

Returns

  • bool: value

Returns true if the hook was successfully added, or false otherwise.

Code Examples

shared

This example will dump info about all triggered events:

function onPreEvent( sourceResource, eventName, eventSource, eventClient, luaFilename, luaLineNumber, ... )
local args = { ... }
local srctype = eventSource and getElementType(eventSource)
local resname = sourceResource and getResourceName(sourceResource)
local plrname = eventClient and getPlayerName(eventClient)
outputDebugString( "preEvent"
.. " " .. tostring(resname)
.. " " .. tostring(eventName)
.. " source:" .. tostring(srctype)
.. " player:" .. tostring(plrname)
.. " file:" .. tostring(luaFilename)
.. "(" .. tostring(luaLineNumber) .. ")"
.. " numArgs:" .. tostring(#args)
.. " arg1:" .. tostring(args[1])
)
end
addDebugHook( "preEvent", onPreEvent )