Raised This Month: $ Target: $400
 0% 

Solved [CS:GO] Help with keyvalue-based ctban plugin


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
potatoz
AlliedModders Donor
Join Date: Nov 2016
Old 08-18-2018 , 10:20   Re: [CS:GO] Help with keyvalue-based ctban plugin
Reply With Quote #10

Quote:
Originally Posted by Crasher_3637 View Post
Show your updated code.
I've got some other small issues that i noticed now afterwards but anyways, this is it;

@mug1wara I'll def try yours out too, major creds for taking the time

PHP Code:
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#pragma semicolon 1 
 
int ctban[MAXPLAYERS+1];
Handle ctbantimer[MAXPLAYERS+1];
bool chatprinted[MAXPLAYERS+1];
 
KeyValues kv

public 
Plugin myinfo =
{
    
name "Simple CT-Ban",
    
author "Potatoz",
    
description "Simple CT-Ban system for jailbreak servers",
    
version "1.0",
    
url "http://www.sourcemod.net/"
};


public 
void OnPluginStart()
{
    
LoadTranslations("common.phrases");
    
RegAdminCmd("sm_ctban"Command_CTBanADMFLAG_BAN);
    
RegAdminCmd("sm_ctunban"Command_CTUnBanADMFLAG_BAN);
    
RegAdminCmd("sm_isbanned"Command_IsBannedADMFLAG_BAN);
    
    
HookEvent("player_team"Event_PlayerTeam);
    
AddCommandListener(Event_OnJoinTeam"jointeam");
    
    
char buffer[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMbuffersizeof(buffer), "configs/ctban_database.cfg");
    
kv = new KeyValues("ctban_database");
    
kv.ImportFromFile(buffer);
}

public 
Action Event_PlayerTeam(Handle event, const char[] namebool dontBroadcast)
{
    new 
client  GetClientOfUserId(GetEventInt(event"userid"));
    if(
IsValidClient(client))
        
CreateTimer(0.2CheckTeamclientTIMER_FLAG_NO_MAPCHANGE);
}

public 
Action CheckTeam(Handle timerint client)
{
    if(
IsValidClient(client) && GetClientTeam(client) == && ctban[client] > 0)
    {
        
int minutes ctban[client] / 60;
        
minutes++;
    
        
PrintToChat(client" \x07* You are banned from the CT team for %.1d more minute(s)"minutes);
        
ChangeClientTeam(client2);
    }
    
    return 
Plugin_Handled;
}

