Cvar3

CodeGS posted a link to cvar3 in another thread which I have been looking for the server sided version as well as the code for ages. So big thanks to him.

I’ve been unable to find any documentation on cvar3, but I’m still able to figure out 90% of everything from the code. With that said, I’ve run into two problems.

#1
I’m trying to loop through all cvars and remove flags from them like so:



		require("cvar3")
		
		local dbg = debug.getregistry()
		
		for k, v in pairs(cvars.GetAllCommands()) do
			if dbg.ConVar.HasFlag(v, FCVAR_DEVELOPMENTONLY) then
				print("has flag")
				dbg.ConVar.SetFlags(v, dbg.ConVar.GetFlags(v) - FCVAR_DEVELOPMENTONLY)
				
				print(v:GetName())
			end
		end	


That outputs this error:



[ERROR] gamemodes/flood/gamemode/init.lua:308: bad argument #2 to 'HasFlag' (convar expected, got number)
  1. HasFlag - [C]:-1
   2. unknown - gamemodes/flood/gamemode/init.lua:308
    3. unknown - lua/includes/modules/concommand.lua:54


I tried changing



if dbg.ConVar.HasFlag(v, FCVAR_DEVELOPMENTONLY) then


to



if dbg.ConVar.HasFlag(GetConVar(v:GetName()), FCVAR_DEVELOPMENTONLY) then


However it still spits out the same error.

#2
Both of these output no errors and do nothing.



print(dbg.Player.GetUserSetting(Entity(1), "voice_enable"))
dbg.Player.ExecuteCommandOnClient(Entity(1), "print_colorcorrection")


Repository I’m using.

#1: GetAllCommands returns the a table of strings; GetAllConVars will return the convar objects usable for HasFlag.

#2: I believe it will not work for blocked convars, but I could be wrong. Your setup looks right – make sure you’re not running it too early to where Entity(1) would be NULL.