Thread: [Solved] Detect CVar value change ?
View Single Post
Chaosxk
Veteran Member
Join Date: Aug 2010
Location: Westeros
Old 03-23-2017 , 19:35   Re: Detect CVar value change ?
Reply With Quote #12

Needs to pass in userid, not clientid in timer and needs to check if client is in game otherwise you get those errors.

Code:
#include <sourcemod>
#include <sdktools>
#include <basecomm>
#include <voiceannounce_ex>
#pragma newdecls required
#define PLUGIN_VERSION "1.0"
#define message "You were kicked for attempting to micspam. Please set voice_inputfromfile to 0."

public Plugin myinfo = 
{
	name = "Slam Protection",
	author = "Furchee",
	description = "Kicks clients that have voice_inputfromfile set to 1.",
	version = PLUGIN_VERSION,
	url = "http://furchee.com"
};

public void OnClientPutInServer(int client)
{
	CreateTimer(2.0, StartVarChecker, GetClientUserId(client));
}

public void OnClientSpeakingEx(int client)
{
	QueryClientConVar(client, "voice_inputfromfile", view_as<ConVarQueryFinished>(ClientConVar), client);
}

public Action StartVarChecker(Handle timer, int userid)
{
	int client = GetClientOfUserId(userid);
	
	if (!IsClientInGame(client))
		return Plugin_Stop;
	
	QueryClientConVar(client, "voice_inputfromfile", view_as<ConVarQueryFinished>(ClientConVar), client);
	return Plugin_Continue;
}

public void ClientConVar(QueryCookie cookie, int client, ConVarQueryResult result, const char[] cvarName, const char[] cvarValue)
{
	if (!StrEqual(cvarValue, "0"))
	{
		LogAction(client, -1, "%L triggered mic spam protection, kicking", client);
		KickClient(client, "%s", message);
	}
}
__________________
Chaosxk is offline