ConVar enforce

#1
Recent am invatat cum pot sa 'fortez' prin intermediul unui plugin o valuare asupra unui anumit ConVar.

Desi din punct de vedere functionalitate totul este okay, m-ar interesa sa stiu daca exista o metoda mai inteligenta de a scrie pentru a obtine acelasi rezultat. In momentul de fata am scris asa :

Code: Select all

public void OnPluginStart()
{	
	HookConVarChange((FindConVar("sv_alltalk")), OnValueChange);
	HookConVarChange((FindConVar("sv_full_alltalk")), OnValueChange);
	HookConVarChange((FindConVar("sv_deadtalk")), OnValueChange);
	HookConVarChange((FindConVar("sv_talk_enemy_dead")), OnValueChange);
	HookConVarChange((FindConVar("sv_talk_enemy_living")), OnValueChange);
}

public void OnValueChange(Handle hConVar, const char[] szOldValue, const char[] szNewValue)
{
	SetConVarInt((FindConVar("sv_alltalk")), 1);
	SetConVarInt((FindConVar("sv_full_alltalk")), 1);
	SetConVarInt((FindConVar("sv_deadtalk")), 1);
	SetConVarInt((FindConVar("sv_talk_enemy_dead")), 1);
	SetConVarInt((FindConVar("sv_talk_enemy_living")), 1);
}
De mentionat ca am folosit ConVars de 'talk' doar ca si exemplu. Stiu ca deja exista un plugin mult mai pertinet ce ofera aceeasi functionalitate.

Re: ConVar enforce

#2

Code: Select all

ConVar g_Cvar_BotQuota;

public void OnPluginStart()
{
	g_Cvar_BotQuota = FindConVar("bot_quota");
	if (g_Cvar_BotQuota)
	{
		g_Cvar_BotQuota.AddChangeHook(ConVarChange_BotQuota);
	}
}

public void ConVarChange_BotQuota(ConVar convar, const char[] oldValue, const char[] newValue)
{
	g_Cvar_BotQuota.SetInt(0);
}
Ar trebui sa faci pt fiecare cvar un HookConVarChange diferit.

Re: ConVar enforce

#3
Adica ceva de genul ?

Code: Select all

ConVar g_Cvar_AllTalk;
ConVar g_Cvar_FullAllTalk;

public void OnPluginStart()
{
	g_Cvar_AllTalk = FindConVar("sv_alltalk");
	if (g_Cvar_AllTalk)
	{
		g_Cvar_AllTalk.AddChangeHook(ConVarChange_AllTalk);
	}
	
	
	g_Cvar_FullAllTalk = FindConVar("sv_full_alltalk");
	if (g_Cvar_FullAllTalk)
	{
		g_Cvar_FullAllTalk.AddChangeHook(ConVarChange_FullAllTalk);
	}
}

public void ConVarChange_AllTalk(ConVar convar, const char[] oldValue, const char[] newValue)
{
	g_Cvar_AllTalk.SetInt(1);
}

public void ConVarChange_FullAllTalk(ConVar convar, const char[] oldValue, const char[] newValue)
{
	g_Cvar_FullAllTalk.SetInt(1);
}
cron