-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbanhammer.sp
148 lines (126 loc) · 3.17 KB
/
banhammer.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
#include <sourcemod>
#include <sdkhooks>
#include <sdktools>
#include <sourcebans>
public Plugin myinfo =
{
name = "BanHammer",
author = "KiD Fearless",
description = "Gives admins the all mighty ban hammer!",
version = "1.0",
url = "https://steamcommunity.com/id/kidfearless/"
}
int g_iBanHammer = -1;
int g_iBanLength[MAXPLAYERS + 1] = 0;
public void OnPluginStart()
{
RegAdminCmd("sm_banhammer", Command_BanHammer, ADMFLAG_RCON, "Equip the ban hammer.");
for(int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i))
{
OnClientPutInServer(i);
}
}
}
public void OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_TraceAttack, OnPlayerHurtPre);
}
public Action OnPlayerHurtPre(int victim, int& attacker, int& inflictor, float& damage, int& damagetype, int& ammotype, int hitbox, int hitgroup)
{
if(g_iBanHammer == -1)
{
return Plugin_Continue;
}
if(Weapon_GetOwner(g_iBanHammer) != attacker)
{
PrintToConsole(attacker, "You are not worthy to hold such power.");
return Plugin_Continue;
}
char weaponName[32];
GetClientWeapon(attacker, weaponName, sizeof(weaponName));
if(StrContains(weaponName, "hammer", false) != -1)
{
for(int i = 1; i <=MaxClients; ++i)
{
if(IsValidClient(i))
{
ClientCommand(i, "play weapons/flashbang/flashbang_explode1.wav");
PrintToChat(i, "THE BAN HAMMER STRIKES AGAIN!");
}
ForcePlayerSuicide(victim);
}
DataPack data = new DataPack();
data.WriteCell(attacker);
data.WriteCell(victim);
CreateTimer(2.0, DelayedBan, data);
}
else
{
PrintToConsole(attacker, "Wrong hammer buddy.");
}
return Plugin_Continue;
}
public Action DelayedBan(Handle timer, DataPack data)
{
data.Reset();
int attacker = data.ReadCell();
int victim = data.ReadCell();
delete data;
SBBanPlayer(attacker, victim, g_iBanLength[attacker], "Ban Hammer Strikes Again!");
return Plugin_Continue;
}
public void OnClientDisconnect(int client)
{
SDKUnhook(client, SDKHook_WeaponDrop, OnWeaponDrop);
g_iBanLength[client] = 0;
}
public void OnMapEnd()
{
g_iBanHammer = -1;
}
public Action Command_BanHammer(int client, int args)
{
SDKHook(client, SDKHook_WeaponDrop, OnWeaponDrop);
g_iBanHammer = GivePlayerItem(client, "weapon_hammer");
EquipPlayerWeapon(client, g_iBanHammer);
if(args > 1)
{
char arg[32];
GetCmdArg(1, arg, sizeof(arg));
g_iBanLength[client] = StringToInt(arg);
}
return Plugin_Handled;
}
public void OnWeaponDrop(int client, int weapon)
{
if(weapon == g_iBanHammer)
{
g_iBanHammer = -1;
SDKUnhook(client, SDKHook_WeaponDrop, OnWeaponDrop);
}
}
stock int Weapon_GetOwner(int weapon)
{
return GetEntPropEnt(weapon, Prop_Data, "m_hOwner");
}
stock bool IsValidClient(int client, bool bAlive = false)
{
return (client >= 1 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client) && !IsClientSourceTV(client) && (!bAlive || IsPlayerAlive(client)));
}
stock bool Client_RemoveWeapon(int client, const char[] className, bool firstOnly=true)
{
int offset = Client_GetWeaponsOffset(client) - 4;
for (int i=0; i < 48; i++)
{
offset += 4;
int weapon = GetEntDataEnt2(client, offset);
if (!IsValidEdict(weapon))
{
continue;
}
RemovePlayerItem(client, weapon);
}
return false;
}