Trying to hook convar changes and changing them seems to not update the convar value if the cvar is changed in game with the sm_cvar command. Here is the code:
PHP Code:
#pragma semicolon 1
#define PLUGIN_AUTHOR "Sgt. Gremulock"
#define PLUGIN_VERSION "1.0.2"
#include <sourcemod>
// ConVars
ConVar cv_ChatText;
ConVar cv_CenterText;
// Booleans
new bool:bChatText;
new bool:bCenterText;
public Plugin myinfo =
{
name = "[TF2] End Round Friendly Fire",
author = PLUGIN_AUTHOR,
description = "Enable's friendly fire at the end of a round and disables it on the start of the next round.",
version = PLUGIN_VERSION,
url = "grem-co.com"
};
public void OnPluginStart()
{
HookEvent("teamplay_round_win", Event_RoundWin);
HookEvent("teamplay_round_start", Event_RoundStart);
cv_ChatText = CreateConVar("sm_endroundff_chat", "1", "Announce ff status in chat?", _, true, 0.0, true, 1.0);
HookConVarChange(cv_ChatText, ConVar_ChatText);
bChatText = GetConVarBool(cv_ChatText);
cv_CenterText = CreateConVar("sm_endroundff_center", "1", "Announce ff status in center text?", _, true, 0.0, true, 1.0);
HookConVarChange(cv_CenterText, ConVar_CenterText);
bCenterText = GetConVarBool(cv_CenterText);
CreateConVar("sm_endroundff_version", PLUGIN_VERSION, "Plugin's version.", FCVAR_REPLICATED|FCVAR_NOTIFY);
AutoExecConfig(true, "endroundff", "sourcemod");
}
public ConVar_ChatText(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (bChatText)
{
SetConVarBool(convar, true);
}
else
{
SetConVarBool(convar, false);
}
}
public ConVar_CenterText(Handle:convar, const String:oldValue[], const String:newValue[])
{
if (bCenterText)
{
SetConVarBool(convar, true);
}
else
{
SetConVarBool(convar, false);
}
}
public void OnConfigsExecuted()
{
GetConVarBool(cv_ChatText);
GetConVarBool(cv_CenterText);
}
public Action Event_RoundWin(Event event, const char[] name, bool dontBroadcast)
{
SetConVarInt(FindConVar("mp_friendlyfire"), 1);
if (bChatText && !bCenterText)
{
PrintToChatAll("[SM] End of round friendly fire has been enabled.");
}
else if (bCenterText && !bChatText)
{
PrintCenterTextAll("End of round friendly fire has been enabled.");
}
else if (bChatText && bCenterText)
{
PrintCenterTextAll("End of round friendly fire has been enabled.");
PrintToChatAll("[SM] End of round friendly fire has been enabled.");
}
}
public Action Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
SetConVarInt(FindConVar("mp_friendlyfire"), 0);
if (bChatText && !bCenterText)
{
PrintToChatAll("[SM] End of round friendly fire has been disabled.");
}
else if (bCenterText && !bChatText)
{
PrintCenterTextAll("End of round friendly fire has been disabled.");
}
else if (bChatText && bCenterText)
{
PrintCenterTextAll("End of round friendly fire has been disabled.");
PrintToChatAll("[SM] End of round friendly fire has been disabled.");
}
}