AddDebugHook: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "__NOTOC__ {{Server function}} {{New feature/item|3.0136|1.3|5939| This function allows tracing of MTA functions and events. It should only be used when debugging scripts as it ma...")
 
No edit summary
Line 50: Line 50:
addDebugHook( "preEvent", onPreEvent )
addDebugHook( "preEvent", onPreEvent )
</syntaxhighlight>
</syntaxhighlight>
==Requirements==
{{Requirements|1.3.4-9.05939|n/a}}


==See Also==
==See Also==
{{Utility functions}}
{{Utility functions}}

Revision as of 05:41, 24 November 2013

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 )

Required Arguments

  • hookType: The type of hook to add. This can be:
    • preEvent
    • postEvent
    • preFunction
    • postFunction
  • callbackFunction : The function to call

Returns

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

Callback parameters

pre/postEvent( resource sourceResource, string eventName, element eventSource, element eventClient, string luaFilename, int luaLineNumber, eventArguments )
pre/postFunction( resource sourceResource, string functionName, bool isAllowedByACL, string luaFilename, int luaLineNumber, functionArguments )

Example

This example will dump info about all triggered events:

function onPreEvent( sourceResource, eventName, eventSource, eventClient, luaFilename, luaLineNumber, ... )
    local args = { ... }
    local resname
    if sourceResource then
        resname = getResourceName(sourceResource)
    else
        resname = "unknown"
    end
    outputDebugString( "preEvent"
        .. " " .. tostring(resname)
        .. " " .. tostring(eventName)
        .. " source:" .. tostring(eventSource)
        .. " player:" .. tostring(eventClient)
        .. " file:" .. tostring(luaFilename)
        .. ":" .. tostring(luaLineNumber)
        .. " #args:" .. tostring(#args)
        .. " args[1]:" .. tostring(args[1])
        )
end
addDebugHook( "preEvent", onPreEvent )

Requirements

Minimum server version 1.3.4-9.05939
Minimum client version n/a

Note: Using this feature requires the resource to have the above minimum version declared in the meta.xml <min_mta_version> section. e.g. <min_mta_version server="1.3.4-9.05939" />

See Also