Sorry in advance if I’ve missed something phenomenally easy, but I cannot, for the life of me, figure out why the following serverside cvar callback is not being called.
( I’m only looking to add a callback to this convar, so that when an admin alters the ttt round limit post-init, the remaining rounds are reset to match - mostly to be used for extending a map for dev reasons or per player request )
CreateConVar( "ttt_round_limit", "6", FCVAR_ARCHIVE + FCVAR_NOTIFY + FCVAR_REPLICATED + FCVAR_GAMEDLL ) local function TTTRoundLimitUpdate( cvar, old, new ) MsgC( Color( 0, 160, 160 ), "TTT Round Limit Changed! " ) new = fnum( new ) or 10 print( "[ New round limit ]: ", new ) SetGlobalInt( "ttt_rounds_left", new ) end cvars.AddChangeCallback( "ttt_round_limit", TTTRoundLimitUpdate, "update_remaining_rounds" )
( note: fnum() is a slightly modified tonumber() )
I tried to find answers myself, but couldn’t find much on the subject except for an excerpt from the outdated wiki at maurits;
“For this to work for ConVars on the server, the ConVar must be created with the FCVAR_GAMEDLL flag.”
Unfortunately, the above quoted statement is incorrect or otherwise did not solve the issue I’m having.
Plus the current official wiki states that the FCVAR_GAMEDLL flag, is set automatically anyway.
Other troubleshooting steps performed:
- Modified original cvar to manually include FCVAR_GAMEDLL, created convar callback on next line, in “lua/gamemodes/terrortown/gamemode/init.lua” ( problem persisted, steps reverted )
- Recreated cvar in “PostGamemodeLoaded” hook, created convar callback on next line( problem persisted, steps still in place, presented in code snippet above )
For anyone who may have assistance to offer, assume that I know enough of the basics to skip the “Did you plug it in?” part of the troubleshooting, it’ll save us both some time.
Any help is much appreciated though, feeling pretty silly for being stumped by this. :hurr:
PS: I am aware that I could achieve the desired result using the think hook and some basic caching/crosschecking, but I would very much love some help with this issue, so I can avoid using the caching method every time I want to do something similar to this.