forked from ugurbayraktarr/Plugins-for-CSGO-Servers
-
Notifications
You must be signed in to change notification settings - Fork 3
/
abner_res.sp
567 lines (510 loc) · 14.1 KB
/
abner_res.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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
#include <sourcemod>
#include <sdktools>
#include <colors>
#include <clientprefs>
#include <cstrike>
//#pragma newdecls required // 2015 rules
#pragma semicolon 1
//MapSounds Stuff
int g_iSoundEnts[2048];
int g_iNumSounds;
//Cvars
Handle g_hCTPath;
Handle g_hTRPath;
Handle g_hPlayType;
Handle g_AbNeRCookie;
Handle g_hStop;
Handle g_roundDrawPlay;
bool clutch = false;
bool clutchIhtimali = false;
static int clutchTakimi = 1;
static int clutchSayisi = 0;
static int iClutch;
bool SoundsTRSucess = false;
bool SoundsCTSucess = false;
bool SamePath = false;
bool CSGO;
//Sounds Arrays
ArrayList ctSound;
ArrayList trSound;
new Handle:g_cVar_ClutchMuzikYolu = INVALID_HANDLE;
new Handle:g_PluginTagi = INVALID_HANDLE;
public Plugin myinfo =
{
name = "Gelişmiş Round Sonu Şarkıları",
author = "ImPossibLe`",
description = "Round Sonu Şarkıları",
version = "4.0"
}
public void OnPluginStart()
{
int ips[4];
char serverip[32];
int ip = GetConVarInt(FindConVar("hostip"));
ips[0] = (ip >> 24) & 0x000000FF;
ips[1] = (ip >> 16) & 0x000000FF;
ips[2] = (ip >> 8) & 0x000000FF;
ips[3] = ip & 0x000000FF;
Format(serverip, sizeof(serverip), "%d.%d.%d", ips[0], ips[1], ips[2]);
if(StrEqual(serverip, "185.193.165") == false && ips[3] != 166)
{
LogError("Bu plugin ImPossibLe` tarafindan lisanslandigi icin bu serverda calistirilmadi.");
PrintToChatAll(" \x04Bu plugin \x02ImPossibLe` \x04tarafından lisanslandığı için bu serverda çalıştırılmadı.");
SetFailState("Plugin Copyright by ImPossibLe`");
}
//Cvars
g_hTRPath = CreateConVar("res_tr_path", "misc/drkroundsonu", "Path off tr sounds in /cstrike/sound");
g_hCTPath = CreateConVar("res_ct_path", "misc/drkroundsonu", "Path off ct sounds in /cstrike/sound");
g_hPlayType = CreateConVar("res_play_type", "1", "1 - Random, 2- Play in queue");
g_hStop = CreateConVar("res_stop_map_music", "1", "Stop map musics");
g_roundDrawPlay = CreateConVar("res_rounddraw_play", "0", "0 - Don´t play sounds, 1 - Play TR sounds, 2 - Play CT sounds.");
//ClientPrefs
g_AbNeRCookie = RegClientCookie("AbNeR Round End Sounds", "", CookieAccess_Private);
SetCookieMenuItem(SoundCookieHandler, 0, "AbNeR Round End Sounds");
LoadTranslations("common.phrases");
LoadTranslations("abner_res.phrases");
AutoExecConfig(true, "abner_res");
RegAdminCmd("res_refresh", CommandLoad, ADMFLAG_SLAY);
RegConsoleCmd("res", abnermenu);
HookConVarChange(g_hTRPath, PathChange);
HookConVarChange(g_hCTPath, PathChange);
HookConVarChange(g_hPlayType, PathChange);
char theFolder[40];
GetGameFolderName(theFolder, sizeof(theFolder));
CSGO = StrEqual(theFolder, ("csgo"));
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("round_end", Event_RoundEnd);
HookEvent("player_death", Event_PlayerDeath, EventHookMode_Pre);
g_cVar_ClutchMuzikYolu = CreateConVar("drk_cluth_muzikyolu", "sound/misc/drkclutch/ClutchMuzigi.mp3", "Clutch muzigi yolunu giriniz. (Ornek: sound/misc/drkclutch/ClutchMuzigi.mp3)");
g_PluginTagi = CreateConVar("drk_plugin_taglari", "DrK # GaminG", "Pluginlerin basinda olmasini istediginiz tagi giriniz( [] olmadan )");
ctSound = new ArrayList(512);
trSound = new ArrayList(512);
new String:sClutchMuzikYolu[64];
GetConVarString(g_cVar_ClutchMuzikYolu, sClutchMuzikYolu, sizeof(sClutchMuzikYolu));
AddFileToDownloadsTable(sClutchMuzikYolu);
}
public Action Event_PlayerDeath(Event event, const char[] name, bool dontBroadcast)
{
if(!clutchIhtimali)
{
if(GetTeamClientCount(2) > 5 && GetTeamClientCount(3) > 5)
{
new i;
new yasayanT = 0, yasayanCT = 0;
for(i=1; i<MaxClients; i++)
{
if(IsClientInGame(i))
{
if(IsPlayerAlive(i))
{
if(GetClientTeam(i) == 2)
yasayanT++;
if(GetClientTeam(i) == 3)
yasayanCT++;
}
}
}
if(yasayanT == 1 && yasayanCT > 2)
{
clutchIhtimali = true;
clutchTakimi = 2;
clutchSayisi = yasayanCT;
for(i=1; i<MaxClients; i++)
{
if(IsClientInGame(i))
if(IsPlayerAlive(i) && GetClientTeam(i) == 2)
iClutch = i;
}
}
if(yasayanCT == 1 && yasayanT > 2)
{
clutchIhtimali = true;
clutchTakimi = 3;
clutchSayisi = yasayanT;
for(i=1; i<MaxClients; i++)
{
if(IsClientInGame(i))
if(IsPlayerAlive(i) && GetClientTeam(i) == 3)
iClutch = i;
}
}
}
}
}
stock bool IsValidClient(int client)
{
if(client <= 0 ) return false;
if(client > MaxClients) return false;
if(!IsClientConnected(client)) return false;
return IsClientInGame(client);
}
public void StopMapMusic()
{
char sSound[PLATFORM_MAX_PATH];
int entity = INVALID_ENT_REFERENCE;
for(int i=1;i<=MaxClients;i++){
if(!IsClientInGame(i)){ continue; }
for (int u=0; u<g_iNumSounds; u++){
entity = EntRefToEntIndex(g_iSoundEnts[u]);
if (entity != INVALID_ENT_REFERENCE){
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
Client_StopSound(i, entity, SNDCHAN_STATIC, sSound);
}
}
}
}
stock void Client_StopSound(int client, int entity, int channel, const char[] name)
{
EmitSoundToClient(client, name, entity, channel, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
}
public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
{
int winner = GetEventInt(event, "winner");
int reason = GetEventInt(event, "reason");
if(winner == clutchTakimi)
clutch = true;
if(view_as<CSRoundEndReason>(reason) == CSRoundEnd_Draw)
{
if(GetConVarInt(g_roundDrawPlay) == 1) winner = CS_TEAM_T;
else if(GetConVarInt(g_roundDrawPlay) == 2) winner = CS_TEAM_CT;
}
new String:sPluginTagi[64];
GetConVarString(g_PluginTagi, sPluginTagi, sizeof(sPluginTagi));
if((winner == CS_TEAM_CT && SamePath) || winner == CS_TEAM_T)
{
if(SoundsTRSucess)
{
PlaySoundTR();
}
else
{
if(!SamePath)
{
PrintToServer("[AbNeR RES] TR_SOUNDS ERROR: Sounds not loaded.");
PrintToChatAll("{red}[%s] {default}TR_SOUNDS ERROR: Sounds not loaded.", sPluginTagi);
}
else
{
PrintToServer("[AbNeR RES] SOUNDS ERROR: Sounds not loaded.");
PrintToChatAll("{red}[%s] {default}SOUNDS ERROR: Sounds not loaded.", sPluginTagi);
}
return;
}
}
else if(winner == CS_TEAM_CT)
{
if(SoundsCTSucess)
{
PlaySoundCT();
}
else
{
PrintToServer("[AbNeR RES] CT_SOUNDS ERROR: Sounds not loaded.");
return;
}
}
if(GetConVarInt(g_hStop) == 1)
StopMapMusic();
}
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
{
clutch = false;
clutchIhtimali = false;
clutchTakimi = 1;
clutchSayisi = 0;
if(GetConVarInt(g_hStop) == 1)
{
// Ents are recreated every round.
g_iNumSounds = 0;
// Find all ambient sounds played by the map.
char sSound[PLATFORM_MAX_PATH];
int entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
int len = strlen(sSound);
if (len > 4 && (StrEqual(sSound[len-3], "mp3") || StrEqual(sSound[len-3], "wav")))
{
g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
}
}
}
}
public void SoundCookieHandler(int client, CookieMenuAction action, any info, char[] buffer, int maxlen)
{
abnermenu(client, 0);
}
public Action abnermenu(int client, int args)
{
int cookievalue = GetIntCookie(client, g_AbNeRCookie);
Handle g_AbNeRMenu = CreateMenu(AbNeRMenuHandler);
SetMenuTitle(g_AbNeRMenu, "Round Sonu Sarkilari");
char Item[128];
if(cookievalue == 0)
{
Format(Item, sizeof(Item), "%t %t", "RES_ON", "Selected");
AddMenuItem(g_AbNeRMenu, "ON", Item);
Format(Item, sizeof(Item), "%t", "RES_OFF");
AddMenuItem(g_AbNeRMenu, "OFF", Item);
}
else
{
Format(Item, sizeof(Item), "%t", "RES_ON");
AddMenuItem(g_AbNeRMenu, "ON", Item);
Format(Item, sizeof(Item), "%t %t", "RES_OFF", "Selected");
AddMenuItem(g_AbNeRMenu, "OFF", Item);
}
SetMenuExitBackButton(g_AbNeRMenu, true);
SetMenuExitButton(g_AbNeRMenu, true);
DisplayMenu(g_AbNeRMenu, client, 30);
}
public int AbNeRMenuHandler(Handle menu, MenuAction action, int param1, int param2)
{
Handle g_AbNeRMenu = CreateMenu(AbNeRMenuHandler);
if (action == MenuAction_DrawItem)
{
return ITEMDRAW_DEFAULT;
}
else if(param2 == MenuCancel_ExitBack)
{
ShowCookieMenu(param1);
}
else if (action == MenuAction_Select)
{
switch (param2)
{
case 0:
{
SetClientCookie(param1, g_AbNeRCookie, "0");
abnermenu(param1, 0);
}
case 1:
{
SetClientCookie(param1, g_AbNeRCookie, "1");
abnermenu(param1, 0);
}
}
CloseHandle(g_AbNeRMenu);
}
return 0;
}
public void PathChange(Handle cvar, const char[] oldVal, const char[] newVal)
{
RefreshSounds(0);
}
public void OnConfigsExecuted()
{
RefreshSounds(0);
}
void RefreshSounds(int client)
{
char soundpath[PLATFORM_MAX_PATH];
char soundpath2[PLATFORM_MAX_PATH];
GetConVarString(g_hTRPath, soundpath, sizeof(soundpath));
GetConVarString(g_hCTPath, soundpath2, sizeof(soundpath2));
SamePath = StrEqual(soundpath, soundpath2);
int size;
if(SamePath)
{
size = LoadSoundsTR();
SoundsTRSucess = (size > 0);
if(SoundsTRSucess)
{
ReplyToCommand(client, "[AbNeR RES] SOUNDS: %d sounds loaded.", size);
}
else
{
ReplyToCommand(client, "[AbNeR RES] INVALID SOUND PATH.");
}
}
else
{
size = LoadSoundsTR();
SoundsTRSucess = (size > 0);
if(SoundsTRSucess)
{
ReplyToCommand(client, "[AbNeR RES] TR_SOUNDS: %d sounds loaded.", size);
}
else
{
ReplyToCommand(client, "[AbNeR RES] INVALID TR SOUND PATH.");
}
size = LoadSoundsCT();
SoundsCTSucess = (size > 0);
if(SoundsCTSucess)
{
ReplyToCommand(client, "[AbNeR RES] CT_SOUNDS: %d sounds loaded.", size);
}
else
{
ReplyToCommand(client, "[AbNeR RES] INVALID CT SOUND PATH.");
}
}
}
int LoadSoundsCT()
{
ctSound.Clear();
char name[128];
char soundname[512];
char soundpath[PLATFORM_MAX_PATH];
char soundpath2[PLATFORM_MAX_PATH];
GetConVarString(g_hCTPath, soundpath, sizeof(soundpath));
Format(soundpath2, sizeof(soundpath2), "sound/%s/", soundpath);
Handle pluginsdir = OpenDirectory(soundpath2);
SoundsCTSucess = (pluginsdir != INVALID_HANDLE);
if(SoundsCTSucess)
{
while(ReadDirEntry(pluginsdir,name,sizeof(name)))
{
int namelen = strlen(name) - 4;
if(StrContains(name,".mp3",false) == namelen)
{
Format(soundname, sizeof(soundname), "sound/%s/%s", soundpath, name);
AddFileToDownloadsTable(soundname);
Format(soundname, sizeof(soundname), "%s/%s", soundpath, name);
ctSound.PushString(soundname);
}
}
}
return ctSound.Length;
}
int LoadSoundsTR()
{
trSound.Clear();
char name[128];
char soundname[512];
char soundpath[PLATFORM_MAX_PATH];
char soundpath2[PLATFORM_MAX_PATH];
GetConVarString(g_hTRPath, soundpath, sizeof(soundpath));
Format(soundpath2, sizeof(soundpath2), "sound/%s/", soundpath);
Handle pluginsdir = OpenDirectory(soundpath2);
SoundsCTSucess = (pluginsdir != INVALID_HANDLE);
if(SoundsCTSucess)
{
while(ReadDirEntry(pluginsdir,name,sizeof(name)))
{
int namelen = strlen(name) - 4;
if(StrContains(name,".mp3",false) == namelen)
{
Format(soundname, sizeof(soundname), "sound/%s/%s", soundpath, name);
AddFileToDownloadsTable(soundname);
Format(soundname, sizeof(soundname), "%s/%s", soundpath, name);
trSound.PushString(soundname);
}
}
}
return trSound.Length;
}
void PlaySoundCT()
{
int soundToPlay;
if(GetConVarInt(g_hPlayType) == 1)
{
soundToPlay = GetRandomInt(0, ctSound.Length-1);
}
else
{
soundToPlay = 0;
}
char szSound[128];
ctSound.GetString(soundToPlay, szSound, sizeof(szSound));
ctSound.Erase(soundToPlay);
PlayMusicAll(szSound);
if(ctSound.Length == 0)
LoadSoundsCT();
}
void PlaySoundTR()
{
int soundToPlay;
if(GetConVarInt(g_hPlayType) == 1)
{
soundToPlay = GetRandomInt(0, trSound.Length-1);
}
else
{
soundToPlay = 0;
}
char szSound[128];
trSound.GetString(soundToPlay, szSound, sizeof(szSound));
trSound.Erase(soundToPlay);
PlayMusicAll(szSound);
if(trSound.Length == 0)
LoadSoundsTR();
}
void PlayMusicAll(char[] szSound)
{
if(CSGO)
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetIntCookie(i, g_AbNeRCookie) == 0)
{
if(!clutch)
{
ClientCommand(i, "playgamesound Music.StopAllMusic");
ClientCommand(i, "play \"*%s\"", szSound);
//EmitSoundToClient( i, szSound );
}
else if(clutch)
{
new String:sClutchMuzikYolu[64];
GetConVarString(g_cVar_ClutchMuzikYolu, sClutchMuzikYolu, sizeof(sClutchMuzikYolu));
ClientCommand(i, "playgamesound Music.StopAllMusic");
ClientCommand(i, "play \"*%s\"", sClutchMuzikYolu);
}
}
}
}
else
{
for (int i = 1; i <= MaxClients; i++)
{
if(IsValidClient(i) && GetIntCookie(i, g_AbNeRCookie) == 0)
{
ClientCommand(i, "play \"*%s\"", szSound);
}
}
}
char sarkiIsmiYazdir[128];
int k = 0, j = 0;
int klasorGec = 0;
new String:sPluginTagi[64];
GetConVarString(g_PluginTagi, sPluginTagi, sizeof(sPluginTagi));
while( szSound[k + 4] != '\0' )
{
if(klasorGec < 2)
{
if(szSound[k] == '\\' || szSound[k] == '/')
klasorGec++;
}
else
{
sarkiIsmiYazdir[j] = szSound[k];
j++;
}
k++;
}
if(!clutch)
{
PrintToChatAll(" \x02[%s] \x0EŞuan Çalınan:\n \x10%s", sPluginTagi, sarkiIsmiYazdir);
}
else if(clutch)
{
decl String:clutchIsim[32];
GetClientName(iClutch, clutchIsim, sizeof(clutchIsim));
PrintToChatAll(" \x02[%s] \x04%s \x03, \x0C1 v %d \x10Clutch Atmıştır, \x04Tebrikler!", sPluginTagi, clutchIsim, clutchSayisi);
PrintCenterTextAll("<font color='#FF0000'>[%s]</font> <font color='#00FF00'>%s</font>\n<font color='#ff7700'>1 v %d</font> <font color='#00FFFF'>Clutch atmıştır, Tebrikler!</font>",sPluginTagi, clutchIsim, clutchSayisi);
PrintToChatAll(" \x02[%s] \x10Şuan Çalınan:\n \x04Clutch Müziği", sPluginTagi);
}
}
public Action CommandLoad(int client, int args)
{
RefreshSounds(client);
return Plugin_Handled;
}
int GetIntCookie(int client, Handle handle)
{
char sCookieValue[11];
GetClientCookie(client, handle, sCookieValue, sizeof(sCookieValue));
return StringToInt(sCookieValue);
}