Creating a convar that changes part of a code

Hello. Question, in a gamemode, how would I create a console command that changes parts of a code? I’m trying to create a console command that would edit my GM:PlayerSpawn hook when enabled, and when disabled would run the hook but with different code. How would I do this?

Global.CreateConVar

Global.GetConVarNumber

Global.GetConVarString



local myConvar = CreateConVar() -- Actually give a name to your convar

if (myConvar:GetBool()) then
    -- myConvar is true
else
    -- myConvar is false
end


GetConVarNumber and GetConVarString (any method that fetches a convar by its name) is noticeably slow when used often, such as in an HUDPaint hook. You should really use _FR_Starfox4’s method (which is super super fast).

Yeah, I thought he was speaking about start up settings.

It’s just a pet peeve of mine because so many addons do it and it actually does have a notable framerate imapct.

Just searching on GitHub can lead to an example of it being used badly within seconds: https://github.com/crazyscouter/GMod-Addons/blob/779884d66fa9ce1527f439d2973da7c2d36d1042/PooPee(%20DarkRP%202.4.3%20)/gamemodes/darkrp/gamemode/modules/pooppee/cl_poopee.lua#L5.

Oh, sorry if I was unclear, I meant a console command that does this.

I don’t see what using concommands would help you achieve when there’s already a lib that does what you need.