Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Choose a unique identifier for your addon
- local MYADDON_NAME = "MyToggleAddon"
- -- Define the slash commands for your addon
- SLASH_MYTOGGLEADDON1 = "/mytoggle" -- This is the primary slash command.
- SLASH_MYTOGGLEADDON2 = "/mta" -- This is an alias (optional).
- -- Create a variable to store the toggle state (true for on, false for off)
- local isMyFunctionEnabled = false
- -- Function to be toggled
- local function MyToggledFunction()
- if isMyFunctionEnabled then
- print(MYADDON_NAME .. ": My toggled function is performing its action!")
- -- Put the actual code for your function here
- local EventLoggerFrame = CreateFrame("Frame", "EventLoggerFrame", UIParent);
- -- This function will be called every time an event fires
- local function EventLogger_OnEvent(self, event, ...)
- -- Get the additional arguments passed with the event
- local args = { ... };
- -- Construct a string to display in chat
- local message = "Event Fired: " .. event;
- if event ~= "UPDATE_UI_WIDGET" then
- -- Append the event arguments to the message (if any)
- if #args > 0 then
- for i, v in ipairs(args) do
- message = message .. ", arg" .. i .. ": " .. tostring(v);
- if isMyFunctionEnabled == true then
- print('|cff00b4ffArguments: '.. #args,'|r' .. message);
- end
- end
- end
- end
- end
- -- Print the message to the chat window
- -- Set the OnEvent script for our frame
- EventLoggerFrame:SetScript("OnEvent", EventLogger_OnEvent);
- -- Register our frame to listen for ALL events
- EventLoggerFrame:RegisterAllEvents();
- else
- print(MYADDON_NAME .. ": My toggled function is currently disabled.")
- end
- end
- -- Slash command handler function
- local function MyToggleAddon_HandleSlashCommand(msg, editBox)
- -- Toggle the state
- isMyFunctionEnabled = not isMyFunctionEnabled
- -- Inform the user of the new state
- if isMyFunctionEnabled then
- print(MYADDON_NAME .. ": My function is now enabled!")
- else
- print(MYADDON_NAME .. ": My function is now disabled.")
- end
- -- You can also call your toggled function here to see its effect
- MyToggledFunction()
- end
- -- Register the handler function with the slash command list
- SlashCmdList["MYTOGGLEADDON"] = MyToggleAddon_HandleSlashCommand
Advertisement
Add Comment
Please, Sign In to add comment