Returns a table containing subtables which contain all hooks.
This code removes all hooks which have their function defined in the current file.
If you wish to cleanup previously defined hooks automatically when using Lua refresh, place it at the top of your file. It will save you from reloading the map or removing those hooks manually.
Be aware that it cleans up by testing the location where hook functions are defined, not where hooks were added!
-- Cleanup hooks that were previously defined in this file. local source = debug.getinfo( 1, "S" ).source for EventName,EventHooks in pairs( hook.GetTable() ) do for HookName,HookFunction in pairs( EventHooks ) do if debug.getinfo( HookFunction, "S" ).source == source then hook.Remove( EventName, HookName ) end end end