Quote:
Originally Posted by PatriotGames
Thanks, Dragokas, that makes sense.
PG
|
To add more to this, we hook a cvar handle to a changehook if we want something to happen as soon as the value of that cvar is changed. (i.e. g_cvIsOn.AddChangeHook(vIsOnHook) or HookConVarChange(g_hIsOn, vIsOnHook))
If we just want to check the current value of the cvar, we can just call it when we need it (or cache it to a variable if you prefer that). (i.e. bIsOn = g_cvIsOn.BoolValue or bIsOn = GetConVarBool(g_hIsOn))
In this example, we're going to check the initial value of the "mp_gamemode" cvar and then hook it so we can check for the value whenever it changes:
PHP Code:
ConVar g_cvMPGameMode;
bool g_bIsCampaign;
public void OnPluginStart()
{
g_cvMPGameMode = FindConVar("mp_gamemode");
if (g_cvMPGameMode != null)
{
g_cvMPGameMode.AddChangeHook(vMPGameModeHook);
}
}
public void OnMapStart()
{
if (g_cvMPGameMode != null)
{
char sGameMode[32];
g_cvMPGameMode.GetString(sGameMode, sizeof(sGameMode));
if (StrEqual(sGameMode, "versus"))
{
g_bIsCampaign = false;
}
}
}
public void vMPGameModeHook(ConVar convar, const char[] oldVal, const char[] newVal)
{
if (StrEqual(newVal, "versus"))
{
g_bIsCampaign = false;
}
else
{
g_bIsCampaign = true;
}
}
I assume you've made this thread due to the changes I made to your plugin last week. I'm sorry for not explaining it to you or adding comments in the code to help you. If you want, we can discuss any other questions you may have in private chat or on Discord.
__________________