Need help to clear up my confusion about GMod's ConVars.

Hi folks!

I am currently working on my biggest project yet and I hope people will like it.
It is nearly finished though I am having trouble with GMod’s ConVar system.

An interesting thing to note here is that this addon will for now be exclusively for Trouble in Terrorist Town. I may consider adding support for other gamemodes if requests are numerous enough.

Here we go:



hook.Add("TTTBeginRound","pill_spawn",	function()
								InitializePillEffects()
							end
		)

-- In the function "InitializePillEffects()" I initialize, amongst alot of other stuff that's unrelated to my problem, alot of ConVars. Here's a snippet from this function:

function InitializePillEffects()

        local convar_flags = {FCVAR_REPLICATED, FCVAR_ARCHIVE}
	
	CreateConVar("pe_bad_trip","1",convar_flags)
	CreateConVar("pe_bad_trip_damage","20",convar_flags)

end


All of my ConVars are currently initialized this way.
During my testing, I have discovered that these variables don’t synchronize with the server, as in I have changed these around locally and on my local testing server and yet the values I have changed locally don’t get overridden by the server’s.

This is especially notable in this kind of situation:



CreateConVar("pe_invisibility_duration","30",convar_flags)

local invisibility_visuals = 	function()
				           if !timer.Exists(tostring(LocalPlayer()).."_invisibility_effect_catch") then -- this timer's delay is controlled by the ConVar "pe_invisibility_duration".
							hook.Remove("HUDPaint",tostring(LocalPlayer():Nick()).."_Invisibility_visuals")
					   end
						local tab = {
							 [ "$pp_colour_addr" ] = 0,
							 [ "$pp_colour_addg" ] = 0.08-(0.072*LocalPlayer():GetColor().a/127),
							 [ "$pp_colour_addb" ] = 0.08-(0.072*LocalPlayer():GetColor().a/127),
							 [ "$pp_colour_brightness" ] = -0.02+(0.018*LocalPlayer():GetColor().a/127),
							 [ "$pp_colour_contrast" ] = 1.25-(0.225*LocalPlayer():GetColor().a/127),
							 [ "$pp_colour_colour" ] = 0.25+(0.665*LocalPlayer():GetColor().a/127),
						         [ "$pp_colour_mulr" ] = 0,
							 [ "$pp_colour_mulg" ] = 0,
							 [ "$pp_colour_mulb" ] = 0
								} 
						if LocalPlayer():GetColor().a < 255 then
							DrawColorModify(tab)
						end
					end


On my client I experienced that the screen effect, which is drawn in the function above, lasts for the duration set on my client as opposed to the one set in the server’s ConVar.
This is where it gets awkward. I do look up most of the stuff I use in my code on the GMod Wiki, including the syntax for the ConVars and I have come up with this configuration:


 local convar_flags = {FCVAR_REPLICATED, FCVAR_ARCHIVE}

Which was supposed to get the ConVar stored in the server’s config (FCVAR_ARCHIVE) and also override the client’s one (FCVAR_REPLICATED).

Any thoughts about this?

Thanks for taking the time, have a great one.

I dont fully get what you want, do you want convars wich players can change ingame, but are serverside or…?

I don’t know if passing it a table works, if always bit.bor’d the values together. Try this


local convar_flags = bit.bor(FCVAR_REPLICATED, FCVAR_ARCHIVE)

Edit; I think I misread your misunderstood your issue but it wouldn’t hurt to try that anyway.

Also creating the the convars inside the hook is unnecessary, you can just create them once when the script runs, then if you want to override the value you could do that in the hook. In fact it might even be the issue since the convar possibly wouldn’t be created serverside until after the player has already joined so I’m not sure how that would go with synchronising the value.

Okay thank you, will try that as soon as I can get my hands back onto my project! I will update whether it worked or not.

I’ve always using FCVAR flags that way:


local cvar_flags = FCVAR_REPLICATED + FCVAR_ARCHIVE

May be this will be able to help you.