forked from Walderr/ZE-Plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SelfMute.sp
439 lines (385 loc) · 11.6 KB
/
SelfMute.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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#include <sourcemod>
#include <sdktools>
#include <adminmenu>
int spamMutes = 4;
bool MuteStatus[MAXPLAYERS+1][MAXPLAYERS+1];
public Plugin myinfo =
{
name = "Self-Mute",
author = "Otokiru, IT-KiLLER, Walderr edit",
description = "Mute player just for you.",
version = "Original: 1.0 JAZE: 1.1",
url = "www.xose.net"
}
public void OnPluginStart()
{
LoadTranslations("common.phrases");
LoadTranslations("SelfMute.phrases");
RegConsoleCmd("sm_sm", selfMute, "Mute player by typing !selfmute [playername]");
RegConsoleCmd("sm_selfmute", selfMute, "Mute player by typing !sm [playername]");
RegConsoleCmd("sm_su", selfUnmute, "Unmute player by typing !su [playername]");
RegConsoleCmd("sm_selfunmute", selfUnmute, "Unmute player by typing !selfunmute [playername]");
}
public void OnPluginEnd()
{
for(int client = 1; client <= MaxClients; client++)
{
for(int target = 1; target <= MaxClients; target++)
{
if(IsClientInGame(client) && IsClientInGame(target))
{
SetListenOverride(client, target, Listen_Default);
}
}
}
}
public void OnClientPutInServer(int client)
{
for (int target = 1; target <= MaxClients; target++)
{
MuteStatus[target][client] = false;
if(target != client && IsClientInGame(target))
{
SetListenOverride(target, client, Listen_Default);
}
}
}
//====================================================================================================
public Action selfMute(int client, int args)
{
// Если команда введена из консоли, выходим.
if(!client) return Plugin_Handled;
if(!args)
{
DisplayMuteMenu(client);
return Plugin_Handled;
}
char strTarget[MAX_NAME_LENGTH];
GetCmdArg(1, strTarget, sizeof(strTarget));
if(StrEqual(strTarget, "@me"))
{
PrintToChat(client, "%t", "Cannot_Mute_Yourself");
return Plugin_Handled;
}
char strTargetName[MAX_TARGET_LENGTH];
int TargetList[MAXPLAYERS], TargetCount;
bool TargetTranslate;
if ((TargetCount = ProcessTargetString(strTarget, 0, TargetList, MAXPLAYERS, COMMAND_FILTER_CONNECTED | COMMAND_FILTER_NO_BOTS , strTargetName, sizeof(strTargetName), TargetTranslate)) <= 0)
{
ReplyToTargetError(client, TargetCount);
return Plugin_Handled;
}
muteTargetedPlayers(client, TargetList, TargetCount, strTarget);
return Plugin_Handled;
}
stock void DisplayMuteMenu(int client)
{
SetGlobalTransTarget(client);
Menu menu = CreateMenu(MenuHandler_MuteMenu);
menu.SetTitle("%T", "SelfMute_Menu_Title", client);
// Здесь будут игроки, добавленные в меню.
bool clientAlreadyListed[MAXPLAYERS+1] = {false,...};
// Убираем клиента из меню.
clientAlreadyListed[client] = true;
char strClientID[12];
char strClientName[50];
// Добавляем в меню игроков, которые уже кем-то заблокированы.
for(int target = 1; target <= MaxClients; target++)
{
if(IsClientInGame(target) && !clientAlreadyListed[target] && !MuteStatus[client][target] && targetMutes(target, true) > 0 && !IsFakeClient(target))
{
if(targetMutes(target, true) < spamMutes)
{
FormatEx(strClientName, sizeof(strClientName), "%t", "Menu_Name_Mutes", target, targetMutes(target, true));
}
else
{
FormatEx(strClientName, sizeof(strClientName), "%t", "Menu_Name_Spamer", target, targetMutes(target, true));
}
clientAlreadyListed[target] = true;
IntToString(GetClientUserId(target), strClientID, sizeof(strClientID));
menu.AddItem(strClientID, strClientName);
}
}
// Добавляем в меню остальных игроков.
for(int i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && !clientAlreadyListed[i] && !MuteStatus[client][i] && !IsFakeClient(i))
{
IntToString(GetClientUserId(i), strClientID, sizeof(strClientID));
FormatEx(strClientName, sizeof(strClientName), "%N", i);
menu.AddItem(strClientID, strClientName);
}
}
// Если нет подходящих игроков
if(menu.ItemCount == 0)
{
PrintToChat(client, "%t", "Could_Not_Mute", clientMutes(client));
delete(menu);
}
// Иначе показываем клиенту меню.
else DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
public int MenuHandler_MuteMenu(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_End:
{
CloseHandle(menu);
}
case MenuAction_Select:
{
char info[32];
int target;
GetMenuItem(menu, param2, info, sizeof(info));
int userid = StringToInt(info);
if((target = GetClientOfUserId(userid)) == 0)
{
PrintToChat(param1, "%t", "Player_No_Longer_Available");
}
else
{
// This will be improved in a later update
int temp[1];
temp[0] = target;
muteTargetedPlayers(param1, temp, 1, "");
}
DisplayMuteMenu(param1);
}
}
}
public void muteTargetedPlayers(int client, int[] list, int TargetCount, const char[] filtername)
{
if(TargetCount == 1)
{
int target = list[0];
if(client == target)
{
PrintToChat(client, "%t", "Cannot_Mute_Yourself");
return;
}
SetListenOverride(client, target, Listen_No);
PrintToChat(client, "%t", "Self_Muted", target);
MuteStatus[client][target] = true;
}
else if(TargetCount > 1)
{
char textNames[250];
int textSize = 0, countTargets = 0;
int target;
for(int i = 0; i < TargetCount; i++)
{
target = list[i];
if(target == client || MuteStatus[client][target]) continue;
countTargets++;
MuteStatus[client][target] = true;
SetListenOverride(client, target, Listen_No);
FormatEx(textNames, sizeof(textNames), "%s%s%N", textNames, countTargets==1 ? "" : ", ", target);
textSize = strlen(textNames) - textSize;
}
if(countTargets > 0)
{
PrintToChat(client, "%t", "Self_Muted_Multi", countTargets , (textSize <= sizeof(textNames) && countTargets <= 14 ) ? textNames : getFilterName(filtername, client));
}
else
{
PrintToChat(client, "%t", "All_Already_SelfMuted");
}
}
}
//====================================================================================================
public Action selfUnmute(int client, int args)
{
// Если команда введена из консоли, выходим.
if(!client) return Plugin_Handled;
if(!args)
{
DisplayUnMuteMenu(client);
return Plugin_Handled;
}
char strTarget[MAX_NAME_LENGTH];
GetCmdArg(1, strTarget, sizeof(strTarget));
if(StrEqual(strTarget, "@me"))
{
PrintToChat(client, "%t", "Cannot_UnMute_Yourself");
return Plugin_Handled;
}
char strTargetName[MAX_TARGET_LENGTH];
int TargetList[MAXPLAYERS], TargetCount;
bool TargetTranslate;
if((TargetCount = ProcessTargetString(strTarget, 0, TargetList, MAXPLAYERS, COMMAND_FILTER_CONNECTED | COMMAND_FILTER_NO_BOTS, strTargetName, sizeof(strTargetName), TargetTranslate)) <= 0)
{
ReplyToTargetError(client, TargetCount);
return Plugin_Handled;
}
unMuteTargetedPlayers(client, TargetList, TargetCount, strTarget);
return Plugin_Handled;
}
stock void DisplayUnMuteMenu(int client)
{
SetGlobalTransTarget(client);
Menu menu = CreateMenu(MenuHandler_UnMuteMenu);
menu.SetTitle("%T", "SelfUnMute_Menu_Title", client);
char strClientID[12];
char strClientName[50];
for(int target = 1; target <= MaxClients; target++)
{
if(client != target && IsClientInGame(target) && MuteStatus[client][target] && !IsFakeClient(target))
{
IntToString(GetClientUserId(target), strClientID, sizeof(strClientID));
FormatEx(strClientName, sizeof(strClientName), "%N (M)", target);
menu.AddItem(strClientID, strClientName);
}
}
if(menu.ItemCount == 0)
{
PrintToChat(client, "%t", "No_Muted_Players");
delete(menu);
}
else
{
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
}
public int MenuHandler_UnMuteMenu(Menu menu, MenuAction action, int param1, int param2)
{
switch(action)
{
case MenuAction_End:
{
delete(menu);
}
case MenuAction_Select:
{
char info[32];
int target;
GetMenuItem(menu, param2, info, sizeof(info));
int userid = StringToInt(info);
if((target = GetClientOfUserId(userid)) == 0)
{
PrintToChat(param1, "%t", "Player_No_Longer_Available");
}
else
{
// This will be improved in a later update
int temp[1];
temp[0] = target;
unMuteTargetedPlayers(param1, temp, 1, "");
}
DisplayUnMuteMenu(param1);
}
}
}
public void unMuteTargetedPlayers(int client, int[] list, int TargetCount, const char[] filtername)
{
if(TargetCount == 1)
{
int target = list[0];
if(client == target)
{
PrintToChat(client, "%t", "Cannot_UnMute_Yourself");
return;
}
SetListenOverride(client, target, Listen_Default);
PrintToChat(client, "%t", "Self_UnMuted", target);
MuteStatus[client][target] = false;
}
else if(TargetCount > 1)
{
char textNames[250];
int textSize = 0, countTargets = 0;
int target;
for(int i = 0; i < TargetCount; i++)
{
target = list[i];
if (target == client || !MuteStatus[client][target]) continue;
countTargets++;
SetListenOverride(client, target, Listen_Default);
MuteStatus[client][target] = false;
FormatEx(textNames, sizeof(textNames), "%s%s%N", textNames, countTargets==1 ? "" : ", ", target);
textSize = strlen(textNames) - textSize;
}
if(countTargets > 0)
{
PrintToChat(client, "%t", "Self_UnMuted_Multi", countTargets , (textSize <= sizeof(textNames) && countTargets <= 14 ) ? textNames : getFilterName(filtername, client));
}
else
{
PrintToChat(client, "%t", "All_Already_SelfUnMuted");
}
}
}
//====================================================================================================
// Checking if a client is admin
stock bool IsPlayerAdmin(int client)
{
if(CheckCommandAccess(client, "Kick_admin", ADMFLAG_KICK, false))
{
return true;
}
return false;
}
// Counting how many mutes a client has done.
stock int clientMutes(int client)
{
int count=0;
for(int target = 1; target <= MaxClients ; target++)
{
if(MuteStatus[client][target]) count++;
}
return count;
}
// Counting how many mutes a target has received.
stock int targetMutes(int target, bool massivemute = false)
{
int count = 0, mutes = 0;
for(int client = 1; client <= MaxClients ; client++)
{
if(MuteStatus[client][target] && (massivemute && (mutes=clientMutes(client)) > 0 && mutes <= (MaxClients/2))) count++;
}
return count;
}
stock char getFilterName(const char[] filter, int client)
{
SetGlobalTransTarget(client);
// This will be improved in a later update
char temp[32];
if (StrEqual(filter, "@all"))
{
FormatEx(temp, sizeof(temp), "%t", "Everyone");
}
else if (StrEqual(filter, "@spec"))
{
FormatEx(temp, sizeof(temp), "%t", "Spectators");
}
else if (StrEqual(filter, "@ct"))
{
FormatEx(temp, sizeof(temp), "%t", "Counter-Terrorists");
}
else if (StrEqual(filter, "@t"))
{
FormatEx(temp, sizeof(temp), "%t", "Terrorists");
}
else if (StrEqual(filter, "@dead"))
{
FormatEx(temp, sizeof(temp), "%t", "Dead players");
}
else if (StrEqual(filter, "@alive"))
{
FormatEx(temp, sizeof(temp), "%t", "Alive players");
}
else if (StrEqual(filter, "@!me"))
{
FormatEx(temp, sizeof(temp), "%t", "Everyone except me");
}
else if (StrEqual(filter, "@admins"))
{
FormatEx(temp, sizeof(temp), "%t", "Admins");
}
else
{
FormatEx(temp, sizeof(temp), "%s", filter);
}
return temp;
}