At the most basic, the following allows you to monitor specific events and handle what to do when they trigger. This code in a lua file and the addon's toc file will be a simple addon.
Just replace < EVENT # > tags with a particular event name and add the appropriate code. For example I am just printing the event name and it's arguments. Just add a new else if section for each new event you want to watch and react to.
But, like SDPhantom said, there are restrictions to what you are allowed to do.
Lua Code:
local eventWatcher = CreateFrame("Frame")
local function OnEvent(self,event,...)
local args = { ... }
if event == "< EVENT 1 >" then
-- What to do if this event triggers
print(event,...)
elseif event == "< EVENT 2 >" then
-- What to do if this event triggers
print(event,...)
end
end
eventWatcher:SetScript( "OnEvent", OnEvent );
eventWatcher:RegisterEvent( " < EVENT 1 >" );
eventWatcher:RegisterEvent( " < EVENT 2 >" );