How to run commands on login?

I’d like to run these commands on login, but not sure how to do it. I also have WeakAuras and can use the event trigger PLAYER_ENTERING_WORLD. But by no means am I an expert in coding.

I need to run:

/console GamePadEnable 0
/console GamePadEnable 1

I don’t use WA, but a regular addon approach is something like:

local f = CreateFrame("Frame")
f:SetScript("OnEvent",function(self,event,...)
  -- stuff to run on login goes here
  C_CVar.SetCVar("GamePadEnable",0)
  C_CVar.SetCVar("GamePadEnable",1)
end)
f:RegisterEvent("PLAYER_LOGIN")

Copy and paste that into https://addon.bool.no/ to turn it into an addon.

PLAYER_ENTERING_WORLD fires every time you get a loading screen. PLAYER_LOGIN first just once during the first loading screen.

Macro commands that have /anything are generally not usable as addon/lua code. Anything /script or /run macro command is fair game after the /script or /run.

3 Likes