ConVar Query

ConVar Query v1.1

9/30/13 - Update to v1.1

  • Removed dependency on signatures
  • Should work on linux if someone wants to compile it
  • If a query times out, it now frees the reference to the function
  • When a map ends all the references are deleted
  • Added more type checks

I decided to take on the task of adding the StartQueryCvarValue to lua since I couldn’t find any working modules that did just that.
It’s easy to use, but because of how StartQueryCvarValue works it’s not an ordinary module. It’s a server plugin so you must place the binary and the vdf in your addons folder and it will automatically load.

This binary is useful because it does not depend on client side lua. This is mainly for anti-cheats, but maybe you could find other uses for it.

Extract both the convar_query.dll and convar_query.vdf to your garrysmod/addons folder


--Passes the value of the cvar or the error as the only paramater in the callback
--Returns true on a successful query and false otherwise
player:QueryConVar( cvar name <string>, callback <function> )

--Would print "The value of the convar is 0" if sv_cheats is 0 on the client
player.GetByID(1):QueryConVar( "sv_cheats", function( value ) print( "The value of the convar is "..value ) end )

local convars = { ["sv_cheats"] = "0", ["host_timescale"] = "1", ["sv_allowcslua"] = "0" };

for _, ply in pairs( player.GetAll() ) do
	for convar, def_value in pairs( convars ) do
		ply:QueryConVar( convar, function( value )
			if ( value != def_value ) then
				if (IsValid( ply )) then
					ply:Ban( 1337, "Convar "..convar.." did not match." );
		end )

Error numbers:
If the query goes through but cannot get the value of the convar, then it will pass an error number instead of the convar value.
The error numbers are as follows:

1: The convar was not found.
2: There's a ConCommand, but it's not a ConVar.
3: The cvar was marked with FCVAR_SERVER_CAN_NOT_QUERY, so the server is not allowed to have its value.

Source code


it doesnt work

[editline]6th October 2017[/editline]

i put the vdf and dll in garrysmod/addons but nothing happens and code errors saying method QueryConVar is nil??

(User was banned for this post ("Bump" - Craptasket))