SourceMod Moderator
|
09-30-2017
, 12:10
Re: L4d2, editing a plugin
|
#2
|
Quote:
Originally Posted by checkster
To start its not my code.
How do I get this to work with sourcebans?
Been so long since I did anything I'm pretty sure I'm lagging on info
|
Something like this:
PHP Code:
#pragma semicolon 1
#include <sourcemod>
/* ADDED CONTENT */
#undef REQUIRE_PLUGIN
#include <sourcebans>
new g_bSBAvailable = false; /* SourceBans not (yet?) available */
/* ADDED CONTENT END */
public Plugin:myinfo =
{
name = "Thirdpersonshoulder Block",
author = "Don",
description = "Kicks clients who enable the thirdpersonshoulder mode on L4D1/2 to prevent them from looking around corners, through walls etc.",
version = "1.3",
url = "http://forums.alliedmods.net/showthread.php?t=159582"
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
decl String:sGame[12];
GetGameFolderName(sGame, sizeof(sGame));
if (StrEqual(sGame, "left4dead") || StrEqual(sGame, "left4dead2")) /* Only load the plugin if the server is running Left 4 Dead or Left 4 Dead 2.
* Loading the plugin on Counter-Strike: Source or Team Fortress 2 would cause all clients to get kicked,
* because the thirdpersonshoulder mode and the corresponding ConVar that we check do not exist there.
*/
{
return APLRes_Success;
}
else
{
strcopy(error, err_max, "Plugin only supports L4D1/2");
return APLRes_Failure;
}
}
public OnPluginStart()
{
CreateConVar("l4d_tpsblock_version", "1.3", "Version of the Thirdpersonshoulder Block plugin", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD);
CreateTimer(GetRandomFloat(2.5, 3.5), CheckClients, _, TIMER_REPEAT);
}
/* ADDED CONTENT */
public OnAllPluginsLoaded()
{
if (LibraryExists("sourcebans")) {
g_bSBAvailable = true;
}
}
public OnLibraryAdded(const String:name[])
{
if (StrEqual(name, "sourcebans")) {
g_bSBAvailable = true;
}
}
public OnLibraryRemoved(const String:name[])
{
if (StrEqual(name, "sourcebans")) {
g_bSBAvailable = false;
}
}
/* ADDED CONTENT END */
public Action:CheckClients(Handle:timer)
{
for (new iClientIndex = 1; iClientIndex <= MaxClients; iClientIndex++)
{
if (IsClientInGame(iClientIndex) && !IsFakeClient(iClientIndex))
{
if (GetClientTeam(iClientIndex) == 2 || GetClientTeam(iClientIndex) == 3) // Only query clients on survivor or infected team, ignore spectators.
{
QueryClientConVar(iClientIndex, "c_thirdpersonshoulder", QueryClientConVarCallback);
}
}
}
}
public QueryClientConVarCallback(QueryCookie:cookie, client, ConVarQueryResult:result, const String:cvarName[], const String:cvarValue[])
{
if (IsClientInGame(client) && !IsClientInKickQueue(client))
{
if (result != ConVarQuery_Okay) /* If the ConVar was somehow not found on the client, is not valid or is protected, kick the client.
* The ConVar should always be readable unless the client is trying to prevent it from being read out.
*/
{
new String:sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
/* ADDED CONTENT */
if (g_bSBAvailable) {
SBBanPlayer(0,client,5,"Banned for potentially using thirdpersonshoulder mode.\nConVar c_thirdpersonshoulder not found, not valid or protected");
} else {
BanClient(client,5,BANFLAG_AUTHID,"Banned for potentially using thirdpersonshoulder mode.\nConVar c_thirdpersonshoulder not found, not valid or protected");
}
/* ADDED CONTENT END */
LogAction(0, client, "Banned \"%L\" for potentially using thirdpersonshoulder mode, ConVar c_thirdpersonshoulder not found, not valid or protected", client);
PrintToChatAll("[SM] Banned %s for potentially using thirdpersonshoulder mode, ConVar c_thirdpersonshoulder not found, not valid or protected", sName);
}
else if (!StrEqual(cvarValue, "false") && !StrEqual(cvarValue, "0")) /* If the ConVar was found on the client, but is not set to either "false" or "0",
* kick the client as well, as he might be using thirdpersonshoulder.
*/
{
new String:sName[MAX_NAME_LENGTH];
GetClientName(client, sName, sizeof(sName));
/* ADDED CONTENT */
if (g_bSBAvailable) {
SBBanPlayer(0, client,5,"Banned for potentially using thirdpersonshoulder mode.\nEnter \"c_thirdpersonshoulder 0\" (without the \"\") in your console before rejoining the server");
} else {
BanClient(client,5,BANFLAG_AUTHID,"Banned for potentially using thirdpersonshoulder mode.\nEnter \"c_thirdpersonshoulder 0\" (without the \"\") in your console before rejoining the server");
}
/* ADDED CONTENT END */
LogAction(0, client, "Banned \"%L\" for potentially using thirdpersonshoulder mode", client);
PrintToChatAll("[SM] Banned %s for potentially using thirdpersonshoulder mode", sName);
}
}
}
All stuff between
PHP Code:
/* ADDED CONTENT */
and
/* ADDED CONTENT END */
are where content was added / altered.
If SourceBans is available, it will use SourceBans, if not, it will fall back to the previous way with BanClient.
__________________
Mostly known as "DarkDeviL".
Dropbox FastDL: Public folder will no longer work after March 15, 2017!
For more info, see the [SRCDS Thread], or the [HLDS Thread].
|
|