WoW Event Prevent Default

Is there a way to do a Prevent Default in WoW Lua?

For example:

local frame_TIME_PLAYED_MSG = CreateFrame("Frame");
frame_PLAYER_LOGIN:RegisterEvent("TIME_PLAYED_MSG");
frame_PLAYER_LOGIN:SetScript("OnEvent", function(self, event)
    print(event);
    self.preventDefault(); -- I want to do this, but what is it in Lua?
end);

Reason → I want to place on my custom experience bar something such as:

Time played this level: 0 days 1 hour 23 minutes 45 seconds

Without it showing a system message in chat:

Time played: 0 days 1 hour 23 minutes 45 seconds
Time played this level: 0 days 1 hour 23 minutes 45 seconds

local f = CreateFrame("Frame", "AkormTimePLayed", UIParent)
f:SetSize(10, 10)
f:SetPoint("TOP", 0, -5)
f.TimePlayed = f:CreateFontString()
f.TimePlayed:SetFontObject(GameFontNormal)
f.TimePlayed:SetPoint("CENTER")

f:RegisterEvent("TIME_PLAYED_MSG")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event, ...)
    if event == "PLAYER_ENTERING_WORLD" then
    	RequestTimePlayed()
    	return
    end
    local totalPlayed, timePlayedThisLevel = ...
    local d, h, m, s = ChatFrame_TimeBreakDown(timePlayedThisLevel)
    self.TimePlayed:SetText(format(TIME_PLAYED_LEVEL, format(TIME_DAYHOURMINUTESECOND, d, h, m, s)))
end)

Format the message however you like, this was just easy.

Yes, but that still shows the system message in chat that is the purpose of this thread to not show, but I don’t want to hide all system messages.

Sorry, misunderstood the question.

Before the code I posted add:

for i=1, NUM_CHAT_WINDOWS do
	_G["ChatFrame"..i]:UnregisterEvent("TIME_PLAYED_MSG")
end
local m=ChatTypeGroup["SYSTEM"]
for i, v in ipairs(m) do
	if v == "TIME_PLAYED_MSG" then
		m[i] = nil
		break
	end
end
1 Like

Oh wow, I wouldn’t of been able to arrive at that. I thought maybe it was a word or two in the event. I was way off. Thanks!

ChatFrame.lua gathers messages into groups. This just removes the time message from the SYSTEM group.