summaryrefslogtreecommitdiff
path: root/sourcemod/scripting/include/smlib/convars.inc
diff options
context:
space:
mode:
authornavewindre <nw@moneybot.cc>2023-11-13 14:28:08 +0100
committernavewindre <nw@moneybot.cc>2023-11-13 14:28:08 +0100
commitda518fdc0f32839730ccdee8098b59c6f842d93f (patch)
treed6f856a6148c0b4d5819f88f068b7287b8044513 /sourcemod/scripting/include/smlib/convars.inc
parentbc678b10830cdaef64bcc592ca2524ebe0fcdc45 (diff)
ya
Diffstat (limited to 'sourcemod/scripting/include/smlib/convars.inc')
-rw-r--r--sourcemod/scripting/include/smlib/convars.inc71
1 files changed, 71 insertions, 0 deletions
diff --git a/sourcemod/scripting/include/smlib/convars.inc b/sourcemod/scripting/include/smlib/convars.inc
new file mode 100644
index 0000000..b7f4b23
--- /dev/null
+++ b/sourcemod/scripting/include/smlib/convars.inc
@@ -0,0 +1,71 @@
+#if defined _smlib_convars_included
+ #endinput
+#endif
+#define _smlib_convars_included
+
+#include <sourcemod>
+
+/**
+ * Checks if a ConVar has one or more flags set.
+ *
+ * @param convar ConVar Handle.
+ * @param flags Flags to check.
+ * @return True if flags are set, false otherwise.
+ */
+stock bool Convar_HasFlags(ConVar convar, int flags)
+{
+ return convar.Flags & flags > 0;
+}
+
+/**
+ * Adds one or more flags to a ConVar.
+ *
+ * @param convar ConVar Handle.
+ * @param flags Flags to add.
+ */
+stock void Convar_AddFlags(ConVar convar, int flags)
+{
+ int newFlags = convar.Flags;
+ newFlags |= flags;
+ convar.Flags = newFlags;
+}
+
+/**
+ * Removes one ore more flags from a ConVar.
+ *
+ * @param convar ConVar Handle.
+ * @param flags Flags to remove
+ * @noreturn
+ */
+stock void Convar_RemoveFlags(ConVar convar, int flags)
+{
+ int newFlags = convar.Flags;
+ newFlags &= ~flags;
+ convar.Flags = newFlags;
+}
+
+/**
+ * Checks if a String is a valid ConVar or
+ * Console Command name.
+ *
+ * @param name String Name.
+ * @return True if the name specified is a valid ConVar or console command name, false otherwise.
+ */
+stock bool Convar_IsValidName(const char[] name)
+{
+ if (name[0] == '\0') {
+ return false;
+ }
+
+ int n=0;
+ while (name[n] != '\0') {
+
+ if (!IsValidConVarChar(name[n])) {
+ return false;
+ }
+
+ n++;
+ }
+
+ return true;
+}