garry's mod Create ConVAR

I want to do a CVAR that executes a command like: tv_enable 0 or 1

I need help, i tested it but ist’nt working…

CreateClientConVar( "examplecommand_tv", "0", true, false ) then
	RunConsoleCommand("tv_enable", "0");
        RunConsoleCommand("tv_enable", "1");


CreateClientConVar( "examplecommand_tv", "0", true, false, tv_enable )

Also, where i put it? Like:
in lua\autorun\server\serverside.lua
in lua\autorun\client\clientside.lua


Can you outline what you’re trying to do in words? Your code is unclear.

cvars.AddChangeCallback(“examplecommand_tv”, function(examplecommand_tv, oldvalue, newvalue) end)

judging by you calling CreateClientConVar you should put it clientside.

CreateConvar("examplecommand", "0", true, false") then
     cvars.AddChangeCallback( "examplecommand", function( tv_enable, 0, 1 )
	print( examplecommand is set to new_var )
end )

That still isn’t syntactically correct – you can only use “then” after an if-statement, but conditional logic isn’t needed here. You would just create the ConVar, then add the callback. Also, for the arguments of cvars.AddChangeCallback, they need to be defined as variables and not explicit values like so:

cvars.AddChangeCallback("examplecommand", function(name, oldval, newval)
   -- code

RunConsoleCommand only accepts strings, so you would want to do RunConsoleCommand(“somecommand”, newval). Also, if you’re just going to change another command from your custom command, why not just change the original command and avoid the mess?

I want to make a ConVar, that changes to 0 or 1 the command that i choose, for example: sv_cheats

Why not just change sv_cheats instead of trying to make another convar update it?

That won’t work if you’re trying to go client -> server.

If you are trying to do this on the client to the server you’ll need to create a concommand that verifies you have authorization to make the change. Although if it is your own server why not just change it through RCon?

If it’s not your server then you’re out of luck.