This repository has been archived by the owner on May 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
bTimes-random.sp
1248 lines (1056 loc) · 32.5 KB
/
bTimes-random.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
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma semicolon 1
#include <bTimes-core>
public Plugin:myinfo =
{
name = "[bTimes] Random",
author = "blacky, cam",
description = "Handles events and modifies them to fit bTimes' needs",
version = VERSION,
url = URL
}
#include <sourcemod>
#include <sdktools>
#include <cstrike>
#include <sdkhooks>
#include <bTimes-timer>
#include <bTimes-zones>
#include <bTimes-random>
#include <clientprefs>
/*
#undef REQUIRE_PLUGIN
#include <bTimes-gunjump>
*/
#define HUD_OFF (1<<0|1<<3|1<<4|1<<8)
#define HUD_ON 0
#define HUD_FUCK (1<<0|1<<1|1<<2|1<<3|1<<4|1<<5|1<<6|1<<7|1<<8|1<<9|1<<10|1<<11)
new g_Settings[MAXPLAYERS+1] = {SHOW_HINT, ...},
bool:g_bHooked;
new Float:g_fMapStart;
new Handle:g_hSettingsCookie;
new g_iSoundEnts[2048];
new g_iNumSounds;
// Settings
new Handle:g_hAllowKeysAlive,
Handle:g_hKeysShowsJumps,
Handle:g_hAllowKnifeDrop,
Handle:g_WeaponDespawn,
Handle:g_hNoDamage,
Handle:g_hAllowHide;
new Handle:g_MessageStart,
Handle:g_MessageVar,
Handle:g_MessageText,
Handle:g_fwdChatChanged;
new String:g_msg_start[128] = {""};
new String:g_msg_varcol[128] = {"\x07B4D398"};
new String:g_msg_textcol[128] = {"\x01"};
//new bool:g_TimerGunJump;
public OnPluginStart(){
if(GetGameType() != GameType_CSGO && GetGameType() != GameType_CSS)
SetFailState("This timer does not support this game (%d)", GetGameType());
// Server settings
g_hAllowKeysAlive = CreateConVar("timer_allowkeysalive", "1", "Allows players to see !keys while alive.", 0, true, 0.0, true, 1.0);
g_hKeysShowsJumps = CreateConVar("timer_keysshowsjumps", "1", "The !keys features shows when a player is using their jump button.", 0, true, 0.0, true, 1.0);
g_hAllowKnifeDrop = CreateConVar("timer_allowknifedrop", "1", "Allows players to drop any weapons (including knives and grenades)", 0, true, 0.0, true, 1.0);
g_WeaponDespawn = CreateConVar("timer_weapondespawn", "1", "Kills weapons a second after spawning to prevent flooding server.", 0, true, 0.0, true, 1.0);
g_hNoDamage = CreateConVar("timer_nodamage", "1", "Blocks all player damage when on", 0, true, 0.0, true, 1.0);
g_hAllowHide = CreateConVar("timer_allowhide", "1", "Allows players to use the !hide command", 0, true, 0.0, true, 1.0);
if(GetGameType() == GameType_CSS)
{
g_MessageStart = CreateConVar("timer_msgstart", "^556b2f[Timer] ^daa520- ", "Sets the start of all timer messages.");
g_MessageVar = CreateConVar("timer_msgvar", "^B4D398", "Sets the color of variables in timer messages such as player names.");
g_MessageText = CreateConVar("timer_msgtext", "^DAA520", "Sets the color of general text in timer messages.");
}
else if(GetGameType() == GameType_CSGO)
{
g_MessageStart = CreateConVar("timer_msgstart", "^3^A^3[^4Timer^3] ^2- ", "Sets the start of all timer messages. (Always keep the ^A after the first color code)");
g_MessageVar = CreateConVar("timer_msgvar", "^4", "Sets the color of variables in timer messages such as player names.");
g_MessageText = CreateConVar("timer_msgtext", "^5", "Sets the color of general text in timer messages.");
}
// Hook specific convars
HookConVarChange(g_MessageStart, OnMessageStartChanged);
HookConVarChange(g_MessageVar, OnMessageVarChanged);
HookConVarChange(g_MessageText, OnMessageTextChanged);
HookConVarChange(g_hNoDamage, OnNoDamageChanged);
HookConVarChange(g_hAllowHide, OnAllowHideChanged);
// Create config file if it doesn't exist
AutoExecConfig(true, "random", "timer");
// Event hooks
HookEvent("player_spawn", Event_PlayerSpawn_Post, EventHookMode_Post);
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
AddNormalSoundHook(NormalSHook);
AddAmbientSoundHook(AmbientSHook);
AddTempEntHook("Shotgun Shot", CSS_Hook_ShotgunShot);
// Command hooks
AddCommandListener(DropItem, "drop");
// Player commands
RegConsoleCmdEx("sm_hide", SM_Hide, "Toggles hide");
RegConsoleCmdEx("sm_unhide", SM_Hide, "Toggles hide");
RegConsoleCmdEx("sm_keys", SM_Keys, "Toggles showing pressed keys");
RegConsoleCmdEx("sm_pad", SM_Keys, "Toggles showing pressed keys");
RegConsoleCmdEx("sm_showkeys", SM_Keys, "Toggles showing pressed keys");
RegConsoleCmdEx("sm_skeys", SM_Keys, "Toggles showing pressed keys");
RegConsoleCmdEx("sm_spec", SM_Spec, "Be a spectator");
RegConsoleCmdEx("sm_spectate", SM_Spec, "Be a spectator");
RegConsoleCmdEx("sm_maptime", SM_Maptime, "Shows how long the current map has been on.");
RegConsoleCmdEx("sm_sound", SM_Sound, "Choose different sounds to stop when they play.");
RegConsoleCmdEx("sm_sounds", SM_Sound, "Choose different sounds to stop when they play.");
RegConsoleCmdEx("sm_specinfo", SM_Specinfo, "Shows who is spectating you.");
RegConsoleCmdEx("sm_specs", SM_Specinfo, "Shows who is spectating you.");
RegConsoleCmdEx("sm_speclist", SM_Specinfo, "Shows who is spectating you.");
RegConsoleCmdEx("sm_spectators", SM_Specinfo, "Shows who is spectating you.");
RegConsoleCmdEx("sm_normalspeed", SM_Normalspeed, "Sets your speed to normal speed.");
RegConsoleCmdEx("sm_speed", SM_Speed, "Changes your speed to the specified value.");
RegConsoleCmdEx("sm_setspeed", SM_Speed, "Changes your speed to the specified value.");
if(GetGameType() != GameType_CSGO){
RegConsoleCmdEx("sm_slow", SM_Slow, "Sets your speed to slow (0.5)");
RegConsoleCmdEx("sm_fast", SM_Fast, "Sets your speed to fast (2.0)");
RegConsoleCmdEx("sm_lowgrav", SM_Lowgrav, "Lowers your gravity.");
RegConsoleCmdEx("sm_normalgrav", SM_Normalgrav, "Sets your gravity to normal.");
}else if(GetGameType() == GameType_CSGO){
RegConsoleCmdEx("sm_flashlight", SM_FlashLight, "Enables or disables the flashlight");
}
// Admin commands
RegAdminCmd("sm_move", SM_Move, ADMFLAG_CUSTOM5, "For getting players out of places they are stuck in");
RegAdminCmd("sm_hudfuck", SM_Hudfuck, ADMFLAG_CUSTOM5, "Removes a player's hud so they can only leave the server/game through task manager (Use only on players who deserve it)");
RegAdminCmd("sm_randomplayer", SM_SelectRandom, ADMFLAG_ROOT, "Selects a random player in the server");
// Client settings
g_hSettingsCookie = RegClientCookie("timer", "Timer settings", CookieAccess_Public);
// Makes FindTarget() work properly..
LoadTranslations("common.phrases");
}
public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max)
{
// Native functions
CreateNative("GetClientSettings", Native_GetClientSettings);
CreateNative("SetClientSettings", Native_SetClientSettings);
// Forwards
g_fwdChatChanged = CreateGlobalForward("OnTimerChatChanged", ET_Event, Param_Cell, Param_String);
return APLRes_Success;
}
/*
public OnAllPluginsLoaded()
{
if(LibraryExists("gunjump"))
{
g_TimerGunJump = true;
}
}
*/
public OnMapStart()
{
//set map start time
g_fMapStart = GetEngineTime();
}
public OnClientPutInServer(client)
{
// for !hide
if(GetConVarBool(g_hAllowHide))
{
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
}
// prevents damage
if(GetConVarBool(g_hNoDamage))
{
SDKHook(client, SDKHook_OnTakeDamage, Hook_OnTakeDamage);
}
}
public OnNoDamageChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
for(new client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
{
if(newValue[0] == '0')
{
SDKUnhook(client, SDKHook_OnTakeDamage, Hook_OnTakeDamage);
}
else
{
SDKHook(client, SDKHook_OnTakeDamage, Hook_OnTakeDamage);
}
}
}
}
public OnAllowHideChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
for(new client = 1; client <= MaxClients; client++)
{
if(IsClientInGame(client))
{
if(newValue[0] == '0')
{
SDKUnhook(client, SDKHook_SetTransmit, Hook_SetTransmit);
}
else
{
SDKHook(client, SDKHook_SetTransmit, Hook_SetTransmit);
}
}
}
}
public OnClientDisconnect_Post(client)
{
CheckHooks();
}
public OnClientCookiesCached(client)
{
// get client settings
decl String:cookies[16];
GetClientCookie(client, g_hSettingsCookie, cookies, sizeof(cookies));
if(strlen(cookies) == 0)
{
g_Settings[client] = SHOW_HINT|AUTO_BHOP|KH_TIMELEFT|KH_SYNC|KH_RECORD|KH_BEST|KH_SPECS;
}
else
{
g_Settings[client] = StringToInt(cookies);
}
if((g_Settings[client] & STOP_GUNS) && g_bHooked == false)
{
g_bHooked = true;
}
}
public OnConfigsExecuted()
{
// load timer message colors
GetConVarString(g_MessageStart, g_msg_start, sizeof(g_msg_start));
Call_StartForward(g_fwdChatChanged);
Call_PushCell(0);
Call_PushString(g_msg_start);
Call_Finish();
GetConVarString(g_MessageVar, g_msg_varcol, sizeof(g_msg_varcol));
Call_StartForward(g_fwdChatChanged);
Call_PushCell(1);
Call_PushString(g_msg_varcol);
Call_Finish();
GetConVarString(g_MessageText, g_msg_textcol, sizeof(g_msg_textcol));
Call_StartForward(g_fwdChatChanged);
Call_PushCell(2);
Call_PushString(g_msg_textcol);
Call_Finish();
}
public OnTimerChatChanged(MessageType, String:Message[])
{
if(MessageType == 0)
{
Format(g_msg_start, sizeof(g_msg_start), Message);
ReplaceMessage(g_msg_start, sizeof(g_msg_start));
}
else if(MessageType == 1)
{
Format(g_msg_varcol, sizeof(g_msg_varcol), Message);
ReplaceMessage(g_msg_varcol, sizeof(g_msg_varcol));
}
else if(MessageType == 2)
{
Format(g_msg_textcol, sizeof(g_msg_textcol), Message);
ReplaceMessage(g_msg_textcol, sizeof(g_msg_textcol));
}
}
public OnMessageStartChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
GetConVarString(g_MessageStart, g_msg_start, sizeof(g_msg_start));
Call_StartForward(g_fwdChatChanged);
Call_PushCell(0);
Call_PushString(g_msg_start);
Call_Finish();
ReplaceString(g_msg_start, sizeof(g_msg_start), "^", "\x07", false);
}
public OnMessageVarChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
GetConVarString(g_MessageVar, g_msg_varcol, sizeof(g_msg_varcol));
Call_StartForward(g_fwdChatChanged);
Call_PushCell(1);
Call_PushString(g_msg_varcol);
Call_Finish();
ReplaceString(g_msg_varcol, sizeof(g_msg_varcol), "^", "\x07", false);
}
public OnMessageTextChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
GetConVarString(g_MessageText, g_msg_textcol, sizeof(g_msg_textcol));
Call_StartForward(g_fwdChatChanged);
Call_PushCell(2);
Call_PushString(g_msg_textcol);
Call_Finish();
ReplaceString(g_msg_textcol, sizeof(g_msg_textcol), "^", "\x07", false);
}
public Action:Timer_StopMusic(Handle:timer, any:data)
{
new ientity, String:sSound[128];
for (new i = 0; i < g_iNumSounds; i++)
{
ientity = EntRefToEntIndex(g_iSoundEnts[i]);
if (ientity != INVALID_ENT_REFERENCE)
{
for(new client=1; client<=MaxClients; client++)
{
if(IsClientInGame(client))
{
if(g_Settings[client] & STOP_MUSIC)
{
GetEntPropString(ientity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
EmitSoundToClient(client, sSound, ientity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
}
}
}
}
}
}
// Credits to GoD-Tony for everything related to stopping gun sounds
public Action:CSS_Hook_ShotgunShot(const String:te_name[], const Players[], numClients, Float:delay)
{
if(!g_bHooked)
return Plugin_Continue;
// Check which clients need to be excluded.
decl newClients[MaxClients], client, i;
new newTotal = 0;
for (i = 0; i < numClients; i++)
{
client = Players[i];
if(!(g_Settings[client] & STOP_GUNS) || !(g_Settings[client] & HIDE_PLAYERS))
newClients[newTotal++] = client;
}
// No clients were excluded.
if (newTotal == numClients)
return Plugin_Continue;
// All clients were excluded and there is no need to broadcast.
else if (newTotal == 0)
return Plugin_Stop;
// Re-broadcast to clients that still need it.
decl Float:vTemp[3];
TE_Start("Shotgun Shot");
TE_ReadVector("m_vecOrigin", vTemp);
TE_WriteVector("m_vecOrigin", vTemp);
TE_WriteFloat("m_vecAngles[0]", TE_ReadFloat("m_vecAngles[0]"));
TE_WriteFloat("m_vecAngles[1]", TE_ReadFloat("m_vecAngles[1]"));
TE_WriteNum("m_iWeaponID", TE_ReadNum("m_iWeaponID"));
TE_WriteNum("m_iMode", TE_ReadNum("m_iMode"));
TE_WriteNum("m_iSeed", TE_ReadNum("m_iSeed"));
TE_WriteNum("m_iPlayer", TE_ReadNum("m_iPlayer"));
TE_WriteFloat("m_fInaccuracy", TE_ReadFloat("m_fInaccuracy"));
TE_WriteFloat("m_fSpread", TE_ReadFloat("m_fSpread"));
TE_Send(newClients, newTotal, delay);
return Plugin_Stop;
}
CheckHooks()
{
new bool:bShouldHook = false;
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i))
{
if(g_Settings[i] & STOP_GUNS)
{
bShouldHook = true;
break;
}
}
}
// Fake (un)hook because toggling actual hooks will cause server instability.
g_bHooked = bShouldHook;
}
public Action:AmbientSHook(String:sample[PLATFORM_MAX_PATH], &entity, &Float:volume, &level, &pitch, Float:pos[3], &flags, &Float:delay){
// Stop music next frame
CreateTimer(0.0, Timer_StopMusic);
}
public Action:NormalSHook(clients[64], &numClients, String:sample[PLATFORM_MAX_PATH], &entity, &channel, &Float:volume, &level, &pitch, &flags){
//PrintToServer("[SOUND DEBUG] Sound played: %s", sample);
if(0 < entity <= MaxClients && IsClientConnected(entity) && IsPlayerAlive(entity) &&
((StrContains(sample, "player/damage", false) != -1)
|| (StrContains(sample, "player/footstep", false) != -1)
|| (StrContains(sample, "physics/", false) != -1)
|| (StrContains(sample, "player/death", false) != -1)
|| (StrContains(sample, "player/land", false) != -1)))
{
for (new i = 0; i < numClients; i++)
{
if(g_Settings[clients[i]] & HIDE_PLAYERS)
{
for (new j = i; j < numClients-1; j++)
{
clients[j] = clients[j+1];
}
numClients--;
i--;
}
}
}
if(IsValidEntity(entity) && IsValidEdict(entity)){
decl String:sClassName[128];
GetEntityClassname(entity, sClassName, sizeof(sClassName));
new iSoundType;
if(StrEqual(sClassName, "func_door"))
iSoundType = STOP_DOORS;
else if(StrContains(sample, "weapons", false) != -1)
iSoundType = STOP_GUNS;
else
return Plugin_Continue;
for (new i = 0; i < numClients; i++)
{
if((g_Settings[clients[i]] & iSoundType) || ((g_Settings[clients[i]] & HIDE_PLAYERS) && iSoundType == STOP_GUNS)){
// Remove the client from the array.
for (new j = i; j < numClients-1; j++)
{
clients[j] = clients[j+1];
}
numClients--;
i--;
}
}
return (numClients > 0) ? Plugin_Changed : Plugin_Stop;
}
return (numClients > 0) ? Plugin_Changed : Plugin_Continue;
}
public OnEntityCreated(entity, const String:classname[]){
if(GetConVarBool(g_WeaponDespawn) == true)
{
if(IsValidEdict(entity) && IsValidEntity(entity))
{
CreateTimer(0.5, KillEntity, EntIndexToEntRef(entity));
}
}
}
public Action:KillEntity(Handle:timer, any:ref)
{
// anti-weapon spam
new ent = EntRefToEntIndex(ref);
if(IsValidEdict(ent) && IsValidEntity(ent))
{
decl String:entClassname[128];
GetEdictClassname(ent, entClassname, sizeof(entClassname));
if(StrContains(entClassname, "weapon_") != -1 || StrContains(entClassname, "item_") != -1)
{
new m_hOwnerEntity = GetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity");
if(m_hOwnerEntity == -1)
AcceptEntityInput(ent, "Kill");
}
}
}
public Action:Event_PlayerSpawn_Post(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
// no block
SetEntProp(client, Prop_Data, "m_CollisionGroup", 2);
return Plugin_Continue;
}
public Action:Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
{
// Ents are recreated every round.
g_iNumSounds = 0;
// Find all ambient sounds played by the map.
decl String:sSound[PLATFORM_MAX_PATH];
new entity = INVALID_ENT_REFERENCE;
while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE)
{
GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
new len = strlen(sSound);
if (len > 4 && (StrEqual(sSound[len-3], "mp3") || StrEqual(sSound[len-3], "wav")))
{
g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
}
}
}
// drop any weapon
public Action:DropItem(client, const String:command[], argc)
{
new weaponIndex = GetEntPropEnt(client, Prop_Send, "m_hActiveWeapon");
// Allow ghosts to drop all weapons and allow players if the cvar allows them to
if(GetConVarBool(g_hAllowKnifeDrop) || IsFakeClient(client))
{
if(IsValidEdict(weaponIndex) && weaponIndex != -1){
SDKHooks_DropWeapon(client, weaponIndex);
AcceptEntityInput(weaponIndex, "KillHierarchy");
AcceptEntityInput(weaponIndex, "Kill");
return Plugin_Handled;
}
}
return Plugin_Continue;
}
// kill weapon and weapon attachments on drop
public Action:CS_OnCSWeaponDrop(client, weaponIndex)
{
if(weaponIndex != -1)
{
AcceptEntityInput(weaponIndex, "KillHierarchy");
AcceptEntityInput(weaponIndex, "Kill");
}
}
// Tells a player who is spectating them
public Action:SM_Specinfo(client, args)
{
if(IsPlayerAlive(client))
{
ShowSpecinfo(client, client);
}
else
{
new Target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget");
new ObserverMode = GetEntProp(client, Prop_Send, "m_iObserverMode");
if((0 < Target <= MaxClients) && (ObserverMode == 4 || ObserverMode == 5))
{
ShowSpecinfo(client, Target);
}
else
{
PrintColorText(client, "%s%sYou are not spectating anyone.",
g_msg_start,
g_msg_textcol);
}
}
return Plugin_Handled;
}
ShowSpecinfo(client, target)
{
decl String:sNames[MaxClients + 1][MAX_NAME_LENGTH];
new index = 0;
new bool:bClientHasAdmin = GetAdminFlag(GetUserAdmin(client), Admin_Generic, Access_Effective);
for(new i = 1; i <= MaxClients; i++)
{
if(IsClientInGame(i) && target != i)
{
if(!bClientHasAdmin && GetAdminFlag(GetUserAdmin(i), Admin_Generic, Access_Effective))
{
continue;
}
if(!IsPlayerAlive(i))
{
new iTarget = GetEntPropEnt(i, Prop_Send, "m_hObserverTarget");
new ObserverMode = GetEntProp(i, Prop_Send, "m_iObserverMode");
if((ObserverMode == 4 || ObserverMode == 5) && (iTarget == target))
{
GetClientName(i, sNames[index], MAX_NAME_LENGTH);
index++;
}
}
}
}
decl String:sTarget[MAX_NAME_LENGTH];
GetClientName(target, sTarget, sizeof(sTarget));
if(index != 0)
{
if(GetGameType() == GameType_CSS){
new Handle:menu = CreatePanel();
decl String:sTitle[64];
Format(sTitle, sizeof(sTitle), "Spectating %s", sTarget);
DrawPanelText(menu, sTitle);
DrawPanelText(menu, " ");
for(new i = 0; i < index; i++)
{
DrawPanelText(menu, sNames[i]);
}
DrawPanelText(menu, " ");
DrawPanelText(menu, "0. Close");
SendPanelToClient(menu, client, Menu_SpecInfo, 10);
}else{
decl String:sString[1024];
Format(sString, sizeof(sString), "%s%s%s%s has %d spectators: ", g_msg_start, g_msg_varcol, sTarget, g_msg_textcol, index);
for(new i = 0; i < index; i++){
if(index == i)
Format(sString, sizeof(sString), "%s%s%s%s.", sString, g_msg_varcol, sNames[i], g_msg_textcol);
else
Format(sString, sizeof(sString), "%s%s%s%s, ", sString, g_msg_varcol, sNames[i], g_msg_textcol);
}
PrintColorText(client, "%s", sString);
}
}
else
{
PrintColorText(client, "%s%s%s%s has no spectators.",
g_msg_start,
g_msg_varcol,
sTarget,
g_msg_textcol);
}
}
public Menu_SpecInfo(Handle:menu, MenuAction:action, param1, param2)
{
if(action == MenuAction_End)
CloseHandle(menu);
}
// Hide other players
public Action:SM_Hide(client, args)
{
SetClientSettings(client, GetClientSettings(client) ^ HIDE_PLAYERS);
if(g_Settings[client] & HIDE_PLAYERS)
{
PrintColorText(client, "%s%sPlayers are now %sinvisible",
g_msg_start,
g_msg_textcol,
g_msg_varcol);
}
else
{
PrintColorText(client, "%s%sPlayers are now %svisible",
g_msg_start,
g_msg_textcol,
g_msg_varcol);
}
return Plugin_Handled;
}
// Spectate command
public Action:SM_Spec(client, args)
{
StopTimer(client);
ForcePlayerSuicide(client);
ChangeClientTeam(client, 1);
if(args != 0)
{
decl String:arg[128];
GetCmdArgString(arg, sizeof(arg));
new target = FindTarget(client, arg, true, false);
if(target != -1)
{
if(client != target)
{
if(IsPlayerAlive(target))
{
SetEntPropEnt(client, Prop_Send, "m_hObserverTarget", target);
}
else
{
decl String:name[MAX_NAME_LENGTH];
GetClientName(target, name, sizeof(name));
PrintColorText(client, "%s%s%s %sis not alive.",
g_msg_start,
g_msg_varcol,
name,
g_msg_textcol);
}
}
else
{
PrintColorText(client, "%s%sYou can't spectate yourself.",
g_msg_start,
g_msg_textcol);
}
}
}
return Plugin_Handled;
}
// Move stuck players
public Action:SM_Move(client, args)
{
if(args != 0)
{
decl String:name[MAX_NAME_LENGTH];
GetCmdArgString(name, sizeof(name));
new Target = FindTarget(client, name, true, false);
if(Target != -1)
{
new Float:angles[3], Float:pos[3];
GetClientEyeAngles(Target, angles);
GetAngleVectors(angles, angles, NULL_VECTOR, NULL_VECTOR);
GetEntPropVector(Target, Prop_Send, "m_vecOrigin", pos);
for(new i=0; i<3; i++)
pos[i] += (angles[i] * 50);
TeleportEntity(Target, pos, NULL_VECTOR, NULL_VECTOR);
LogMessage("%L moved %L", client, Target);
}
}
else
{
PrintToChat(client, "[SM] Usage: sm_move <target>");
}
return Plugin_Handled;
}
// Punish players
public Action:SM_Hudfuck(client, args)
{
decl String:arg[250];
GetCmdArgString(arg, sizeof(arg));
new target = FindTarget(client, arg, false, false);
if(target != -1)
{
SetEntProp(target, Prop_Send, "m_iHideHUD", HUD_FUCK);
decl String:targetname[MAX_NAME_LENGTH];
GetClientName(target, targetname, sizeof(targetname));
PrintColorTextAll("%s%s%s %shas been HUD-FUCKED for their negative actions",
g_msg_start,
g_msg_varcol,
targetname,
g_msg_textcol);
// Log the hudfuck event
LogMessage("%L executed sm_hudfuck command on %L", client, target);
}
else
{
new Handle:menu = CreateMenu(Menu_HudFuck);
SetMenuTitle(menu, "Select player to HUD FUCK");
decl String:sAuth[32], String:sDisplay[64], String:sInfo[8];
for(new iTarget = 1; iTarget <= MaxClients; iTarget++)
{
if(IsClientInGame(iTarget))
{
GetClientAuthId(iTarget, AuthId_Steam2, sAuth, sizeof(sAuth));
Format(sDisplay, sizeof(sDisplay), "%N <%s>", iTarget, sAuth);
IntToString(GetClientUserId(iTarget), sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, sDisplay);
}
}
SetMenuExitBackButton(menu, true);
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
}
return Plugin_Handled;
}
public Menu_HudFuck(Handle:menu, MenuAction:action, param1, param2)
{
if (action == MenuAction_Select)
{
new String:info[32];
GetMenuItem(menu, param2, info, sizeof(info));
new target = GetClientOfUserId(StringToInt(info));
if(target != 0)
{
PrintColorTextAll("%s%s%N %shas been HUD-FUCKED for their negative actions",
g_msg_start,
g_msg_varcol,
target,
g_msg_textcol);
SetEntProp(target, Prop_Send, "m_iHideHUD", HUD_FUCK);
// Log the hudfuck event
LogMessage("%L executed sm_hudfuck command on %L", param1, target);
}
else
{
PrintColorText(param1, "%s%sTarget not in game",
g_msg_start,
g_msg_textcol);
}
}
else if(action == MenuAction_End)
CloseHandle(menu);
}
// Display current map session time
public Action:SM_Maptime(client, args)
{
new Float:mapTime = GetEngineTime() - g_fMapStart;
new hours, minutes, seconds;
hours = RoundToFloor(mapTime/3600);
mapTime -= (hours * 3600);
minutes = RoundToFloor(mapTime/60);
mapTime -= (minutes * 60);
seconds = RoundToFloor(mapTime);
PrintColorText(client, "%s%sCurrent map has been on for: %s%d%s %s, %s%d%s %s, %s%d%s %s",
g_msg_start,
g_msg_textcol,
g_msg_varcol,
hours,
g_msg_textcol,
(hours==1)?"hour":"hours",
g_msg_varcol,
minutes,
g_msg_textcol,
(minutes==1)?"minute":"minutes",
g_msg_varcol,
seconds,
g_msg_textcol,
(seconds==1)?"second":"seconds");
}
// Show player key presses
public Action:SM_Keys(client, args)
{
SetClientSettings(client, GetClientSettings(client) ^ SHOW_KEYS);
if(g_Settings[client] & SHOW_KEYS)
{
PrintColorText(client, "%s%sShowing key presses",
g_msg_start,
g_msg_textcol);
}
else
{
if(GetGameType() == GameType_CSS)
PrintCenterText(client, "");
PrintColorText(client, "%s%sNo longer showing key presses",
g_msg_start,
g_msg_textcol);
}
return Plugin_Handled;
}
GetKeysMessage(client, String:sKeys[], maxlen)
{
new buttons = Timer_GetButtons(client);
new String:sForward[1], String:sBack[1], String:sMoveleft[2], String:sMoveright[2];
if(buttons & IN_FORWARD)
sForward[0] = 'W';
else
sForward[0] = 32;
if(buttons & IN_MOVELEFT)
{
sMoveleft[0] = 'A';
sMoveleft[1] = 0;
}
else
{
sMoveleft[0] = 32;
sMoveleft[1] = 32;
}
if(buttons & IN_MOVERIGHT)
{
sMoveright[0] = 'D';
sMoveright[1] = 0;
}
else
{
sMoveright[0] = 32;
sMoveright[1] = 32;
}
if(buttons & IN_BACK)
sBack[0] = 'S';
else
sBack[0] = 32;
if(GetGameType() == GameType_CSGO)
{
Format(sKeys, maxlen, " %s\n%s %s %s", sForward, sMoveleft, sBack, sMoveright);
if(buttons & IN_DUCK)
Format(sKeys, maxlen, "%s\nDUCK", sKeys);
else
Format(sKeys, maxlen, "%s\n", sKeys);
if(GetConVarBool(g_hKeysShowsJumps))
{
if(buttons & IN_JUMP)
Format(sKeys, maxlen, "%s\nJUMP", sKeys);
else
Format(sKeys, maxlen, "%s\n ", sKeys);
}
}
else
{
Format(sKeys, maxlen, " %s\n%s %s\n %s", sForward, sMoveleft, sMoveright, sBack);
if(buttons & IN_DUCK)
Format(sKeys, maxlen, "%s\nDUCK", sKeys);
else
Format(sKeys, maxlen, "%s\n ", sKeys);
if(GetConVarBool(g_hKeysShowsJumps))
{
if(buttons & IN_JUMP)
Format(sKeys, maxlen, "%s\nJUMP", sKeys);
else
Format(sKeys, maxlen, "%s\n ", sKeys);
}
}
}
// Open sound control menu
public Action:SM_Sound(client, args)
{
new Handle:menu = CreateMenu(Menu_StopSound);
SetMenuTitle(menu, "Control Sounds");
decl String:sInfo[16];
IntToString(STOP_DOORS, sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, (g_Settings[client] & STOP_DOORS)?"Door sounds: Off":"Door sounds: On");
IntToString(STOP_GUNS, sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, (g_Settings[client] & STOP_GUNS)?"Gun sounds: Off":"Gun sounds: On");
IntToString(STOP_MUSIC, sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, (g_Settings[client] & STOP_MUSIC)?"Music: Off":"Music: On");
IntToString(STOP_RECSND, sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, (g_Settings[client] & STOP_RECSND)?"WR sound: Off":"WR sound: On");
IntToString(STOP_RECSND, sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, (g_Settings[client] & STOP_PBSND)?"Personal best sound: Off":"Personal best sound: On");
IntToString(STOP_RECSND, sInfo, sizeof(sInfo));
AddMenuItem(menu, sInfo, (g_Settings[client] & STOP_FAILSND)?"No new time sound: Off":"No new time sound: On");
SetMenuExitButton(menu, true);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
return Plugin_Handled;
}
public Menu_StopSound(Handle:menu, MenuAction:action, param1, param2)