-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathctban.sp
120 lines (95 loc) · 2.72 KB
/
ctban.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <cnf_core>
#include <timedpunishment>
#include <teambalance>
#include <ctban>
#pragma semicolon 1
#pragma newdecls required
bool g_bIsCTBanned[MAXPLAYERS + 1];
public void OnPluginStart()
{
//TimedPunishment_RegisterPunishment(GetMyHandle(), "sm_ctban", "sm_unctban", "CT ban", ADMFLAG_KICK, COUNTDOWN_ALIVE, false, true, "CTBan_OnStart", "CTBan_OnStop", "CTBan_OnJoin", "CTBan_OnLeave");
TimedPunishment_RegisterPunishment("sm_ctban", "sm_unctban", "CT ban", ADMFLAG_KICK, COUNTDOWN_ALIVE, false, true, "CTBan_OnStart", "CTBan_OnStop", "CTBan_OnJoin", "CTBan_OnLeave");
HookEvent("player_team", Event_PlayerTeam, EventHookMode_Pre);
}
public void Core_OnClientPutInServer(int client)
{
g_bIsCTBanned[client] = false;
}
public Action Teambalance_OnGuardJoinAttempt(int client)
{
if (g_bIsCTBanned[client])
{
PrintHintText(client, "You are currently ctbanned and thus can't join CT");
return Plugin_Handled;
}
return Plugin_Continue;
}
public Action Event_PlayerTeam(Event event, char[] name, bool dontBroadcast)
{
int iUserId = event.GetInt("userid");
int iClient = GetClientOfUserId(iUserId);
int iTeam = event.GetInt("team");
if (iTeam != CS_TEAM_CT || !g_bIsCTBanned[iClient])
{
return Plugin_Continue;
}
dontBroadcast = true;
CreateTimer(0.0, Timer_SwitchTeam, iUserId);
return Plugin_Stop;
}
public Action Timer_SwitchTeam(Handle timer, any iUserId)
{
int client = GetClientOfUserId(iUserId);
if (client == 0 || GetClientTeam(client) != CS_TEAM_CT)
{
return Plugin_Stop;
}
CS_SwitchTeam(client, CS_TEAM_T);
if (IsPlayerAlive(client))
{
// If the player was alive already, move him back to his team's spawn
CS_RespawnPlayer(client);
}
return Plugin_Stop;
}
/************************ TIMEDPUNISHMENT CALLBACKS *****************************/
public void CTBan_OnStart(int client)
{
if (GetClientTeam(client) == CS_TEAM_CT)
{
ForcePlayerSuicide(client);
CS_SwitchTeam(client, CS_TEAM_T);
}
g_bIsCTBanned[client] = true;
}
public void CTBan_OnStop(int client)
{
g_bIsCTBanned[client] = false;
}
public void CTBan_OnJoin(int client)
{
if (GetClientTeam(client) == CS_TEAM_CT)
{
ForcePlayerSuicide(client);
CS_SwitchTeam(client, CS_TEAM_T);
}
g_bIsCTBanned[client] = true;
}
public void CTBan_OnLeave(int client)
{
g_bIsCTBanned[client] = false;
}
/********************************** NATIVES *************************************/
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
CreateNative("IsCTBanned", Native_IsCTBanned);
return APLRes_Success;
}
public int Native_IsCTBanned(Handle plugin, int numParams)
{
int client = GetNativeCell(1);
return view_as<int>(g_bIsCTBanned[client]);
}