Return to Main Page

ConVars

Page white text.png Description:Article about convars.
link=User:Dim1xs Author:Dim1xs
Calendar.png Created:September 28th 2023

This article will learn you, how to create and use lua ConVars

The beginning

ConVar is executing to the game automatically,
if the script is located in '../lua/autorun' , or the function is runned via/from SWEP/ENTITY.

CreateConVar

For adding ConVar you can use this function:
--Command Name, Default Value, FLAGS, HelpText, Minimum Value, Maximum Value
CreateConVar("CommandName", "defValue", FCVAR_NONE, "HelpText", "minValue", "maxValue")
               

Examples

Here some examples, how you can use it.

First is going example, for getting bool from ConVar:
local checkBool = CreateConVar("gmed_giveweapons", "1", FCVAR_CLIENT, "Give weapons?", "0", "1")

if checkBool:GetBool() == true then
   print("ConVar is Working!")
end
               
Next is example, how to get int from ConVar:
local checkInt = CreateConVar("checkInteger", "1", FCVAR_SERVER, "Checks Integer", "0", "255")

if checkBool:GetInt() == 133 then
   print("int = 133")
end
               

Flags

Flags are using FCVAR enum.

Thank you for reading this tutorial, see ya later!

JOIN HL2GMED DISCORD SERVER!