-
Notifications
You must be signed in to change notification settings - Fork 37
/
friendlyfire.sp
245 lines (204 loc) · 7.28 KB
/
friendlyfire.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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
* MyJailbreak - Warden - Friendly Fire Module.
* by: shanapu
* https://github.com/shanapu/MyJailbreak/
*
* Copyright (C) 2016-2017 Thomas Schmidt (shanapu)
* Contributer: Hexer10
*
* This file is part of the MyJailbreak SourceMod Plugin.
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, version 3.0, as published by the
* Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
/******************************************************************************
STARTUP
******************************************************************************/
// Includes
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <cstrike>
#include <colors>
#include <autoexecconfig>
#include <warden>
#include <myjbwarden>
#include <mystocks>
// Compiler Options
#pragma semicolon 1
#pragma newdecls required
// Console Variables
ConVar gc_bFF;
ConVar gc_bFFDeputy;
ConVar gc_sCustomCommandFF;
ConVar gc_sFFCT;
// Extern Convars
ConVar g_bFF;
ConVar Cvar_tg_team_none_attack;
ConVar Cvar_tg_cvar_friendlyfire;
ConVar Cvar_tg_ct_friendlyfire;
//Integer
int OldCvar_tg_team_none_attack;
int OldCvar_tg_cvar_friendlyfire;
int OldCvar_tg_ct_friendlyfire;
// Start
public void FriendlyFire_OnPluginStart()
{
// Client commands
RegConsoleCmd("sm_setff", Command_FriendlyFire, "Allows player to see the state and the Warden to toggle friendly fire");
// AutoExecConfig
gc_bFF = AutoExecConfig_CreateConVar("sm_warden_ff", "1", "0 - disabled, 1 - enable switch ff for the warden", _, true, 0.0, true, 1.0);
gc_sFFCT = AutoExecConfig_CreateConVar("sm_warden_ff_ct_enable", "0", "0 - disabled, 1 - enable ff for cts also", _, true, 0.0, true, 1.0);
gc_bFFDeputy = AutoExecConfig_CreateConVar("sm_warden_ff_deputy", "1", "0 - disabled, 1 - enable switch ff for the deputy, too", _, true, 0.0, true, 1.0);
gc_sCustomCommandFF = AutoExecConfig_CreateConVar("sm_warden_cmds_ff", "isff, friendlyfire", "Set your custom chat commands for set/see friendly fire(!ff is reservered)(!setff (no 'sm_'/'!')(seperate with comma ', ')(max. 12 commands)");
// Hooks
HookEvent("round_end", FriendlyFire_Event_RoundEnd);
HookEvent("player_death", FriendlyFire_Event_PlayerDeath);
// FindConVar
g_bFF = FindConVar("mp_teammates_are_enemies");
}
/******************************************************************************
COMMANDS
******************************************************************************/
public Action Command_FriendlyFire(int client, int args)
{
if (gc_bFF.BoolValue)
{
if (g_bFF.BoolValue)
{
if (IsClientWarden(client) || (IsClientDeputy(client) && gc_bFFDeputy.BoolValue))
{
SetCvar("mp_teammates_are_enemies", 0);
g_bFF = FindConVar("mp_teammates_are_enemies");
CPrintToChatAll("%s %t", g_sPrefix, "warden_ffisoff");
if (Cvar_tg_team_none_attack != null)
{
// Replace the Cvar Value with old value
Cvar_tg_team_none_attack.IntValue = OldCvar_tg_team_none_attack;
Cvar_tg_cvar_friendlyfire.IntValue = OldCvar_tg_cvar_friendlyfire;
Cvar_tg_ct_friendlyfire.IntValue = OldCvar_tg_ct_friendlyfire;
}
}
else CReplyToCommand(client, "%s %t", g_sPrefix, "warden_ffison");
}
else
{
if (IsClientWarden(client) || (IsClientDeputy(client) && gc_bFFDeputy.BoolValue))
{
SetCvar("mp_teammates_are_enemies", 1);
g_bFF = FindConVar("mp_teammates_are_enemies");
CPrintToChatAll("%s %t", g_sPrefix, "warden_ffison");
if (Cvar_tg_team_none_attack != null)
{
Cvar_tg_team_none_attack.IntValue = 1;
Cvar_tg_cvar_friendlyfire.IntValue = 1;
Cvar_tg_ct_friendlyfire.IntValue = 1;
}
}
else CReplyToCommand(client, "%s %t", g_sPrefix, "warden_ffisoff");
}
}
return Plugin_Handled;
}
/******************************************************************************
EVENTS
******************************************************************************/
public void FriendlyFire_Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
if (!gc_bPlugin.BoolValue || !g_bEnabled)
return;
if (!g_bFF.BoolValue)
return;
if (GetPlayerCount(true, CS_TEAM_T) < 1)
{
SetCvar("mp_teammates_are_enemies", 0);
CS_TerminateRound(5.0, CSRoundEnd_CTWin, false);
}
}
public void FriendlyFire_Event_RoundEnd(Event event, const char[] name, bool dontBroadcast)
{
if (!gc_bPlugin.BoolValue || !g_bEnabled)
return;
if (!g_bFF.BoolValue)
return;
SetCvar("mp_teammates_are_enemies", 0);
g_bFF = FindConVar("mp_teammates_are_enemies");
CPrintToChatAll("%s %t", g_sPrefix, "warden_ffisoff");
if (Cvar_tg_team_none_attack != null)
{
// Replace the Cvar Value with old value
Cvar_tg_team_none_attack.IntValue = OldCvar_tg_team_none_attack;
Cvar_tg_cvar_friendlyfire.IntValue = OldCvar_tg_cvar_friendlyfire;
Cvar_tg_ct_friendlyfire.IntValue = OldCvar_tg_ct_friendlyfire;
}
}
public Action FriendlyFire_OnTraceAttack(int victim, int &attacker, int &inflictor, float &damage, int &damagetype, int &ammotype, int hitbox, int hitgroup)
{
if (gc_sFFCT.BoolValue)
return Plugin_Continue;
if (gp_bMyJailBreak && MyJailbreak_IsEventDayRunning())
return Plugin_Continue;
if (!IsValidClient(victim, true, false) || !IsValidClient(attacker, true, false))
{
return Plugin_Continue;
}
if ((victim != attacker) && ((GetClientTeam(victim) == GetClientTeam(attacker)) && (GetClientTeam(victim) == CS_TEAM_CT)))
{
return Plugin_Handled;
}
return Plugin_Continue;
}
/******************************************************************************
FORWARDS LISTENING
******************************************************************************/
public void FriendlyFire_OnConfigsExecuted()
{
// Get the Cvar Value
Cvar_tg_team_none_attack = FindConVar("tg_team_none_attack");
Cvar_tg_cvar_friendlyfire = FindConVar("tg_cvar_friendlyfire");
Cvar_tg_ct_friendlyfire = FindConVar("tg_ct_friendlyfire");
// Set custom Commands
int iCount = 0;
char sCommands[128], sCommandsL[12][32], sCommand[32];
// Friendly fire
gc_sCustomCommandFF.GetString(sCommands, sizeof(sCommands));
ReplaceString(sCommands, sizeof(sCommands), " ", "");
iCount = ExplodeString(sCommands, ",", sCommandsL, sizeof(sCommandsL), sizeof(sCommandsL[]));
for (int i = 0; i < iCount; i++)
{
Format(sCommand, sizeof(sCommand), "sm_%s", sCommandsL[i]);
if (!CommandExists(sCommand))
RegConsoleCmd(sCommand, Command_FriendlyFire, "Allows player to see the state and the Warden to toggle friendly fire");
}
}
public void FriendlyFire_OnClientPutInServer(int client)
{
SDKHook(client, SDKHook_TraceAttack, FriendlyFire_OnTraceAttack);
}
static int GetPlayerCount(bool alive = false, int team = -1)
{
int i, iCount = 0;
for (i = 1; i <= MaxClients; i++)
{
if (!IsValidClient(i,_, !alive))
continue;
if (gp_bDeadGames)
{
if(DeadGames_IsOnGame(i))
continue;
}
if (team != -1 && GetClientTeam(i) != team)
continue;
iCount++;
}
return iCount;
}