-
Notifications
You must be signed in to change notification settings - Fork 0
/
sank_sounds.sma
2795 lines (2489 loc) · 81 KB
/
sank_sounds.sma
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
/***************************************************************************
* This plugin reads keyword/wav/mp3 combinations from a configfile and when
* a player says one of the keywords, it will trigger HL to play that Wav/MP3
* file to all or dead/alive players. It allows reloading of the file without
* restarting the current level, as well as adding keyword/wav/mp3
* combinations from the console during gameplay. Also includes banning
* players from playing sounds.
*
* Credits:
* - Luke Sankey -> original author
* - HunteR -> modifications
*
* Functions included in this plugin:
* mp_sank_sounds_download 1/0 - turn internal download system on/off
* amx_sound - turn Sank Sounds on/off
* amx_sound_help - prints all available sounds to console
* amx_sound_play <dir/sound> - plays a specific wav/mp3/speech
* amx_sound_add <keyword> <dir/sound> - adds a word/wav/mp3/speech
* amx_sound_reload <filename> - reload your snd-list.cfg or custom .cfg
* amx_sound_remove <keyword> <dir/sound> - remove a word/wav/mp3
* amx_sound_write <filename> - write all settings to custom .cfg
* amx_sound_reset <player> - resets quota for specified player
* amx_sound_debug - prints debugs (debug mode must be on, see define below)
* amx_sound_ban <player> - bans player from using sounds for current map
* amx_sound_unban <player> - unbans player from using sounds for current map
* amx_sound_top <x> - shows the top <x> most played keywords (leave <x> away for top 10)
*
* Config file settings:
* SND_WARN - The number at which a player will get warned for playing too many sounds each map
* SND_MAX - The number at which a player will get muted for playing too many sounds each map
* SND_MAX_DUR - The maximum amount of seconds a player can play sounds each map (float )
* SND_JOIN - The Sounds to play when a person joins the game
* SND_EXIT - The Sounds to play when a person exits the game
* SND_DELAY - Minimum delay between sounds (float)
* SND_MODE XX - Determinates who can play and who can hear sounds (see readme.txt for details)
* SND_IMMUNITY "XYZ" - Determine the access levels which shall have immunity to warn/ban
* SND_OBEY_DUR XX - Determine who shall obey duration before next sound will be played
* EXACT_MATCH 1/0 - Determinates if plugin triggers on exact match, or partial speech match
* ADMINS_ONLY 1/0 - Determinates if only admins are allowed to play sounds
* DISPLAY_KEYWORDS 1/0 - Determinates if keywords are shown in chat or not
* FREEZE_TIME_CON XX - Time in seconds to wait till first sounds are played (applies only to connect/disconnect sounds)
*
* Commands available for each player:
* amx_sound_help - prints all available sounds to console
* say "/soundson" - now the player can hear sounds again
* say "/soundsoff" - player disables ability to hear sounds
* say "/sounds" - shows a list of all sounds
* say "/soundlist" - shows a list of all sounds
*
* ported to Amx Mod X by White Panther
*
* v1.0.2 (original 4.1 but this is AmxModX):
* - initial release for AmxModX
* - renamed commands to fit with AmxModX
* - Admin sounds cannot be seen by normal people when using amx_sound_help
* - sounds are precached from file
* - fix: check if soundfile exist before precache (that should solve some probs)
* - fix: if chat message was longer than 29 chars the first wav in cfg was played
*
* v1.1.3 :
* - fixed bug with spaces between keywords and wavs
* - multiple Join and Exit sounds can now be used
* - fixed bug where connect and disconnect sound have not been played
* - fixed bug where dead players could not hear sounds
* - added bot check
* - added option to only allow admins to play sounds
*
* v 1.2.4 :
* - added mp3 support (they have to be in <Mod-Dir>/sound too) (engine module needed therefore) (+ hotfix: wavs not being played)
* - changed the way of initializing each sound file (if bad file it wont be loaded and error msg will be printed)
* - changed SND_KICK to SND_MAX
* - increased default defines ( words: 40 - > 80 / each wavs: 10 -> 14 / file chars: 30 -> 60 )
* - fixed bug for 32 players
* - increased memory usage for variables to 64K (should fix probs)
* - while parsing there is now a check if file exists (if not it wont be put in list)
*
* v1.2.5:
* - added a cvar to enable or disable auto download (change will take place after restart/mapchange)
*
* v1.3:
* - fixed:
* - fixed prob where strings were copied into other strings with no size match
* - removed bot detection (maybe this was causing some problems, playing sounds to bots does not do any harm)
* - admin sounds could not be played (eg: hallo; misc/hi.wav;@misc/hi2.wav -> hi2.wav was not played, even by admins)
* - added:
* - type "/sounds" in chat to get a MOTD window with all sounds available (not all mods support MOTD window)
* - ability for speech sounds (like the AmxModX's speechmenu)
* - admin check to "amx_sound_debug" so in debugmode only admins can use it
* - list is now sorted by name for more readable output (sort by Bailopan) (sort can be turned off by define)
*
* v1.3.2:
* - fixed:
* - mp3 support not working
* - changed:
* - mp3 now dont need to be in sound folder but anywhere you want (anywhere in your mod folder though)
* just specify the correct path (eg: music/mymusic/my.mp3 or sound/testmp3/test.mp3 or mainfolder.mp3)
* - amx_sound_debug can now also be used if debug mode is off (this function prints the sound matrix)
*
* v1.3.3:
* - added:
* - cvar "mp_sank_sounds_freezetime" to define when first connect/disconnect sounds are played after mapchange (in seconds)
*
* v1.3.4:
* - fixed:
* - error where some players could not hear any sound
* - changed:
* - some log messages got better checks
* - reimplemented check for bots
*
* v1.3.5:
* - added:
* - with "/soundson" and "/soundsoff" each player can activate/deactivate the ability to hear sounds
*
* v1.3.7:
* - added:
* - "DISPLAY_KEYWORDS" to config, it determinates if keywords are shown in chat or not
* - option to load specific sounds only on specific maps
* - changed:
* - "SND_DELAY" is now a float
*
* v1.4.0:
* - added:
* - option to load packages of sounds, packages cycle with each map-change (packages must be numbered)
* - ability to ban people from using sounds (only for current map) ( amx_sound_ban <player> <1/0 OR on/off> )
* - changed:
* - precache method changed
* - all keywords are now stored into buffer, even those sounds that are not precached
* - code improvements
*
* v1.4.1:
* - fixed:
* - when setting DISPLAY_KEYWORDS to 0 chat was disabled
*
* v1.4.2:
* - fixed:
* - players could be banned from sounds after reconnect
* - added:
* - option to include sounds from "half-life.gcf" and <current mod>.gcf
*
* v1.4.2b:
* - fixed:
* - compile error when disabling mp3 support
*
* v1.4.3:
* - fixed:
* - keywords without or with wrong files will not be added anymore
* - possible errors fixed
* - error with MOTD display fixed
*
* v1.4.5:
* - fixed:
* - ADMINS_ONLY was not working always
* - players could only play less sound than specified in SND_MAX
* - runtime error with amx_sound_reload
* - added:
* - sounds can now also be used in team chat
* - amx_sound_unban to unban players
* - changed:
* - keyword check tweaked
* - amx_sound_ban now do not expect additional parameter "on / off" or "1 / 0"
*
* v1.4.7:
* - fixed:
* - keywords with admin and public sounds, could block normal players from playing normal sounds
* - runtime error which could stop plugin to work
* - message telling players to wait till next sound can be played is not displayed on every word anymore
*
* v1.5.0: ( AmxModX 1.71 or better ONLY )
* - fixed:
* - sounds being not in a subfolder ( eg: sound/mysound.wav ) will now be played
* - reconnecting to reset quota will not work anymore
* - no more overlapping sounds ( Join and Exit sounds will still overlap other but others cannot overlap them )
* - amx_sound_reset now accepts IDs too
* - sound quota could be increased even if no sound was played
* - added:
* - sound duration is now calculated
* - changed:
* - SND_DELAY does not affect admins anymore
* - SND_SPLIT has been replaced with more customizable SND_MODE
* - removed support to disable MP3
*
* v1.5.0b:
* - fixed:
* - rare runtime error
*
* v1.5.1:
* - fixed:
* - calculation for MP3's encoded with MPEG 2
* - added:
* - saying "/soundlist" will now show sound list like "/sounds" does
* - CVAR: "mp_sank_sounds_obey_duration" to determine if sounds may overlap or not ( default: 1 = do not overlap )
*
* v1.5.1b:
* - fixed:
* - runtime error in mp3 calculation
*
* v1.5.2:
* - fixed:
* - support for SND_DELAY was accidently removed
* - some possible minor bugs
* - added:
* - SND_MAX_DUR: maximum of seconds a player can play sounds each map
* - two new options for SND_MODE ( read help for more information )
*
* v1.5.3:
* - fixed:
* - admin being able to play sounds when "mp_sank_sounds_obey_duration" was on
* - added:
* - CVAR: "mp_sank_sounds_motd_address" to use a website to show all sounds ( empty cvar = no website will be used )
*
* v1.5.4:
* - fixed:
* - error in mp3 calculation
* - when using "mapnameonly" option, following options have been ignored
* - added:
* - minor detection for damaged/invalid files
* - changed:
* - both "SND-LIST.CFG" and "snd-list.cfg" will work now ( linux )
* - code improvements
* - faster config parsing/writing
*
* v1.5.5:
* - fixed:
* - error in mp3 calculation ( once again :( )
* - added:
* - additional debug info for mp3's when compiled in DEGUB_MODE 1
*
* v1.5.6:
* - fixed:
* - sounds located in <MODDIR>/sounds/ (no subfolder) not being played if dead and alive not being splitted
* - long lines not being parsed correctly
* - players could play one more sound than allowed
*
* v1.6.0: (16.4.2007)
* - fixed:
* - speech sounds not being played
* - join / exit sound duration was incorrect
* - SND_WARN / SND_MAX error checking could display wrong error
* - added:
* - access can be defined for every sound and keyword seperately
* - changed:
* - partly rewritten
* - way of saving data
* - sounds when enabling and disabling Sank Sounds are not precached anymore ( hard coded )
* - many code improvements
*
* v1.6.2: (16.01.2008)
* - fixed:
* - removed debug message
* - admins are not included in overlapping check anymore
* - non admins could see sounds that are for admins only
* - bug when adding and removing sounds ingame to list (wierd keywords and sounds)
* - added:
* - "PLAY_COUNT_KEY" and "PLAY_COUNT" to data structure to count how often a key and sound has been used
* - messages for players when enabling/disabling sounds and if players have to wait cause of delay
* - changed:
* - sank sounds is now precaching sounds after plugin init (fakemeta modul needed)
* - no more engine, but therefore fakemeta is needed
* - minor code tweaks
*
* v1.6.3: (29.02.2008)
* - fixed:
* - runtime error if more sounds added than defined in MAX_KEYWORDS
* - commenting SND_JOIN and SND_EXIT (adding # or // infront of them) made the following sounds to be added to these options
* - changed:
* - CVAR "mp_sank_sounds_obey_duration" is now a bitmask (see readme.txt)
*
* v1.6.4: (21.12.2008)
* - added:
* - warning for unsupported mp3 files
* - changed:
* - mp3 detection code rewritten
*
* v1.6.5: (14.01.2009)
* - fixed:
* - wav detection for bad files
*
* v1.6.5b: (22.01.2009)
* - changed:
* - removed warning for unsupported mp3s (they are supported)
*
* v1.6.6: (03.03.2009)
* - fixed:
* - last entry in configfile was not sorted
* - runtime error with keywords without any sound
* - exploit where SND_JOIN and SND_EXIT could be used as keywords
* - changed:
* - SND_JOIN and SND_JOIN do not have to be before any other keyword
*
* v1.6.6b: (29.03.2009)
* - fixed:
* - runtime error
* - if SND_JOIN or SND_JOIN was not at the beginning and more sounds were added afterwards, those new sounds overwrote previous sounds
*
* v1.6.6c: (30.06.2009)
* - fixed:
* - removed debug message
*
* v1.6.6d: (03.07.2009)
* - fixed:
* - speech files not being played
*
* v1.7.0: (08.08.2011)
* - added:
* - further checks for bad configfiles
* - new option SND_IMMUNITY (defines all levels that shall get immunity)
* - info when used last sound
* - amx_sound_top <x> shows the top <x> (default 10) most played keywords during current map
* - using keywords followed by a ! (eg: haha!) will play the sound bound to a location (WAVs only)
* you can move away from the sound. NO config change needed
* - changed:
* - WAVs are not bound to <mod-dir>/sound folder anymore (config change needed unfortunately)
* all sounds now need the full path (eg: haha; sound/misc/haha.wav)
*
* v1.7.1: (11.08.2011)
* - fixed:
* - WAVs not downloading and producing error messages
*
* v1.8.0: (11.01.2012)
* - fixed:
* - adding new sounds with console command could add it but it would not be available
* - changed:
* - dynamic arrays are now used to store key/sound data to remove limits
* - saving to default config file is now allowed
*
* v1.8.1: (14.03.2013)
* - fixed:
* - determination if sound can be played for admins
* - "amx_sound_add" could add empty keywords if sound was invalid
* - "amx_sound_add" is not checking sounds if they exist anymore
* - changed:
* - increased motd webpage link length to 255 characters
*
* v1.8.2: (01.09.2013)
* - fixed:
* - exit sounds could be replaced by keyword sounds
*
* v1.8.3: (21.10.2013)
* - fixed:
* - ADMINS_ONLY setting was ignored
*
* v1.8.4: (06.01.2014)
* - fixed:
* - admins could get spammed with "You are muted" messages
*
* v1.8.5: (04.05.2014)
* - added:
* - support to also load files from "<MOD>_downloads" folder
* - fixed:
* - issue with ADMINS_ONLY and RCON access level
*
* v1.8.6: (22.05.2016)
* - fixed:
* - players could get stuck in a "spectator" mode state or being kicked if trying to play a sound with exactly TOK_LENGTH length
*
* v1.8.7: (2017.11.26)
* - fixed:
* - console warnings when "developer" is set to "1"
* - misc
* - changed:
* - support to also load files from "<MOD>_<xxx>" folders
*
* v1.8.8: (2019.05.05)
* - fixed:
* - Players had to wait up to SND_DELAY after map change before being able to play sounds
* - Some warnings not being displayed
* - Issue where downloading was not working for WAV files (due to "developer 1" fix)
*
* v1.8.9: (2019.10.03)
* - added:
* - Option to allow bots to use sounds
* - fixed:
* - Always playing first sound.
*
* v1.9.0: (2020.09.10)
* - changed:
* - CVAR "mp_sank_sounds_obey_duration" replaced with config "SND_OBEY_DUR"
* - CVAR "mp_sank_sounds_freezetime" replaced with config "FREEZE_TIME_CON"
* - fixed:
* - Obey duration for admins would prevent them from playing any sound
*
* v1.9.1: (2021.07.02)
* - changed:
* - using precache generic for all types (instead of precache sound for WAVs)
*
* IMPORTANT:
* a) if u want to use the internal download system do not use more than 200 sounds (HL cannot handle it)
* (also depending on map, you may need to use even less)
* but if u disable the internal download system u can use as many sounds as the plugin can handle
* (max should be over 100000 sounds (depending on the Array Defines ), BUT the plugin speed
* is another question with thousands of sounds ;) )
*
* b) File has to look like this:
* SND_MAX; 20
* SND_MAX_DUR; 180.0
* SND_WARN; 17
* SND_JOIN; misc/hi.wav
* SND_EXIT; misc/comeagain.wav
* SND_DELAY; 0.0
* SND_MODE; 15
* SND_IMMUNITY; "l"
* SND_OBEY_DUR; 1
* EXACT_MATCH; 1
* ADMINS_ONLY; 0
* DISPLAY_KEYWORDS; 1
* FREEZE_TIME_CON; 0
*
* # Word/Sound combinations:
* crap; misc/awwcrap.Wav;misc/awwcrap2.wav
* woohoo; misc/woohoo.wav
* @ha ha; misc/haha.wav
* @abm@godlike; misc/godlike.wav
* doh; misc/doh.wav;misc/doh2.wav;@misc/doh3.wav
* mp3; sound/mymp3.mp3;music/mymp3s/number2.mp3;mainfolder.mp3
* target; "target destroyed"
*
* mapname TESTMAP
* testmap; misc/doh.wav
* mapname TESTMAP2
* testmap2; misc/haha.wav;sound/mymp3.mp3
* testmap3; misc/hi.wav
*
* package 1
* haha2; misc/haha.wav
* doh3; misc/doh3.wav
* package 2
* hi; misc/hi.wav
*
* modspecific
* <keyword>; <location>/<name>.wav
*
* Follow these instructions
* wavs:
* - base directory is "mod-dir/sound/"
* - put EXACT PATH to the wav beginning from base directory (eg misc/test.wav or test2.wav)
* mp3:
* - base directory is "mod-dir/"
* - put the EXACT PATH to the mp3 (eg sound/test.mp3 or music/mymp3s/test2.mp3 or mainfolder.mp3)
* speech:
* - base directory is "mod-dir/sound/vox/"
* - these files are inside the steam package
* - for a list look at c)
* mapname:
* - type mapname <space> the real mapname (without .bsp)
* - everthing below will be loaded only on this map
* mapnameonly:
* - type mapnameonly <space> the real mapname (without .bsp)
* - everthing below will be loaded only on this map
* - everthing below will be only available on this map
* package:
* - type package <space> number
* - everthing below will be loaded only once and switched to next package on map-change
* - if only 1 package this package will be used every map-change
* modspecific:
* - every sound below that line must be inside half-life.gcf or <yourmod>.gcf
* - if you add other files then said above they may/will crash your server as these sounds are assumed to be existent
*
* c) speech sounds must be put in quotes (eg: target; "target destroyed")
* you may not put different speech types into 1 speech or the speech wont be played
* speech without directory is used from "vox/.."
* first specify the speech type (ONLY ONCE eg hgrunt/) and then put the words with spaces between each speech
* eg "hgrunt/yessir barney/stop1" will not work as 2 different speeches
* BUT "hgrunt/yessir no" will work
* get all available speech sounds here:
* "http://www.adminmod.org/help/online/Admin_Mod_Reference/Half_Life_Sounds.htm"
*
* d) "@" infront of a
* - word means only admin can use this word
* - wav/mp3/speech/word means players can use the word but this sound is only played by admins
*
* e) custom admin access:
* - infront of a word/sound add @<ACCESS_LEVELS>@
* - replace <ACCESS_LEVELS> with the access levels you desire
* - @abc@ means: everyone with access a, b or c can use it
***************************************************************************/
#include <amxmodx>
#include <amxmisc>
#include <fakemeta>
// set this to 1 to get some debug messages
#define DEBUG_MODE 0
// turn this off to stop list from being sorted by keywords in alphabetic order
#define ALLOW_SORT 1
// Array Defines, ATTENTION: ( MAX_RANDOM + 1 ) * TOK_LENGTH must be smaller 2048 !!!
#define BUFFER_LEN 2048 // Maximum number of space per line to use when reading configfile
#define MAX_RANDOM 15 // Maximum number of tries to find a sound file
#define TOK_LENGTH 60 // Maximum length of keyword and sound file strings
#define MAX_BANS 32 // Maximum number of bans stored
#define NUM_PER_LINE 6 // Number of words per line from amx_sound_help
//#pragma dynamic 16384
#pragma dynamic 65536
#define ACCESS_ADMIN ADMIN_LEVEL_A
#define PLUGIN_AUTHOR "White Panther, Luke Sankey, HunteR"
#define PLUGIN_VERSION "1.9.1"
new Enable_Sound[] = "sound/misc/woohoo.wav" // Sound played when Sank Sounds being enabled
new Disable_Sound[] = "sound/misc/awwcrap.wav" // Sound played when Sank Sounds being disabled
new config_filename[128]
new SndCount[33] = {0, ...} // Holds the number telling how many sounds a player has played
new Float:SndLenghtCount[33] = {0.0, ...}
new SndOn[33] = {1, ...}
new SND_WARN = 0 // The number at which a player will get warned for playing too many sounds
new SND_MAX = 0 // The number at which a player will get muted for playing too many sounds
new Float:SND_MAX_DUR = 0.0
new Float:SND_DELAY = 0.0 // Minimum delay between sounds
new SND_MODE = 15 // Determinates who can play and who can hear sounds (dead and alive)
new SND_IMMUNITY = ACCESS_ADMIN // Determine the access levels which shall have immunity to warn/ban (default ACCESS_ADMIN for backwards compatability)
new SND_OBEY_DUR = 1 // Determine who shall obey duration before next sound will be played
new EXACT_MATCH = 1 // Determinates if plugin triggers on exact match, or partial speech match
new ADMINS_ONLY = 0 // Determinates if only admins are allowed to play sounds
new DISPLAY_KEYWORDS = 1 // Determinates if keywords are shown in chat or not
new FREEZE_TIME_CON = 0 // Time in seconds to wait till first sounds are played (applies only to connect/disconnect sounds)
new Float:NextSoundTime // spam protection
new Float:Join_exit_SoundTime // spam protection 2
new Float:LastSoundTime = 0.0
new bSoundsEnabled = 1 // amx_sound <on/off> or <1/0>
new g_max_players
new banned_player_steamids[MAX_BANS][60]
new restrict_playing_sounds[33]
new sound_quota_steamids[33][60]
new motd_sound_list_address[256]
new Array:modSearchPaths
enum
{
PARSE_SND_MAX,
PARSE_SND_MAX_DUR,
PARSE_SND_WARN,
PARSE_SND_DELAY,
PARSE_SND_MODE,
PARSE_SND_IMMUNITY,
PARSE_SND_OBEY_DUR,
PARSE_EXACT_MATCH,
PARSE_ADMINS_ONLY,
PARSE_DISPLAY_KEYWORDS,
PARSE_FREEZE_TIME_CON,
PARSE_KEYWORD
}
enum
{
ERROR_NONE,
ERROR_MAX_KEYWORDS,
ERROR_STRING_LENGTH
}
enum
{
RESULT_OK = 1,
RESULT_BAD_ALIVE_STATUS = 0,
RESULT_QUOTA_EXCEEDED = -1,
RESULT_QUOTA_DURATION_EXCEEDED = -2,
RESULT_SOUND_DELAY = -3,
RESULT_ADMINS_ONLY = -4,
}
enum
{
FLAG_IGNORE_AMOUNT = 1,
FLAGS_JOIN_SND = 2,
FLAGS_EXIT_SND = 4
}
enum
{
SOUND_TYPE_SPEECH,
SOUND_TYPE_MP3,
SOUND_TYPE_WAV,
SOUND_TYPE_WAV_LOCAL
}
enum _:SOUND_DATA_BASE
{
KEYWORD[TOK_LENGTH + 1],
ADMIN_LEVEL_BASE,
SOUND_AMOUNT,
FLAGS,
PLAY_COUNT_KEY,
Array:SUB_INDEX
}
enum _:SOUND_DATA_SUB
{
SOUND_FILE[TOK_LENGTH + 1],
Float:DURATION,
ADMIN_LEVEL,
SOUND_TYPE,
PLAY_COUNT
}
new Array:soundData
public plugin_init( )
{
register_plugin("Sank Sounds Plugin", PLUGIN_VERSION, PLUGIN_AUTHOR)
register_cvar("sanksounds_version", PLUGIN_VERSION, FCVAR_SERVER)
new tmpStr[32]
get_cvar_string("sanksounds_version", tmpStr, 31)
if ( !equal(tmpStr, PLUGIN_VERSION) )
{
set_cvar_string("sanksounds_version", PLUGIN_VERSION)
}
register_concmd("amx_sound_reset", "amx_sound_reset", ACCESS_ADMIN, " <user | all> : Resets sound quota for ^"user^", or everyone if ^"all^"")
register_concmd("amx_sound_add", "amx_sound_add", ACCESS_ADMIN, " <keyword> <dir/sound> : Adds a Word/Sound combo to the sound list")
register_clcmd("amx_sound_help", "amx_sound_help")
register_concmd("amx_sound", "amx_sound", ACCESS_ADMIN, " : Turns sounds on/off")
register_concmd("amx_sound_play", "amx_sound_play", ACCESS_ADMIN, " <dir/sound> : Plays sound to all users")
register_concmd("amx_sound_reload", "amx_sound_reload", ACCESS_ADMIN, " : Reloads config file. Filename is optional. If no filename, default is loaded")
register_concmd("amx_sound_remove", "amx_sound_remove", ACCESS_ADMIN, " <keyword> <dir/sound> : Removes a Word/Sound combo from the sound list. Must use quotes")
register_concmd("amx_sound_write", "amx_sound_write", ACCESS_ADMIN, " : Writes current sound configuration to file")
register_concmd("amx_sound_debug", "amx_sound_debug", ACCESS_ADMIN, "prints the whole Word/Sound combo list")
register_concmd("amx_sound_ban", "amx_sound_ban", ACCESS_ADMIN, " <name or #userid>: Bans player from using sounds for current map")
register_concmd("amx_sound_unban", "amx_sound_unban", ACCESS_ADMIN, " <name or #userid>: Unbans player from using sounds for current map")
register_concmd("amx_sound_top", "amx_sound_top", ACCESS_ADMIN, " <number> (optional): Shows the top X (default 10) most used keywords during this map")
register_clcmd("say", "HandleSay")
register_clcmd("say_team", "HandleSay")
register_cvar("mp_sank_sounds_download", "1")
register_cvar("mp_sank_sounds_motd_address", "")
g_max_players = get_maxplayers()
NextSoundTime = get_gametime() - SND_DELAY
LastSoundTime = NextSoundTime
soundData = ArrayCreate(SOUND_DATA_BASE)
modSearchPaths = ArrayCreate(64)
new tmpLen = strlen(Enable_Sound)
if ( tmpLen > 4
&& equali(Enable_Sound[tmpLen - 4], ".wav") )
{
Enable_Sound[tmpLen - 4] = 0
}
tmpLen = strlen(Disable_Sound)
if ( tmpLen > 4
&& equali(Disable_Sound[tmpLen - 4], ".wav") )
{
Disable_Sound[tmpLen - 4] = 0
}
}
public plugin_cfg( )
{
get_cvar_string("mp_sank_sounds_motd_address", motd_sound_list_address, 255)
new configpath[61]
get_configsdir(configpath, 60)
format(config_filename, 127, "%s/SND-LIST.CFG", configpath) // Name of file to parse
// check if file in capital letter exists
// otherwise make it all lowercase and try to load it
if ( file_exists(config_filename) )
{
parse_sound_file(config_filename)
}else
{
strtolower(config_filename)
parse_sound_file(config_filename)
}
}
public client_putinserver( id )
{
restrict_playing_sounds[id] = -1
new steamid[60], i
get_user_authid(id, steamid, 59)
for ( i = 0; i < MAX_BANS; ++i )
{
if ( equal(steamid, banned_player_steamids[i]) )
restrict_playing_sounds[id] = i
}
if ( !equal(steamid, sound_quota_steamids[id]) )
{
copy(sound_quota_steamids[id], 59, steamid)
SndCount[id] = 0
SndLenghtCount[id] = 0.0
}
SndOn[id] = 1
new Float:gametime = get_gametime()
if ( gametime <= FREEZE_TIME_CON )
return
new sData[SOUND_DATA_BASE]
ArrayGetArray(soundData, 0, sData)
if ( sData[SOUND_AMOUNT] == 0 )
return
if ( Join_exit_SoundTime >= gametime )
return
if ( sData[SOUND_AMOUNT] == 0 )
return
new rand = random(sData[SOUND_AMOUNT])
new subData[SOUND_DATA_SUB]
ArrayGetArray(sData[SUB_INDEX], rand, subData)
if ( subData[ADMIN_LEVEL] != 0
&& !(get_user_flags(id) & subData[ADMIN_LEVEL]) )
return
playsoundall(subData[SOUND_FILE], subData[SOUND_TYPE])
Join_exit_SoundTime = gametime + subData[DURATION]
if ( NextSoundTime < Join_exit_SoundTime )
NextSoundTime = Join_exit_SoundTime
}
#if AMXX_VERSION_NUM < 183
public client_disconnect( id )
#else
public client_disconnected( id )
#endif
{
SndOn[id] = 1
restrict_playing_sounds[id] = -1
new Float:gametime = get_gametime()
if ( gametime <= FREEZE_TIME_CON )
return
new sData[SOUND_DATA_BASE]
ArrayGetArray(soundData, 1, sData)
if ( sData[SOUND_AMOUNT] == 0 )
return
if ( Join_exit_SoundTime >= gametime )
return
if ( sData[SOUND_AMOUNT] == 0 )
return
new rand = random(sData[SOUND_AMOUNT])
new subData[SOUND_DATA_SUB]
ArrayGetArray(sData[SUB_INDEX], rand, subData)
if ( subData[ADMIN_LEVEL] != 0
&& !(get_user_flags(id) & subData[ADMIN_LEVEL]) )
return
playsoundall(subData[SOUND_FILE], subData[SOUND_TYPE])
Join_exit_SoundTime = gametime + subData[DURATION]
if ( NextSoundTime < Join_exit_SoundTime )
NextSoundTime = Join_exit_SoundTime
}
public amx_sound_reset( id , level , cid )
{
if ( !cmd_access(id, level, cid, 2) )
return PLUGIN_HANDLED
new arg[33], target
read_argv(1, arg, 32)
if ( equal(arg, "all") == 1 )
{
client_print(id, print_console, "Sank Sounds >> Quota has been reseted for all players")
for ( target = 1; target <= g_max_players; ++target )
{
SndCount[target] = 0
SndLenghtCount[target] = 0.0
}
}else
{
target = cmd_target(id, arg, 1)
if ( !target )
return PLUGIN_HANDLED
SndCount[target] = 0
SndLenghtCount[target] = 0.0
new name[33]
get_user_name(target, name, 32)
client_print(id, print_console, "Sank Sounds >> Quota has been reseted for ^"%s^"", name)
}
return PLUGIN_HANDLED
}
//////////////////////////////////////////////////////////////////////////////
// Adds a Word/Sound combo to the list. If it is a valid line in the config
// file, then it is a valid parameter here. The only difference is you can
// only specify one Sound file at a time with this command.
//
// Usage: amx_sound_add <keyword> <dir/sound>
// Usage: amx_sound_add <setting> <value>
//////////////////////////////////////////////////////////////////////////////
public amx_sound_add( id , level , cid )
{
if ( !cmd_access(id, level, cid, 2) )
return PLUGIN_HANDLED
new Word[TOK_LENGTH + 1], Sound[TOK_LENGTH + 1]
new configOption = 0
read_argv(1, Word, TOK_LENGTH)
read_argv(2, Sound, TOK_LENGTH)
if ( strlen(Word) <= 0
|| strlen(Sound) == 0 )
{
client_print(id, print_console, "Sank Sounds >>Invalid format")
client_print(id, print_console, "Sank Sounds >>USAGE: amx_sound_add keyword <dir/sound>")
return PLUGIN_HANDLED
}
// First look for special parameters
if ( equali(Word, "SND_MAX") )
{
SND_MAX = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "SND_MAX_DUR") )
{
SND_MAX_DUR = floatstr(Sound)
configOption = 1
}else if ( equali(Word, "SND_WARN") )
{
SND_WARN = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "SND_DELAY") )
{
SND_DELAY = floatstr(Sound)
configOption = 1
}else if ( equali(Word, "SND_MODE") )
{
SND_MODE = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "SND_IMMUNITY") )
{
SND_IMMUNITY = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "SND_OBEY_DUR") )
{
SND_OBEY_DUR = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "EXACT_MATCH") )
{
EXACT_MATCH = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "ADMINS_ONLY") )
{
ADMINS_ONLY = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "DISPLAY_KEYWORDS") )
{
DISPLAY_KEYWORDS = str_to_num(Sound)
configOption = 1
}else if ( equali(Word, "FREEZE_TIME_CON") )
{
FREEZE_TIME_CON = str_to_num(Sound)
configOption = 1
}
if ( configOption )
{
// Do some error checking on the user-input numbers
ErrorCheck()
return PLUGIN_HANDLED
}
// Loop once for each keyword
new i, j
new sData[SOUND_DATA_BASE]
new subData[SOUND_DATA_SUB]
new aLen = ArraySize(soundData)
new subLen
new resCode
for( i = 0; i < aLen; ++i )
{
ArrayGetArray(soundData, i, sData)
// If no match found, keep looping
if ( !equal(Word, sData[KEYWORD], TOK_LENGTH) )
continue
// See if the Sound already exists
subLen = ArraySize(sData[SUB_INDEX])
for( j = 0; j < subLen; ++j )
{
ArrayGetArray(sData[SUB_INDEX], j, subData)
// See if this is the same as the new Sound
if ( equali(Sound, subData[SOUND_FILE], TOK_LENGTH) )
{
client_print(id, print_console, "Sank Sounds >> ^"%s; %s^" already exists", Word, Sound)
return PLUGIN_HANDLED
}
}
// Word exists, but Sound is new to the list, so add entry
resCode = array_add_inner_element(i, j, Sound, 0)
if ( resCode != -1 )
client_print(id, print_console, "Sank Sounds >> ^"%s^" successfully added to ^"%s^"", Sound, Word)
return PLUGIN_HANDLED
}
// Word/Sound combo is new to the list, so make a new entry
array_add_element(i, Word)
resCode = array_add_inner_element(i, 0, Sound, 0)
if ( resCode != -1 )
{
ArraySort(soundData, "sortSoundDataFunc")
client_print(id, print_console, "Sank Sounds >> ^"%s; %s^" successfully added", Word, Sound)
}else
{
// removed keyword because no sound could be added
array_remove(i)
}
return PLUGIN_HANDLED
}
//////////////////////////////////////////////////////////////////////////////
// amx_sound_help lists all amx_sound commands and keywords to the user.
//
// Usage: amx_sound_help
//////////////////////////////////////////////////////////////////////////////
public amx_sound_help( id )
{
print_sound_list(id)
return PLUGIN_HANDLED
}
//////////////////////////////////////////////////////////////////////////////
// Turns on/off the playing of the Sound files for this plugin only
//////////////////////////////////////////////////////////////////////////////
public amx_sound( id , level , cid )
{
if ( !cmd_access(id, level, cid, 2) )
return PLUGIN_HANDLED
new onoff[5]
read_argv(1, onoff, 4)
if ( equal(onoff, "on")
|| equal(onoff, "1") )
{
if ( bSoundsEnabled == 1 )
console_print(id, "Sank Sounds >> Plugin already enabled")
else
{
bSoundsEnabled = 1
console_print(id, "Sank Sounds >> Plugin enabled")
client_print(0, print_chat, "Sank Sounds >> Plugin has been enabled")
if ( Enable_Sound[0] )
{
new type = Enable_Sound[0] == '^"' ? SOUND_TYPE_SPEECH : ( Enable_Sound[strlen(Enable_Sound) - 1] == '3' ? SOUND_TYPE_MP3 : SOUND_TYPE_WAV )
playsoundall(Enable_Sound, type)
}
}
return PLUGIN_HANDLED
}else if ( equal(onoff, "off")
|| equal(onoff, "0") )
{
if ( bSoundsEnabled == 0 )
console_print(id, "Sank Sounds >> Plugin already disabled")
else
{
bSoundsEnabled = 0
console_print(id, "Sank Sounds >> Plugin disabled")
client_print(0, print_chat, "Sank Sounds >> Plugin has been disabled")
if ( Disable_Sound[0] )
{
new type = Disable_Sound[0] == '^"' ? SOUND_TYPE_SPEECH : ( Disable_Sound[strlen(Disable_Sound) - 1] == '3' ? SOUND_TYPE_MP3 : SOUND_TYPE_WAV )
playsoundall(Disable_Sound, type)
}
}
}
return PLUGIN_HANDLED
}
//////////////////////////////////////////////////////////////////////////////
// Plays a sound to all players
//
// Usage: amx_sound_play <dir/sound>
//////////////////////////////////////////////////////////////////////////////
public amx_sound_play( id , level , cid )
{
if ( !cmd_access(id, level, cid, 2) )
return PLUGIN_HANDLED