/console commands in addon

/console CameraDistanceMaxZoomFactor 4
/console ShowClassColorInNameplate 1

would like to know how to turn /console commands into something i can input into my addon like i can do with my /script commands, thanks

SetCVar("ShowClassColorInNameplate", 1)

For certain CVars like cameraDistanceMaxZoomFactor you need to set it in PLAYER_ENTERING_WORLD because the default UI sets them on that event

local function OnEvent(self, event)
	SetCVar("cameraDistanceMaxZoomFactor", 4)
end

local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", OnEvent)

it maxes out at 2.6

I suppose he is playing on Classic which effectively maxes out at 3.34 but allows up to 4

1 Like

Works like a charm. Thanks brother.

The earlier posts are totally correct, but I will add a nuance so you don’t encounter problems in the future.

On classic, SetCVar is absolutely correct.

On retail, SetCVar is depreciated since 8.1 and you should use C_CVar.SetCVar for future compatibility.

To workaround this, if you play both classic and retail, put the following line at the top of the file:

local SetCVar = SetCVar or C_CVar.SetCVar;