public 
Action Event_OnJoinTeam(int client, const char[] commandint args
{
    if (!
IsValidClient(client) || IsFakeClient(client))
        return 
Plugin_Continue;

    
char teamString[2];
    
GetCmdArg(1teamStringsizeof(teamString));
    
int team StringToInt(teamString);

    
int minutes ctban[client] / 60;
    
minutes++;
    
    if (
team == 0
    {
        
PrintToChat(client" \x07* You can't auto-assign to select team");
        return 
Plugin_Stop;
    }
    
    if (
team == && ctban[client] > 0
    {
        
PrintToChat(client" \x07* You are banned from the CT team for %.1d more minute(s)"minutes);
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;
}

public 
OnClientPostAdminCheck(int client
{
    
chatprinted[client] = false;
    
GetCTBanData(client);
    
    if(
ctban[client] > 0)
        
ctbantimer[client] = CreateTimer(1.0Timer_CTBanclientTIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
}

public 
Action Command_CTBan(int clientint args)
{
    if(
args 3
    {
        
ReplyToCommand(client"[SM] Usage: sm_ctban <name|#userid> [minutes] [reason]");
        return 
Plugin_Handled;
    }
    
    
char arg1[32], arg2[32], arg3[40];

    
GetCmdArg(1arg1sizeof(arg1));
    
GetCmdArg(2arg2sizeof(arg2));
    
GetCmdArg(3arg3sizeof(arg3));
    
    
int minutes StringToInt(arg2);
    
int target FindTarget(clientarg1);
    if (
target == -1) return Plugin_Handled;
    
    if(
ctban[target] > 0)
    {
        
PrintToChat(client" \x07* %N is already CT-Banned"target);
        return 
Plugin_Handled;
    }
    
    
chatprinted[target] = false;
    
ctban[target] = minutes 60;
    
ctbantimer[target] = CreateTimer(1.0Timer_CTBantargetTIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
    
    
UpdateCTBanData(target);
    
    if(
GetClientTeam(target) == 3)
    {
        
ChangeClientTeam(target2);
        
ForcePlayerSuicide(target);
    }
    
    
PrintToChatAll(" \x07*\x01 ADMIN: \x07%N\x01 CT-Banned \x07%N \x01for %s minute(s) with reason: \x07%s"clienttargetarg2arg3);
    
    return 
Plugin_Handled;
}

public 
Action Command_CTUnBan(int clientint args)
{
    if(
args 1
    {
        
ReplyToCommand(client"[SM] Usage: sm_ctunban <name|#userid>");
        return 
Plugin_Handled;
    }
    
    
char arg1[32];

    
GetCmdArg(1arg1sizeof(arg1));
    
int target FindTarget(clientarg1);
    if (
target == -1) return Plugin_Handled;
    
    if(
ctban[target] < 1)
        
PrintToChat(client" \x07* %N is not CT-Banned"target);
    
    
chatprinted[target] = true;
    
ctbantimer[target] = null;
    
KillTimer(ctbantimer[target]);
    
    
ctban[target] = 0;
    
PrintToChatAll(" \x06*\x01 ADMIN: \x06%N\x01 has removed CT-Ban from \x06%N"clienttarget);
    
UpdateCTBanData(target);
    
    return 
Plugin_Handled;
}

public 
Action Timer_CTBan(Handle timerint client)
{
    if(
ctban[client] < 1)
    {
        
ctban[client] = 0;
        
        
ctbantimer[client] = null;
        
KillTimer(ctbantimer[client]);
        
        return 
Plugin_Stop;
    }
    
    
ctban[client]--;
    
UpdateCTBanData(client);
    
    if(
ctban[client] < 1)
    {
        if(!
chatprinted[client])
        {
            
PrintToChat(client" \x06*\x01 Your CT-Ban has expired");
            
chatprinted[client] = true;
        }
        
        
ctban[client] = 0;
        
        
ctbantimer[client] = null;
        
KillTimer(ctbantimer[client]);
        
        return 
Plugin_Stop;
    }
    
    return 
Plugin_Continue;
}

public 
void OnClientDisconnect(int client)
{
    if (
ctbantimer[client] != null)
    {
        
KillTimer(ctbantimer[client]);
        
ctbantimer[client] = null;
        
chatprinted[client] = false;
    }
}

public 
Action Command_IsBanned(int clientint args)
{
    if(
args 1
    {
        
ReplyToCommand(client"[SM] Usage: sm_isbanned <name|#userid>");
        return 
Plugin_Handled;
    }
    
    
char arg1[32];
    
GetCmdArg(1arg1sizeof(arg1));
    
int target FindTarget(clientarg1);
    if (
target == -1) return Plugin_Handled;
    
    
int minutes ctban[client] / 60;
    
minutes++;
    
    if(
ctban[target] < 1)
        
PrintToChat(client" \x07* %N is not CT-Banned"target);
    else 
PrintToChat(client" \x06* %N \x01is CT-Banned for %.1d more minute(s)"targetminutes);
    
    return 
Plugin_Handled;
}

UpdateCTBanData(int client)
{
    
char buffer[PLATFORM_MAX_PATH], steamauth[50];
    
GetClientAuthId(clientAuthId_Steam2steamauthsizeof(steamauth));
    
Format(buffersizeof(buffer), "%d"ctban[client]);
    
kv.JumpToKey(steamauthtrue);
    
kv.SetString("ctban_time"buffer);
    
    
int length StringToInt(buffer);
    if (
length == 0)
        
kv.DeleteThis();
    
    
kv.Rewind();
    
BuildPath(Path_SMbuffersizeof(buffer), "configs/ctban_database.cfg");
    
kv.ExportToFile(buffer);
}

GetCTBanData(int client)
{
    
char sConfig[PLATFORM_MAX_PATH], sUserID[50];
    
GetClientAuthId(clientAuthId_Steam2sUserIDsizeof(sUserID));
    
BuildPath(Path_SMsConfigsizeof(sConfig), "configs/ctban_database.cfg");

    
KeyValues hConfig = new KeyValues("ctban_database");
    
    if (
FileToKeyValues(hConfigsConfig))
    {
        if (
KvJumpToKey(hConfigsUserIDfalse))
        {
            
char sTimeLeft[20];
            
KvGetString(hConfig"ctban_time"sTimeLeftsizeof(sTimeLeft));
                
            if (
sTimeLeft[0] != '\0')
                
ctban[client] = StringToInt(sTimeLeft);
            else
                
ctban[client] = 0;
                
            if(
ctban[client] > 0)
            {
                if(
ctbantimer[client] == null)
                    
ctbantimer[client] = CreateTimer(1.0Timer_CTBanclientTIMER_REPEAT TIMER_FLAG_NO_MAPCHANGE);
            }
            else
            {
                
ctban[client] = 0;
                
KillTimer(ctbantimer[client]);
                
ctbantimer[client] = null;
            }
        }
        else
        {
            
ctban[client] = 0;
            
KillTimer(ctbantimer[client]);
            
ctbantimer[client] = null;
        }
    }
    
    
CloseHandle(hConfig);
}

bool IsValidClient(int client
{
    if (!( 
<= client <= MaxClients ) || !IsClientInGame(client)) 
        return 
false
     
    return 
true

__________________
potatoz is offline
 



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 10:41.


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