You can just pass a function
as a second argument to RegisterEvent:
Lua Code:
local doStuff = function(self, event, ...)
local servers = {
["Aggra(Português)"] = "Portuguese",
}
...
end
localeicon:RegisterEvent("PLAYER_ENTERING_WORLD", doStuff)
localeicon:RegisterEvent("PLAYER_TARGET_CHANGED", doStuff)
---
edit for verbosity:
Right now you're passing function that's supposed to be executed as a callback to SetScript:
Lua Code:
localeicon:RegisterEvent("PLAYER_ENTERING_WORLD")
localeicon:RegisterEvent("PLAYER_TARGET_CHANGED")
localeicon:SetScript("OnEvent", function(self, event, ...)
local servers = {
-- ...
}
if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
-- ...
end
end)
Since oUF rewrote the RegisterEvent function, this might not work out as planned. Instead, you can just define that function locally and pass it as a second argument to RegisterEvent() like I showed above:
Lua Code:
local setRealmIcon = function(self, event, ...)
local servers = {
-- ...
}
if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
-- ...
end
end
localeicon:RegisterEvent("PLAYER_ENTERING_WORLD", setRealmIcon)
localeicon:RegisterEvent("PLAYER_TARGET_CHANGED", setRealmIcon)