Raised This Month: $32 Target: $400
 8% 

L4d2, editing a plugin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
checkster
BANNED
Join Date: Apr 2007
Location: Norway
Old 09-30-2017 , 11:00   L4d2, editing a plugin
Reply With Quote #1

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

PHP Code:
#pragma semicolon 1

#include <sourcemod>

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:myselfbool:lateString:error[], err_max)
{
    
decl String:sGame[12];
    
GetGameFolderName(sGamesizeof(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(errorerr_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.53.5), CheckClients_TIMER_REPEAT);
}

public 
Action:CheckClients(Handle:timer)
{
    for (new 
iClientIndex 1iClientIndex <= MaxClientsiClientIndex++)
    {
        if (
IsClientInGame(iClientIndex) && !IsFakeClient(iClientIndex))
        {
            if (
GetClientTeam(iClientIndex) == || GetClientTeam(iClientIndex) == 3)    // Only query clients on survivor or infected team, ignore spectators.
            
{
                
QueryClientConVar(iClientIndex"c_thirdpersonshoulder"QueryClientConVarCallback);
            }
        }
    }    
}

public 
QueryClientConVarCallback(QueryCookie:cookieclientConVarQueryResult: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(clientsNamesizeof(sName));
            
BanClient(client,5,BANFLAG_AUTHID,"Banned for potentially using thirdpersonshoulder mode.\nConVar c_thirdpersonshoulder not found, not valid or protected");
            
LogAction(0client"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(clientsNamesizeof(sName));
            
BanClient(client,5,BANFLAG_AUTHID,"Banned for potentially using thirdpersonshoulder mode.\nEnter \"c_thirdpersonshoulder 0\" (without the \"\") in your console before rejoining the server");
            
LogAction(0client"Banned \"%L\" for potentially using thirdpersonshoulder mode"client);
            
PrintToChatAll("[SM] Banned %s for potentially using thirdpersonshoulder mode"sName);
        }
    }

checkster is offline
DarkDeviL
SourceMod Moderator
Join Date: Apr 2012
Old 09-30-2017 , 12:10   Re: L4d2, editing a plugin
Reply With Quote #2

Quote:
Originally Posted by checkster View Post
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:myselfbool:lateString:error[], err_max)
{
    
decl String:sGame[12];
    
GetGameFolderName(sGamesizeof(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(errorerr_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.53.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 1iClientIndex <= MaxClientsiClientIndex++)
    {
        if (
IsClientInGame(iClientIndex) && !IsFakeClient(iClientIndex))
        {
            if (
GetClientTeam(iClientIndex) == || GetClientTeam(iClientIndex) == 3)    // Only query clients on survivor or infected team, ignore spectators.
            
{
                
QueryClientConVar(iClientIndex"c_thirdpersonshoulder"QueryClientConVarCallback);
            }
        }
    }    
}

public 
QueryClientConVarCallback(QueryCookie:cookieclientConVarQueryResult: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(clientsNamesizeof(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(0client"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(clientsNamesizeof(sName));
/* ADDED CONTENT */
            
if (g_bSBAvailable) {
                        
SBBanPlayer(0client,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(0client"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].
DarkDeviL is offline
checkster
BANNED
Join Date: Apr 2007
Location: Norway
Old 09-30-2017 , 13:06   Re: L4d2, editing a plugin
Reply With Quote #3

Quote:
Originally Posted by arne1288 View Post
Something like this:


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.


Lol now I feel stupid, but thank you Arne, let me buy you a beer if you're ever close. (rogaland)
I had no idea there was a #include for sourcebans.

cheers
checkster is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:27.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode