Advertisement
SHUFEN

Untitled

Mar 6th, 2016
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 84.52 KB | None | 0 0
  1. /*
  2. * vim: set ai et ts=4 sw=4 :
  3.  
  4. Cvarlist (default value):
  5. sm_sound_enable 1 Turns Sounds On/Off
  6. sm_sound_warn 3 Number of sounds to warn person at
  7. sm_sound_limit 5 Maximum sounds per person
  8. sm_sound_admin_limit 0 Maximum sounds per admin
  9. sm_sound_admin_warn 0 Number of sounds to warn admin at
  10. sm_sound_announce 0 Turns on announcements when a sound is played
  11. sm_sound_sentence 0 When set, will trigger sounds if keyword is embedded in a sentence
  12. sm_sound_logging 0 When set, will log sounds that are played
  13. sm_join_exit 0 Play sounds when someone joins or exits the game
  14. sm_join_spawn 1 Wait until the player spawns before playing the join sound
  15. sm_specific_join_exit 0 Play sounds when a specific STEAM ID joins or exits the game
  16. sm_time_between_sounds 4.5 Time between each sound trigger, 0.0 to disable checking
  17. sm_time_between_admin_sounds 4.5 Time between each sound trigger (for admins), 0.0 to disable checking
  18. sm_sound_showmenu 1 Turns the Public Sound Menu on(1) or off(0)
  19. sm_saysounds_volume 1.0 Global/Default Volume setting for Say Sounds (0.0 <= x <= 1.0).
  20. sm_saysoundhe_interrupt_sound 1 If set, interrupt the current sound when a new start
  21. sm_saysoundhe_filter_if_dead 0 If set, alive players do not hear sounds triggered by dead players
  22. sm_saysoundhe_download_threshold -1 If set, sets the number of sounds that are downloaded per map.
  23. sm_saysoundhe_sound_threshold 0 If set, sets the number of sounds that are precached on map start (in SetupSound).
  24. sm_saysoundhe_sound_max -1 If set, set max number of sounds that can be used on a map.
  25. sm_saysoundhe_track_disconnects 1 If set, stores sound counts when clients leave and loads them when they join.
  26.  
  27. Admin Commands:
  28. sm_sound_ban <user> Bans a player from using sounds
  29. sm_sound_unban <user> Unbans a player os they can play sounds
  30. sm_sound_reset <all|user> Resets sound quota for user, or everyone if all
  31. sm_admin_sounds Display a menu of all admin sounds to play
  32. !adminsounds When used in chat will present a menu of all admin sound to play.
  33. !allsounds When used in chat will present a menu of all sounds to play.
  34.  
  35. User Commands:
  36. sm_sound_menu Display a menu of all sounds (trigger words) to play
  37. sm_sound_list Print all trigger words to the console
  38. !sounds When used in chat turns sounds on/off for that client
  39. !soundlist When used in chat will print all the trigger words to the console (Now displays menu)
  40. !soundmenu When used in chat will present a menu to choose a sound to play.
  41. !stop When used in chat will per-user stop any sound currently playing by this plug-in
  42.  
  43. */
  44.  
  45. #include <sourcemod>
  46. #include <sdktools>
  47. #include <clientprefs>
  48. #undef REQUIRE_EXTENSIONS
  49. #include <tf2_stocks>
  50. #define REQUIRE_EXTENSIONS
  51.  
  52. // *** Sound Info Library ***
  53. #include <soundlib>
  54.  
  55. #undef REQUIRE_PLUGIN
  56. #include <adminmenu>
  57.  
  58. // BEIGN MOD BY LAMDACORE
  59. // extra memory usability for a lot of sounds.
  60. // Uncomment the next line (w/#pragma) to add additional memory
  61. //#pragma dynamic 65536
  62. #pragma dynamic 131072
  63. // END MOD BY LAMDACORE
  64.  
  65. #pragma semicolon 1
  66.  
  67. #define PLUGIN_VERSION "4.0.8"
  68.  
  69. //*****************************************************************
  70. // ------------------------------------------------------------- *
  71. // *** Defines for checkClientCookies *** *
  72. // ------------------------------------------------------------- *
  73. //*****************************************************************
  74. #define CHK_CHATMSG 1
  75. #define CHK_SAYSOUNDS 2
  76. #define CHK_EVENTS 3
  77. #define CHK_KARAOKE 4
  78. #define CHK_BANNED 5
  79. #define CHK_GREETED 6
  80.  
  81. //*****************************************************************
  82. // ------------------------------------------------------------- *
  83. // *** Define countdown sounds for karaoke *** *
  84. // ------------------------------------------------------------- *
  85. //*****************************************************************
  86. #define TF2_ATTENTION "vo/announcer_attention.wav"
  87. #define TF2_20_SECONDS "vo/announcer_begins_20sec.wav"
  88. #define TF2_10_SECONDS "vo/announcer_begins_10sec.wav"
  89. #define TF2_5_SECONDS "vo/announcer_begins_5sec.wav"
  90. #define TF2_4_SECONDS "vo/announcer_begins_4sec.wav"
  91. #define TF2_3_SECONDS "vo/announcer_begins_3sec.wav"
  92. #define TF2_2_SECONDS "vo/announcer_begins_2sec.wav"
  93. #define TF2_1_SECOND "vo/announcer_begins_1sec.wav"
  94.  
  95. #define HL2_ATTENTION "npc/overwatch/radiovoice/attention.wav"
  96. #define HL2_10_SECONDS "npc/overwatch/cityvoice/fcitadel_10sectosingularity.wav"
  97. #define HL2_5_SECONDS "npc/overwatch/radiovoice/five.wav"
  98. #define HL2_4_SECONDS "npc/overwatch/radiovoice/four.wav"
  99. #define HL2_3_SECONDS "npc/overwatch/radiovoice/three.wav"
  100. #define HL2_2_SECONDS "npc/overwatch/radiovoice/two.wav"
  101. #define HL2_1_SECOND "npc/overwatch/radiovoice/one.wav"
  102.  
  103. enum sound_types { normal_sounds, admin_sounds, karaoke_sounds, all_sounds };
  104.  
  105. //*****************************************************************
  106. // ------------------------------------------------------------- *
  107. // *** Cvar Handles *** *
  108. // ------------------------------------------------------------- *
  109. //*****************************************************************
  110. new Handle:cvarsaysoundversion = INVALID_HANDLE;
  111. new Handle:cvarsoundenable = INVALID_HANDLE;
  112. new Handle:cvarsoundlimit = INVALID_HANDLE;
  113. new Handle:cvarsoundlimitFlags = INVALID_HANDLE;
  114. new Handle:cvarsoundFlags = INVALID_HANDLE;
  115. new Handle:cvarsoundFlagsLimit = INVALID_HANDLE;
  116. new Handle:cvarsoundwarn = INVALID_HANDLE;
  117. new Handle:cvarjoinexit = INVALID_HANDLE;
  118. new Handle:cvarjoinspawn = INVALID_HANDLE;
  119. new Handle:cvarspecificjoinexit = INVALID_HANDLE;
  120. new Handle:cvartimebetween = INVALID_HANDLE;
  121. new Handle:cvartimebetweenFlags = INVALID_HANDLE;
  122. new Handle:cvaradmintime = INVALID_HANDLE;
  123. new Handle:cvaradminwarn = INVALID_HANDLE;
  124. new Handle:cvaradminlimit = INVALID_HANDLE;
  125. new Handle:cvarannounce = INVALID_HANDLE;
  126. new Handle:cvaradult = INVALID_HANDLE;
  127. new Handle:cvarsentence = INVALID_HANDLE;
  128. new Handle:cvarlogging = INVALID_HANDLE;
  129. new Handle:cvarplayifclsndoff = INVALID_HANDLE;
  130. new Handle:cvarkaraokedelay = INVALID_HANDLE;
  131. new Handle:cvarvolume = INVALID_HANDLE; // mod by Woody
  132. new Handle:cvarsoundlimitround = INVALID_HANDLE;
  133. new Handle:cvarexcludelastsound = INVALID_HANDLE;
  134. new Handle:cvarblocktrigger = INVALID_HANDLE;
  135. new Handle:cvarinterruptsound = INVALID_HANDLE;
  136. new Handle:cvarfilterifdead = INVALID_HANDLE;
  137. new Handle:cvarTrackDisconnects = INVALID_HANDLE;
  138. new Handle:cvarStopFlags = INVALID_HANDLE;
  139. new Handle:cvarMenuSettingsFlags = INVALID_HANDLE;
  140. new Handle:g_hMapvoteDuration = INVALID_HANDLE;
  141. //####FernFerret####/
  142. new Handle:cvarshowsoundmenu = INVALID_HANDLE;
  143. //##################/
  144. new Handle:listfile = INVALID_HANDLE;
  145. new Handle:hAdminMenu = INVALID_HANDLE;
  146. new Handle:g_hSoundCountTrie = INVALID_HANDLE;
  147. new String:soundlistfile[PLATFORM_MAX_PATH] = "";
  148.  
  149. //*****************************************************************
  150. // ------------------------------------------------------------- *
  151. // *** Client Peferences *** *
  152. // ------------------------------------------------------------- *
  153. //*****************************************************************
  154. //new Handle:g_ssgeneral_cookie = INVALID_HANDLE; // Cookie for storing clints general saysound setting (ON/OFF)
  155. new Handle:g_sssaysound_cookie = INVALID_HANDLE; // Cookie for storing clints saysound setting (ON/OFF)
  156. new Handle:g_ssevents_cookie = INVALID_HANDLE; // Cookie for storing clients eventsound setting (ON/OFF)
  157. new Handle:g_sschatmsg_cookie = INVALID_HANDLE; // Cookie for storing clients chat message setting (ON/OFF)
  158. new Handle:g_sskaraoke_cookie = INVALID_HANDLE; // Cookie for storing clients karaoke setting (ON/OFF)
  159. new Handle:g_ssban_cookie = INVALID_HANDLE; // Cookie for storing if client is banned from using saysiunds
  160. new Handle:g_ssgreeted_cookie = INVALID_HANDLE; // Cookie for storing if we've played the welcome sound to the client
  161. //new Handle:g_dbClientprefs = INVALID_HANDLE; // Handle for the clientprefs SQLite DB
  162.  
  163. //*****************************************************************
  164. // ------------------------------------------------------------- *
  165. // *** Variables *** *
  166. // ------------------------------------------------------------- *
  167. //*****************************************************************
  168. //new restrict_playing_sounds[MAXPLAYERS+1];
  169. //new SndOn[MAXPLAYERS+1];
  170. new SndCount[MAXPLAYERS+1];
  171. new String:SndPlaying[MAXPLAYERS+1][PLATFORM_MAX_PATH];
  172. //new Float:LastSound[MAXPLAYERS+1];
  173. new bool:firstSpawn[MAXPLAYERS+1];
  174. //new bool:greeted[MAXPLAYERS+1];
  175. new Float:globalLastSound = 0.0;
  176. new Float:globalLastAdminSound = 0.0;
  177. new String:LastPlayedSound[PLATFORM_MAX_PATH+1] = "";
  178. new bool:hearalive = true;
  179. new bool:gb_csgo = false;
  180.  
  181. // Variables for karaoke
  182. new Handle:karaokeFile = INVALID_HANDLE;
  183. new Handle:karaokeTimer = INVALID_HANDLE;
  184. new Float:karaokeStartTime = 0.0;
  185.  
  186. // Variables to enable/disable advertisments plugin during karaoke
  187. new Handle:cvaradvertisements = INVALID_HANDLE;
  188. new bool:advertisements_enabled = false;
  189.  
  190. // Some event variable
  191. //new bool:TF2waiting = false;
  192. //new g_BroadcastAudioTeam;
  193. // Kill Event: If someone kills a few clients with a crit
  194. // make sure he won't get spammed with the corresponding sound
  195. new bool:g_bPlayedEvent2Client[MAXPLAYERS+1] = false;
  196.  
  197.  
  198. //*****************************************************************
  199. // ------------------------------------------------------------- *
  200. // *** Plugin Info *** *
  201. // ------------------------------------------------------------- *
  202. //*****************************************************************
  203. public Plugin:myinfo =
  204. {
  205. name = "Say Sounds (including Hybrid Edition)",
  206. author = "Hell Phoenix|Naris|FernFerret|Uberman|psychonic|edgecom|woody|Miraculix|gH0sTy",
  207. description = "Say Sounds and Action Sounds packaged into one neat plugin! Welcome to the new day of SaySounds Hybrid!",
  208. version = PLUGIN_VERSION,
  209. url = "http://forums.alliedmods.net/showthread.php?t=82220"
  210. };
  211.  
  212. //*****************************************************************
  213. // ------------------------------------------------------------- *
  214. // *** Inculding seperate files *** *
  215. // ------------------------------------------------------------- *
  216. //*****************************************************************
  217. #include "saysounds/gametype.sp"
  218. #include "saysounds/resourcemanager.sp"
  219. #include "saysounds/checks.sp"
  220. #include "saysounds/menu.sp"
  221.  
  222. //*****************************************************************
  223. // ------------------------------------------------------------- *
  224. // *** Plugin Start *** *
  225. // ------------------------------------------------------------- *
  226. //*****************************************************************
  227. public OnPluginStart()
  228. {
  229. if(GetGameType() == l4d2 || GetGameType() == l4d)
  230. SetFailState("The Left 4 Dead series is not supported!");
  231.  
  232. // ***Load Translations **
  233. LoadTranslations("common.phrases");
  234. LoadTranslations("saysoundhe.phrases");
  235.  
  236. // *** Creating the Cvars ***
  237. cvarsaysoundversion = CreateConVar("sm_saysounds_hybrid_version", PLUGIN_VERSION, "Say Sounds Version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  238. cvarsoundenable = CreateConVar("sm_saysoundhe_enable","1","Turns Sounds On/Off",FCVAR_PLUGIN);
  239. // Client limit cvars
  240. cvarsoundwarn = CreateConVar("sm_saysoundhe_sound_warn","3","Number of sounds to warn person at (0 for no warnings)",FCVAR_PLUGIN);
  241. cvarsoundlimit = CreateConVar("sm_saysoundhe_sound_limit","5","Maximum sounds per person (0 for unlimited)",FCVAR_PLUGIN);
  242. cvarsoundlimitFlags = CreateConVar("sm_saysoundhe_sound_flags","","User flags that will result in unlimited sounds",FCVAR_PLUGIN);
  243. cvarsoundFlags = CreateConVar("sm_saysoundhe_flags","","Flag(s) that will have a seperate sound limit",FCVAR_PLUGIN);
  244. cvarsoundFlagsLimit = CreateConVar("sm_saysoundhe_flags_limit","5","Maximum sounds per person with the corresponding flag (0 for unlimited)",FCVAR_PLUGIN);
  245. // Join cvars
  246. cvarjoinexit = CreateConVar("sm_saysoundhe_join_exit","0","Play sounds when someone joins or exits the game",FCVAR_PLUGIN);
  247. cvarjoinspawn = CreateConVar("sm_saysoundhe_join_spawn","1","Wait until the player spawns before playing the join sound",FCVAR_PLUGIN);
  248. cvarspecificjoinexit = CreateConVar("sm_saysoundhe_specific_join_exit","1","Play sounds when specific steam ID joins or exits the game",FCVAR_PLUGIN);
  249. // Anti-Spam cavrs
  250. cvartimebetween = CreateConVar("sm_saysoundhe_time_between_sounds","4.5","Time between each sound trigger, 0.0 to disable checking",FCVAR_PLUGIN);
  251. cvartimebetweenFlags = CreateConVar("sm_saysoundhe_time_between_flags","","User flags to bypass the Time between sounds check",FCVAR_PLUGIN);
  252. // Admin limit cvars
  253. cvaradmintime = CreateConVar("sm_saysoundhe_time_between_admin_sounds","4.5","Time between each admin sound trigger, 0.0 to disable checking for admin sounds \nSet to -1 to completely bypass the soundspam protection for admins",FCVAR_PLUGIN);
  254. cvaradminwarn = CreateConVar("sm_saysoundhe_sound_admin_warn","0","Number of sounds to warn admin at (0 for no warnings)",FCVAR_PLUGIN);
  255. cvaradminlimit = CreateConVar("sm_saysoundhe_sound_admin_limit","0","Maximum sounds per admin (0 for unlimited)",FCVAR_PLUGIN);
  256. //
  257. cvarsoundlimitround = CreateConVar("sm_saysoundhe_limit_sound_per_round", "0", "If set, sm_saysoundhe_sound_limit is the limit per round instead of per map", FCVAR_PLUGIN);
  258. //
  259. cvarannounce = CreateConVar("sm_saysoundhe_sound_announce","1","Turns on announcements when a sound is played",FCVAR_PLUGIN);
  260. cvaradult = CreateConVar("sm_saysoundhe_adult_announce","0","Announce played adult sounds? | 0 = off 1 = on",FCVAR_PLUGIN);
  261. cvarsentence = CreateConVar("sm_saysoundhe_sound_sentence","0","When set, will trigger sounds if keyword is embedded in a sentence",FCVAR_PLUGIN);
  262. cvarlogging = CreateConVar("sm_saysoundhe_sound_logging","0","When set, will log sounds that are played",FCVAR_PLUGIN);
  263. cvarvolume = CreateConVar("sm_saysoundhe_saysounds_volume","1.0","Volume setting for Say Sounds (0.0 <= x <= 1.0)",FCVAR_PLUGIN,true,0.0,true,1.0); // mod by Woody
  264. cvarplayifclsndoff = CreateConVar("sm_saysoundhe_play_cl_snd_off","0","When set, allows clients that have turned their sounds off to trigger sounds (0=off | 1=on)",FCVAR_PLUGIN);
  265. cvarkaraokedelay = CreateConVar("sm_saysoundhe_karaoke_delay","15.0","Delay before playing a Karaoke song",FCVAR_PLUGIN);
  266. cvarexcludelastsound = CreateConVar("sm_saysoundhe_excl_last_sound", "0", "If set, don't allow to play a sound that was recently played", FCVAR_PLUGIN);
  267. cvarblocktrigger = CreateConVar("sm_saysoundhe_block_trigger", "0", "If set, block the sound trigger to be displayed in the chat window", FCVAR_PLUGIN);
  268. cvarinterruptsound = CreateConVar("sm_saysoundhe_interrupt_sound", "0", "If set, interrupt the current sound when a new start", FCVAR_PLUGIN);
  269. cvarfilterifdead = CreateConVar("sm_saysoundhe_filter_if_dead", "0", "If set, alive players do not hear sounds triggered by dead players", FCVAR_PLUGIN);
  270. cvarTrackDisconnects = CreateConVar("sm_saysoundhe_track_disconnects", "1", "If set, stores sound counts when clients leave and loads them when they join.", FCVAR_PLUGIN);
  271. cvarStopFlags = CreateConVar("sm_saysoundhe_stop_flags","","User flags that are allowed to stop a sound",FCVAR_PLUGIN);
  272. cvarMenuSettingsFlags = CreateConVar("sm_saysoundhe_confmenu_flags","","User flags that are allowed to access the configuration menu",FCVAR_PLUGIN);
  273.  
  274. #if !defined _ResourceManager_included
  275. cvarDownloadThreshold = CreateConVar("sm_saysoundhe_download_threshold", "-1", "Number of sounds to download per map start (-1=unlimited).", FCVAR_PLUGIN);
  276. cvarSoundThreshold = CreateConVar("sm_saysoundhe_sound_threshold", "0", "Number of sounds to precache on map start (-1=unlimited).", FCVAR_PLUGIN);
  277. cvarSoundLimitMap = CreateConVar("sm_saysoundhe_sound_max", "-1", "Maximum number of sounds to allow (-1=unlimited).", FCVAR_PLUGIN);
  278. #endif
  279.  
  280. //####FernFerret####//
  281. // This is the Variable that will enable or disable the sound menu to public users, Admin users will always have
  282. // access to their menus, From the admin menu it is a toggle variable
  283. cvarshowsoundmenu = CreateConVar("sm_saysoundhe_showmenu","1","1 To show menu to users, 0 to hide menu from users (admins excluded)",FCVAR_PLUGIN);
  284. //##################//
  285.  
  286. //##### Clientprefs #####
  287. // for storing clients sound settings
  288. g_sssaysound_cookie = RegClientCookie("saysoundsplay", "Play Say Sounds", CookieAccess_Protected);
  289. g_ssevents_cookie = RegClientCookie("saysoundsevent", "Play Action sounds", CookieAccess_Protected);
  290. g_sschatmsg_cookie = RegClientCookie("saysoundschatmsg", "Display Chat messages", CookieAccess_Protected);
  291. g_sskaraoke_cookie = RegClientCookie("saysoundskaraoke", "Play Karaoke music", CookieAccess_Protected);
  292. g_ssban_cookie = RegClientCookie("saysoundsban", "Banned From Say Sounds", CookieAccess_Protected);
  293. g_ssgreeted_cookie = RegClientCookie("saysoundsgreeted", "Join sound Cache", CookieAccess_Protected);
  294. SetCookieMenuItem(SaysoundClientPref, 0, "Say Sounds Preferences");
  295. //SetCookiePrefabMenu(g_sssaysound_cookie, CookieMenu_OnOff, "Saysounds ON/OFF");
  296. //#######################
  297.  
  298. // #### Handle Enabling/Disabling of Say Sounds ###
  299. HookConVarChange(cvarsoundenable, EnableChanged);
  300.  
  301. RegAdminCmd("sm_sound_ban", Command_Sound_Ban, ADMFLAG_BAN, "sm_sound_ban <user> : Bans a player from using sounds");
  302. RegAdminCmd("sm_sound_unban", Command_Sound_Unban, ADMFLAG_BAN, "sm_sound_unban <user> : Unbans a player from using sounds");
  303. RegAdminCmd("sm_sound_reset", Command_Sound_Reset, ADMFLAG_GENERIC, "sm_sound_reset <user | all> : Resets sound quota for user, or everyone if all");
  304. RegAdminCmd("sm_admin_sounds", Command_Admin_Sounds,ADMFLAG_GENERIC, "Display a menu of Admin sounds to play");
  305. RegAdminCmd("sm_karaoke", Command_Karaoke, ADMFLAG_GENERIC, "Display a menu of Karaoke songs to play");
  306. //####FernFerret####/
  307. // This is the admin command that shows all sounds, it is currently set to show to a GENERIC ADMIN
  308. RegAdminCmd("sm_all_sounds", Command_All_Sounds, ADMFLAG_GENERIC,"Display a menu of ALL sounds to play");
  309. //##################/
  310.  
  311. RegConsoleCmd("sm_sound_list", Command_Sound_List, "List available sounds to console");
  312. RegConsoleCmd("sm_sound_menu", Command_Sound_Menu, "Display a menu of sounds to play");
  313. //RegConsoleCmd("say", Command_Say);
  314. AddCommandListener(Command_Say, "say");
  315. //RegConsoleCmd("say2", Command_InsurgencySay);
  316. AddCommandListener(Command_Say, "say2");
  317. //RegConsoleCmd("say_team", Command_Say);
  318. AddCommandListener(Command_Say, "say_team");
  319.  
  320. // *** Execute the config file ***
  321. AutoExecConfig(true, "sm_saysounds");
  322.  
  323. //*****************************************************************
  324. // ------------------------------------------------------------- *
  325. // *** Hooking Events *** *
  326. // ------------------------------------------------------------- *
  327. //*****************************************************************
  328. if(GetConVarBool(cvarsoundenable))
  329. {
  330. HookEvent("player_death", Event_Kill);
  331. HookEvent("player_disconnect", Event_Disconnect, EventHookMode_Pre);
  332. HookEventEx("player_spawn",PlayerSpawn);
  333.  
  334. if (GetGameType() == tf2)
  335. {
  336. LogMessage("[Say Sounds] Detected Team Fortress 2");
  337. HookEvent("teamplay_flag_event", Event_Flag);
  338. HookEvent("player_chargedeployed", Event_UberCharge);
  339. HookEvent("player_builtobject", Event_Build);
  340. HookEvent("teamplay_round_start", Event_RoundStart);
  341. //HookEvent("teamplay_round_active", Event_SetupStart);
  342. HookEvent("teamplay_setup_finished", Event_SetupEnd);
  343. //HookEvent("teamplay_waiting_begins", Event_WaitingStart);
  344. //HookEvent("teamplay_waiting_ends", Event_WaitingEnd);
  345. HookEvent("teamplay_broadcast_audio", OnAudioBroadcast, EventHookMode_Pre);
  346. }
  347. else if (GetGameType() == dod)
  348. {
  349. LogMessage("[Say Sounds] Detected Day of Defeat");
  350. HookEvent("player_hurt", Event_Hurt);
  351. HookEvent("dod_round_start", Event_RoundStart);
  352. //HookEvent("dod_round_win", Event_RoundWin);
  353. HookEvent("dod_broadcast_audio", OnAudioBroadcast, EventHookMode_Pre);
  354. }
  355. else if (GetGameType() == zps)
  356. {
  357. LogMessage("[Say Sounds] Detected Zombie Panic:Source");
  358. HookEvent("game_round_restart", Event_RoundStart);
  359. }
  360. else if (GetGameType() == cstrike)
  361. {
  362. LogMessage("[Say Sounds] Detected Counter Strike");
  363. HookEvent("round_start", Event_RoundStart);
  364. HookEvent("round_end", Event_RoundEnd);
  365. }
  366. else if (GetGameType() == hl2mp)
  367. {
  368. LogMessage("[Say Sounds] Detected Half-Life 2 Deathmatch");
  369. HookEvent("teamplay_round_start",Event_RoundStart);
  370. }
  371. else if (GetGameType() == csgo)
  372. {
  373. LogMessage("[Say Sounds] Detected Counter-Strike: Global Offensive");
  374. HookEvent("round_start", Event_RoundStart);
  375. gb_csgo = true;
  376. }
  377. else if (GetGameType() == other_game)
  378. {
  379. LogMessage("[Say Sounds] No specific game detected");
  380. HookEvent("round_start", Event_RoundStart);
  381. }
  382.  
  383. // if there are no limits, there is no need to save counts
  384. if (GetConVarBool(cvarTrackDisconnects) &&
  385. (GetConVarInt(cvarsoundlimit) > 0 ||
  386. GetConVarInt(cvaradminlimit) > 0 ||
  387. GetConVarInt(cvarsoundFlagsLimit) > 0))
  388. {
  389. g_hSoundCountTrie = CreateTrie();
  390. }
  391. }
  392.  
  393. //*****************************************************************
  394. // ------------------------------------------------------------- *
  395. // *** Account for late loading *** *
  396. // ------------------------------------------------------------- *
  397. //*****************************************************************
  398. new Handle:topmenu;
  399. if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
  400. OnAdminMenuReady(topmenu);
  401.  
  402. // *** Update the Plugin Version cvar ***
  403. SetConVarString(cvarsaysoundversion, PLUGIN_VERSION, true, true);
  404. }
  405.  
  406. //*****************************************************************
  407. // ------------------------------------------------------------- *
  408. // *** Un/Hooking Events *** *
  409. // ------------------------------------------------------------- *
  410. //*****************************************************************
  411. public EnableChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  412. {
  413. new intNewValue = StringToInt(newValue);
  414. new intOldValue = StringToInt(oldValue);
  415.  
  416. if(intNewValue == 1 && intOldValue == 0)
  417. {
  418. LogMessage("[Say Sounds] Enabled, Hooking Events");
  419.  
  420. AddCommandListener(Command_Say, "say");
  421. AddCommandListener(Command_Say, "say2");
  422. AddCommandListener(Command_Say, "say_team");
  423.  
  424. HookEvent("player_death", Event_Kill);
  425. HookEvent("player_disconnect", Event_Disconnect, EventHookMode_Pre);
  426. HookEventEx("player_spawn",PlayerSpawn);
  427.  
  428. if (GetGameType() == tf2)
  429. {
  430. LogMessage("[Say Sounds] Detected Team Fortress 2");
  431. HookEvent("teamplay_flag_event", Event_Flag);
  432. HookEvent("player_chargedeployed", Event_UberCharge);
  433. HookEvent("player_builtobject", Event_Build);
  434. HookEvent("teamplay_round_start", Event_RoundStart);
  435. //HookEvent("teamplay_round_active", Event_SetupStart);
  436. HookEvent("teamplay_setup_finished", Event_SetupEnd);
  437. //HookEvent("teamplay_waiting_begins", Event_WaitingStart);
  438. //HookEvent("teamplay_waiting_ends", Event_WaitingEnd);
  439. HookEvent("teamplay_broadcast_audio", OnAudioBroadcast, EventHookMode_Pre);
  440. }
  441. else if (GetGameType() == dod)
  442. {
  443. LogMessage("[Say Sounds] Detected Day of Defeat");
  444. HookEvent("player_hurt", Event_Hurt);
  445. HookEvent("dod_round_start", Event_RoundStart);
  446. //HookEvent("dod_round_win", Event_RoundWin);
  447. HookEvent("dod_broadcast_audio", OnAudioBroadcast, EventHookMode_Pre);
  448. }
  449. else if (GetGameType() == zps)
  450. {
  451. LogMessage("[Say Sounds] Detected Zombie Panic:Source");
  452. HookEvent("game_round_restart", Event_RoundStart);
  453. }
  454. else if (GetGameType() == cstrike)
  455. {
  456. LogMessage("[Say Sounds] Detected Counter Strike");
  457. HookEvent("round_start", Event_RoundStart);
  458. HookEvent("round_end", Event_RoundEnd);
  459. }
  460. else if (GetGameType() == hl2mp)
  461. {
  462. LogMessage("[Say Sounds] Detected Half-Life 2 Deathmatch");
  463. HookEvent("teamplay_round_start",Event_RoundStart);
  464. }
  465. else if (GetGameType() == csgo)
  466. {
  467. LogMessage("[Say Sounds] Detected Counter-Strike: Global Offensive");
  468. HookEvent("round_start", Event_RoundStart);
  469. gb_csgo = true;
  470. }
  471. else if (GetGameType() == other_game)
  472. {
  473. LogMessage("[Say Sounds] No specific game detected");
  474. HookEvent("round_start", Event_RoundStart);
  475. }
  476.  
  477. ClearSoundCountTrie();
  478. }
  479. else if(intNewValue == 0 && intOldValue == 1)
  480. {
  481. LogMessage("[Say Sounds] Disabled, Unhooking Events");
  482.  
  483. RemoveCommandListener(Command_Say, "say");
  484. RemoveCommandListener(Command_Say, "say2");
  485. RemoveCommandListener(Command_Say, "say_team");
  486.  
  487. UnhookEvent("player_death", Event_Kill);
  488. UnhookEvent("player_disconnect", Event_Disconnect, EventHookMode_Pre);
  489. UnhookEvent("player_spawn",PlayerSpawn);
  490.  
  491. if (GetGameType() == tf2)
  492. {
  493. UnhookEvent("teamplay_flag_event", Event_Flag);
  494. UnhookEvent("player_chargedeployed", Event_UberCharge);
  495. UnhookEvent("player_builtobject", Event_Build);
  496. UnhookEvent("teamplay_round_start", Event_RoundStart);
  497. //HookEvent("teamplay_round_active", Event_SetupStart);
  498. UnhookEvent("teamplay_setup_finished", Event_SetupEnd);
  499. //UnhookEvent("teamplay_waiting_begins", Event_WaitingStart);
  500. //UnhookEvent("teamplay_waiting_ends", Event_WaitingEnd);
  501. UnhookEvent("teamplay_broadcast_audio", OnAudioBroadcast, EventHookMode_Pre);
  502. }
  503. else if (GetGameType() == dod)
  504. {
  505. UnhookEvent("player_hurt", Event_Hurt);
  506. UnhookEvent("dod_round_start", Event_RoundStart);
  507. //UnhookEvent("dod_round_win", Event_RoundWin);
  508. UnhookEvent("dod_broadcast_audio", OnAudioBroadcast, EventHookMode_Pre);
  509. }
  510. else if (GetGameType() == zps){
  511.  
  512. UnhookEvent("game_round_restart", Event_RoundStart);
  513. }
  514. else if (GetGameType() == cstrike)
  515. {
  516. UnhookEvent("round_start", Event_RoundStart);
  517. UnhookEvent("round_end", Event_RoundEnd);
  518. }
  519. else if (GetGameType() == hl2mp)
  520. {
  521. UnhookEvent("teamplay_round_start",Event_RoundStart);
  522. }
  523. else if (GetGameType() == csgo)
  524. {
  525. UnhookEvent("round_start", Event_RoundStart);
  526. }
  527. else if (GetGameType() == other_game)
  528. {
  529. UnhookEvent("round_start", Event_RoundStart);
  530. }
  531. }
  532. }
  533.  
  534. //*****************************************************************
  535. // ------------------------------------------------------------- *
  536. // *** Plugin End *** *
  537. // ------------------------------------------------------------- *
  538. //*****************************************************************
  539. public OnPluginEnd()
  540. {
  541. if (listfile != INVALID_HANDLE)
  542. {
  543. CloseHandle(listfile);
  544. listfile = INVALID_HANDLE;
  545. }
  546.  
  547. if (karaokeFile != INVALID_HANDLE)
  548. {
  549. CloseHandle(karaokeFile);
  550. karaokeFile = INVALID_HANDLE;
  551. }
  552. }
  553.  
  554. //*****************************************************************
  555. // ------------------------------------------------------------- *
  556. // *** Map Start *** *
  557. // ------------------------------------------------------------- *
  558. //*****************************************************************
  559. public OnMapStart()
  560. {
  561. LastPlayedSound = "";
  562. globalLastSound = 0.0;
  563. globalLastAdminSound = 0.0;
  564.  
  565. for (new i = 1; i <= MAXPLAYERS; i++)
  566. {
  567. SndCount[i] = 0;
  568. //LastSound[i] = 0.0;
  569. }
  570.  
  571. ClearSoundCountTrie();
  572.  
  573. #if !defined _ResourceManager_included
  574. g_iDownloadThreshold = GetConVarInt(cvarDownloadThreshold);
  575. g_iSoundThreshold = GetConVarInt(cvarSoundThreshold);
  576. g_iSoundLimit = GetConVarInt(cvarSoundLimitMap);
  577.  
  578. // Setup trie to keep track of precached sounds
  579. if (g_soundTrie == INVALID_HANDLE)
  580. g_soundTrie = CreateTrie();
  581. else
  582. ClearTrie(g_soundTrie);
  583. #endif
  584.  
  585. /* Delay precaching the karaoke countdown sounds
  586. * until they are actually used.
  587. *
  588. if (GetGameType() == tf2) {
  589. PrecacheSound(TF2_ATTENTION, true);
  590. PrecacheSound(TF2_20_SECONDS, true);
  591. PrecacheSound(TF2_10_SECONDS, true);
  592. PrecacheSound(TF2_5_SECONDS, true);
  593. PrecacheSound(TF2_4_SECONDS, true);
  594. PrecacheSound(TF2_3_SECONDS, true);
  595. PrecacheSound(TF2_2_SECONDS, true);
  596. PrecacheSound(TF2_1_SECOND, true);
  597. } else {
  598. PrecacheSound(HL2_ATTENTION, true);
  599. PrecacheSound(HL2_10_SECONDS, true);
  600. PrecacheSound(HL2_5_SECONDS, true);
  601. PrecacheSound(HL2_4_SECONDS, true);
  602. PrecacheSound(HL2_3_SECONDS, true);
  603. PrecacheSound(HL2_2_SECONDS, true);
  604. PrecacheSound(HL2_1_SECOND, true);
  605. }
  606. */
  607.  
  608. CreateTimer(0.1, Load_Sounds);
  609. }
  610.  
  611. //*****************************************************************
  612. // ------------------------------------------------------------- *
  613. // *** Map End *** *
  614. // ------------------------------------------------------------- *
  615. //*****************************************************************
  616. public OnMapEnd()
  617. {
  618. /*if (g_dbClientprefs != INVALID_HANDLE)
  619. {
  620. CloseHandle(g_dbClientprefs);
  621. g_dbClientprefs = INVALID_HANDLE;
  622. }*/
  623.  
  624. if (g_hSoundCountTrie != INVALID_HANDLE)
  625. {
  626. CloseHandle(g_hSoundCountTrie);
  627. g_hSoundCountTrie = INVALID_HANDLE;
  628. }
  629.  
  630. if (listfile != INVALID_HANDLE)
  631. {
  632. CloseHandle(listfile);
  633. listfile = INVALID_HANDLE;
  634. }
  635.  
  636. if (karaokeFile != INVALID_HANDLE)
  637. {
  638. CloseHandle(karaokeFile);
  639. karaokeFile = INVALID_HANDLE;
  640. }
  641.  
  642. if (karaokeTimer != INVALID_HANDLE)
  643. {
  644. KillTimer(karaokeTimer);
  645. karaokeTimer = INVALID_HANDLE;
  646. }
  647.  
  648. #if !defined _ResourceManager_included
  649. if (g_iPrevDownloadIndex >= g_iSoundCount ||
  650. g_iDownloadCount < g_iDownloadThreshold)
  651. {
  652. g_iPrevDownloadIndex = 0;
  653. }
  654.  
  655. g_iDownloadCount = 0;
  656. g_iSoundCount = 0;
  657. #endif
  658. }
  659.  
  660. //*****************************************************************
  661. // ------------------------------------------------------------- *
  662. // *** Map Vote *** *
  663. // ------------------------------------------------------------- *
  664. //*****************************************************************
  665. public OnMapVoteStarted()
  666. {
  667. g_hMapvoteDuration = FindConVar("sm_mapvote_voteduration");
  668.  
  669. if (g_hMapvoteDuration != INVALID_HANDLE)
  670. CreateTimer(GetConVarFloat(g_hMapvoteDuration), TimerMapvoteEnd);
  671. else
  672. LogError("ConVar sm_mapvote_voteduration not found!");
  673.  
  674. runSoundEvent(INVALID_HANDLE,"mapvote","start",0,0,-1);
  675. }
  676.  
  677. public Action:TimerMapvoteEnd(Handle:timer)
  678. {
  679. runSoundEvent(INVALID_HANDLE,"mapvote","end",0,0,-1);
  680. }
  681.  
  682. //*****************************************************************
  683. // ------------------------------------------------------------- *
  684. // *** Waiting for Players *** *
  685. // ------------------------------------------------------------- *
  686. //*****************************************************************
  687. public TF2_OnWaitingForPlayersStart()
  688. {
  689. runSoundEvent(INVALID_HANDLE,"wait4players","start",0,0,-1);
  690. }
  691.  
  692. public TF2_OnWaitingForPlayersEnd()
  693. {
  694. runSoundEvent(INVALID_HANDLE,"wait4players","end",0,0,-1);
  695. }
  696.  
  697. //*****************************************************************
  698. // ------------------------------------------------------------- *
  699. // *** Load the Sounds from the Config *** *
  700. // ------------------------------------------------------------- *
  701. //*****************************************************************
  702. public Action:Load_Sounds(Handle:timer)
  703. {
  704. // precache sounds, loop through sounds
  705. BuildPath(Path_SM,soundlistfile,sizeof(soundlistfile),"configs/saysounds.cfg");
  706. if(!FileExists(soundlistfile))
  707. {
  708. SetFailState("saysounds.cfg not parsed...file doesnt exist!");
  709. }
  710. else
  711. {
  712. if (listfile != INVALID_HANDLE)
  713. CloseHandle(listfile);
  714.  
  715. listfile = CreateKeyValues("soundlist");
  716. FileToKeyValues(listfile,soundlistfile);
  717. KvRewind(listfile);
  718. if (KvGotoFirstSubKey(listfile))
  719. {
  720. do
  721. {
  722. if (KvGetNum(listfile, "enable", 1))
  723. {
  724. decl String:filelocation[PLATFORM_MAX_PATH+1];
  725. decl String:file[8];
  726. new count = KvGetNum(listfile, "count", 1);
  727. new download = KvGetNum(listfile, "download", 1);
  728. new bool:force = bool:KvGetNum(listfile, "force", 0);
  729. new bool:precache = bool:KvGetNum(listfile, "precache", 0);
  730. new bool:preload = bool:KvGetNum(listfile, "preload", 0);
  731. for (new i = 0; i <= count; i++)
  732. {
  733. if (i)
  734. Format(file, sizeof(file), "file%d", i);
  735. else
  736. strcopy(file, sizeof(file), "file");
  737.  
  738. filelocation[0] = '\0';
  739. KvGetString(listfile, file, filelocation, sizeof(filelocation), "");
  740. if (filelocation[0] != '\0')
  741. SetupSound(filelocation, force, download, precache, preload);
  742. }
  743. }
  744. } while (KvGotoNextKey(listfile));
  745. }
  746. else
  747. SetFailState("saysounds.cfg not parsed...No subkeys found!");
  748. }
  749. return Plugin_Handled;
  750. }
  751.  
  752. //*****************************************************************
  753. // ------------------------------------------------------------- *
  754. // *** UNSORTED *** *
  755. // ------------------------------------------------------------- *
  756. //*****************************************************************
  757. ResetClientSoundCount()
  758. {
  759. for (new i = 1; i <= MAXPLAYERS; i++)
  760. {
  761. SndCount[i] = 0;
  762. }
  763.  
  764. ClearSoundCountTrie();
  765. }
  766.  
  767. public Action:reset_PlayedEvent2Client(Handle:timer, any:client)
  768. {
  769. g_bPlayedEvent2Client[client] = false;
  770. }
  771.  
  772. //*****************************************************************
  773. // ------------------------------------------------------------- *
  774. // *** Event Actions *** *
  775. // ------------------------------------------------------------- *
  776. //*****************************************************************
  777. public Action:Event_Disconnect(Handle:event,const String:name[],bool:dontBroadcast)
  778. {
  779. decl String:SteamID[60];
  780. GetEventString(event, "networkid", SteamID, sizeof(SteamID));
  781. SetAuthIdCookie(SteamID, g_ssgreeted_cookie, "0");
  782. new id2Client = GetClientOfUserId(GetEventInt(event, "userid"));
  783.  
  784. if (g_hSoundCountTrie != INVALID_HANDLE)
  785. SetTrieValue(g_hSoundCountTrie, SteamID, SndCount[id2Client]);
  786. }
  787.  
  788. public Action:OnAudioBroadcast(Handle:event, const String:name[], bool:dontBroadcast)
  789. {
  790. if(!GetConVarBool(cvarsoundenable))
  791. return Plugin_Continue;
  792.  
  793. decl String:sound[30];
  794. GetEventString(event, "sound", sound, sizeof(sound));
  795.  
  796. if(GetGameType() == tf2)
  797. {
  798. new iTeam = GetEventInt(event, "team");
  799. if(StrEqual(sound, "Game.Stalemate") && runSoundEvent(event,"round","Stalemate",0,0,-1))
  800. return Plugin_Handled;
  801. else if(StrEqual(sound, "Game.SuddenDeath") && runSoundEvent(event,"round","SuddenDeath",0,0,-1))
  802. return Plugin_Handled;
  803. else if(StrEqual(sound, "Game.YourTeamWon") && runSoundEvent(event,"round","won",0,0,iTeam))
  804. return Plugin_Handled;
  805. else if(StrEqual(sound, "Game.YourTeamLost") && runSoundEvent(event,"round","lost",0,0,iTeam))
  806. return Plugin_Handled;
  807. }
  808. else if(GetGameType() == dod)
  809. {
  810. if(StrEqual(sound, "Game.USWin") && runSoundEvent(event,"round","USWon",0,0,-1))
  811. return Plugin_Handled;
  812. else if(StrEqual(sound, "Game.GermanWin") && runSoundEvent(event,"round","GERWon",0,0,-1))
  813. return Plugin_Handled;
  814. }
  815. return Plugin_Continue;
  816. }
  817.  
  818. public Action:Event_SetupEnd(Handle:event,const String:name[],bool:dontBroadcast)
  819. {
  820. runSoundEvent(event,"round","setupend",0,0,-1);
  821. return Plugin_Continue;
  822. }
  823.  
  824. public Action:Event_RoundStart(Handle:event,const String:name[],bool:dontBroadcast)
  825. {
  826. runSoundEvent(event,"round","start",0,0,-1);
  827.  
  828. if (GetConVarBool(cvarsoundlimitround))
  829. ResetClientSoundCount();
  830.  
  831. return Plugin_Continue;
  832. }
  833.  
  834. public Action:Event_RoundEnd(Handle:event,const String:name[],bool:dontBroadcast)
  835. {
  836. runSoundEvent(event,"round","end",0,0,-1);
  837. return Plugin_Continue;
  838. }
  839.  
  840. public Action:Event_UberCharge(Handle:event,const String:name[],bool:dontBroadcast)
  841. {
  842. new attacker = GetClientOfUserId(GetEventInt(event, "userid"));
  843. new victim = GetClientOfUserId(GetEventInt(event, "targetid"));
  844. runSoundEvent(event,"uber","uber",attacker,victim,-1);
  845. return Plugin_Continue;
  846. }
  847.  
  848. public Action:Event_Flag(Handle:event,const String:name[],bool:dontBroadcast)
  849. {
  850. // pick up(1), capture(2), defend(3), dropped(4)
  851. // Translate the Integer that is the input to a string so that users
  852. // can just add a string to the config file
  853. decl String:flagstring[PLATFORM_MAX_PATH+1];
  854. new flagint;
  855. flagint = GetEventInt(event, "eventtype");
  856. switch(flagint)
  857. {
  858. case 1:
  859. strcopy(flagstring,sizeof(flagstring),"flag_picked_up");
  860. case 2:
  861. strcopy(flagstring,sizeof(flagstring),"flag_captured");
  862. case 3:
  863. strcopy(flagstring,sizeof(flagstring),"flag_defended");
  864. case 4:
  865. strcopy(flagstring,sizeof(flagstring),"flag_dropped");
  866. default:
  867. strcopy(flagstring,sizeof(flagstring),"flag_captured");
  868. }
  869. runSoundEvent(event,"flag",flagstring,0,0,-1);
  870. return Plugin_Continue;
  871. }
  872.  
  873. public Action:Event_Kill(Handle:event,const String:name[],bool:dontBroadcast)
  874. {
  875. decl String:wepstring[PLATFORM_MAX_PATH+1];
  876. // psychonic ,octo, FernFerret
  877. new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
  878. new victim = GetClientOfUserId(GetEventInt(event, "userid"));
  879.  
  880. if (attacker == victim)
  881. {
  882. runSoundEvent(event,"kill","suicide",0,victim,-1);
  883. return Plugin_Continue;
  884. }
  885. else
  886. {
  887. GetEventString(event, "weapon_logclassname",wepstring,PLATFORM_MAX_PATH+1);
  888.  
  889. if (GetGameType() == tf2)
  890. {
  891. new custom_kill = GetEventInt(event, "customkill");
  892. if (custom_kill == TF_CUSTOM_HEADSHOT)
  893. {
  894. runSoundEvent(event,"kill","headshot",attacker,victim,-1);
  895. return Plugin_Continue;
  896. }
  897. if (custom_kill == TF_CUSTOM_BACKSTAB)
  898. {
  899. runSoundEvent(event,"kill","backstab",attacker,victim,-1);
  900. return Plugin_Continue;
  901. }
  902. if (custom_kill == TF_CUSTOM_TELEFRAG)
  903. {
  904. runSoundEvent(event,"kill","telefrag",attacker,victim,-1);
  905. return Plugin_Continue;
  906. }
  907. new bits = GetEventInt(event,"damagebits");
  908. if (bits & 1048576 && attacker > 0)
  909. {
  910. runSoundEvent(event,"kill","crit_kill",attacker,victim,-1);
  911. return Plugin_Continue;
  912. }
  913. if (bits == 16 && victim > 0)
  914. {
  915. runSoundEvent(event,"kill","hit_by_train",0,victim,-1);
  916. return Plugin_Continue;
  917. }
  918. if (bits == 16384 && victim > 0)
  919. {
  920. runSoundEvent(event,"kill","drowned",0,victim,-1);
  921. return Plugin_Continue;
  922. }
  923. if (bits & 32 && victim > 0)
  924. {
  925. runSoundEvent(event,"kill","fall",0,victim,-1);
  926. return Plugin_Continue;
  927. }
  928.  
  929. GetEventString(event, "weapon_logclassname",wepstring,PLATFORM_MAX_PATH+1);
  930. }
  931. else if (GetGameType() == cstrike || GetGameType() == csgo)
  932. {
  933. new headshot = 0;
  934. headshot = GetEventBool(event, "headshot");
  935. if (headshot == 1)
  936. {
  937. runSoundEvent(event,"kill","headshot",attacker,victim,-1);
  938. return Plugin_Continue;
  939. }
  940. GetEventString(event, "weapon",wepstring,PLATFORM_MAX_PATH+1);
  941. }
  942. else
  943. {
  944. GetEventString(event, "weapon",wepstring,PLATFORM_MAX_PATH+1);
  945. }
  946.  
  947. runSoundEvent(event,"kill",wepstring,attacker,victim,-1);
  948.  
  949. return Plugin_Continue;
  950. }
  951. }
  952.  
  953. // ####### Day of Defeat #######
  954. public Action:Event_Hurt(Handle:event,const String:name[],bool:dontBroadcast)
  955. {
  956. new attacker = GetClientOfUserId(GetEventInt(event, "attacker"));
  957. new victim = GetClientOfUserId(GetEventInt(event, "userid"));
  958. new headshot = (GetEventInt(event, "health") == 0 && GetEventInt(event, "hitgroup") == 1);
  959.  
  960. if (headshot)
  961. runSoundEvent(event,"kill","headshot",attacker,victim,-1);
  962.  
  963. return Plugin_Continue;
  964. }
  965. // ####### TF2 #######
  966. public Action:Event_Build(Handle:event,const String:name[],bool:dontBroadcast)
  967. {
  968. decl String:object[PLATFORM_MAX_PATH+1];
  969. new objectint = GetEventInt(event,"object");
  970. new attacker = GetClientOfUserId(GetEventInt(event, "userid"));
  971. switch(objectint)
  972. {
  973. case 0:
  974. strcopy(object,sizeof(object),"obj_dispenser");
  975. case 1:
  976. strcopy(object,sizeof(object),"obj_tele_in");
  977. case 2:
  978. strcopy(object,sizeof(object),"obj_tele_out");
  979. case 3:
  980. strcopy(object,sizeof(object),"obj_sentry");
  981. default:
  982. strcopy(object,sizeof(object),"obj_dispenser");
  983. }
  984. runSoundEvent(event,"build",object,attacker,0,-1);
  985. return Plugin_Continue;
  986. }
  987.  
  988. //*****************************************************************
  989. // ------------------------------------------------------------- *
  990. // *** Run Event Sounds *** *
  991. // ------------------------------------------------------------- *
  992. //*****************************************************************
  993. // Generic Sound event, this gets triggered whenever an event that is supported is triggered
  994. public runSoundEvent(Handle:event,const String:type[],const String:extra[],const attacker,victim,team)
  995. {
  996. decl String:action[PLATFORM_MAX_PATH+1];
  997. decl String:extraparam[PLATFORM_MAX_PATH+1];
  998. decl String:location[PLATFORM_MAX_PATH+1];
  999. decl String:playto[PLATFORM_MAX_PATH+1];
  1000. new bool:result = false;
  1001.  
  1002. if(listfile == INVALID_HANDLE)
  1003. return false;
  1004.  
  1005. KvRewind(listfile);
  1006. if (!KvGotoFirstSubKey(listfile))
  1007. return false;
  1008.  
  1009. // Do while loop that finds out what extra parameter is and plays according sound, also adds random
  1010. do
  1011. {
  1012. KvGetString(listfile, "action",action,sizeof(action),"");
  1013. //PrintToServer("Found Subkey, trying to match (%s) with (%s)",action,type);
  1014. if (StrEqual(action, type, false))
  1015. {
  1016. if (!KvGetNum(listfile, "enable", 1))
  1017. continue;
  1018.  
  1019. //KvGetString(listfile, "file", location, sizeof(location),"");
  1020. // ###### Random Sound ######
  1021. decl String:file[8] = "file";
  1022. new count = KvGetNum(listfile, "count", 1);
  1023. if (count > 1)
  1024. Format(file, sizeof(file), "file%d", GetRandomInt(1,count));
  1025.  
  1026. if (StrEqual(file, "file1"))
  1027. KvGetString(listfile, "file", location, sizeof(location), "");
  1028. else
  1029. KvGetString(listfile, file, location, sizeof(location),"");
  1030.  
  1031.  
  1032. // ###### Random Sound End ######
  1033. KvGetString(listfile, "param",extraparam,sizeof(extraparam),action);
  1034. if(team == -1)
  1035. KvGetString(listfile, "playto",playto,sizeof(playto),"all");
  1036. else
  1037. KvGetString(listfile, "playto",playto,sizeof(playto),"RoundEvent");
  1038.  
  1039. // Used for identifying the names of things
  1040. //PrintToChatAll("Found Subkey, trying to match (%s) with (%s)",extra,extraparam);
  1041.  
  1042. if(!IsGameSound(location) && !checkSamplingRate(location))
  1043. return false;
  1044.  
  1045. if(StrEqual(extra, extraparam, false))// && checkSamplingRate(location))
  1046. {
  1047. // Next section performs random calculations, all percents in decimal from 1-0
  1048. new Float:random = KvGetFloat(listfile, "prob",1.0);
  1049. // Added error checking for the random number
  1050. if(random <= 0.0)
  1051. {
  1052. random = 0.01;
  1053. PrintToChatAll("Your random value for (%s) is <= 0, please make it above 0",location);
  1054. }
  1055. else if(random > 1.0)
  1056. random = 1.0;
  1057.  
  1058. new Float:generated = GetRandomFloat(0.0,1.0);
  1059. // Debug line for new action sounds -- FernFerret
  1060. //PrintToChatAll("I found action: %s",action);
  1061. if (generated <= random)
  1062. {
  1063. //### Delay
  1064. new Float:delay = KvGetFloat(listfile, "delay", 0.1);
  1065. if(delay < 0.1)
  1066. delay = 0.1;
  1067. else if (delay > 60.0)
  1068. delay = 60.0;
  1069.  
  1070. new Handle:pack;
  1071. CreateDataTimer(delay,runSoundEventTimer,pack, TIMER_FLAG_NO_MAPCHANGE);
  1072. WritePackCell(pack, attacker);
  1073. WritePackCell(pack, victim);
  1074. WritePackCell(pack, team);
  1075. WritePackString(pack, playto);
  1076. WritePackString(pack, location);
  1077. ResetPack(pack);
  1078. //PrepareAndEmitSound(clientlist, clientcount, location);
  1079. }
  1080. result = true;
  1081. }
  1082. else
  1083. result = false;
  1084. }
  1085. else
  1086. result = false;
  1087. } while (KvGotoNextKey(listfile));
  1088. //return false;
  1089. return result;
  1090. }
  1091.  
  1092. //*****************************************************************
  1093. // ------------------------------------------------------------- *
  1094. // *** Event Sound Timer *** *
  1095. // ------------------------------------------------------------- *
  1096. //*****************************************************************
  1097. public Action:runSoundEventTimer(Handle:timer,Handle:pack)
  1098. {
  1099. //decl String:location[PLATFORM_MAX_PATH+1];
  1100. // Send to all clients, will update in future to add To client/To Team/To All
  1101. //new clientlist[MAXPLAYERS+1];
  1102. //new looserlist[MAXPLAYERS+1];
  1103. //new clientcount = 0;
  1104. //new loosercount = 0;
  1105. new attacker = ReadPackCell(pack);
  1106. new victim = ReadPackCell(pack);
  1107. new iTeam = ReadPackCell(pack);
  1108. decl String:playto[PLATFORM_MAX_PATH+1];
  1109. ReadPackString(pack, playto, sizeof(playto));
  1110. decl String:location[PLATFORM_MAX_PATH+1];
  1111. ReadPackString(pack, location, sizeof(location));
  1112. //new playersconnected = GetMaxClients();
  1113.  
  1114. if (StrEqual(playto, "attacker", false)) // Send to attacker
  1115. {
  1116. if (IsValidClient(attacker) && checkClientCookies(attacker, CHK_EVENTS) && !g_bPlayedEvent2Client[attacker])
  1117. {
  1118. PrepareAndEmitSoundToClient(attacker, location);
  1119. g_bPlayedEvent2Client[attacker] = true;
  1120. CreateTimer(2.0, reset_PlayedEvent2Client, attacker);
  1121. //PrintToChat(attacker, "Attacker: %s", location);
  1122. }
  1123. }
  1124. else if (StrEqual(playto, "victim", false)) // Send to victim
  1125. {
  1126. //PrintToChat(victim, "Victim: %s", location);
  1127. if (IsValidClient(victim)&& checkClientCookies(victim, CHK_EVENTS))
  1128. {
  1129. PrepareAndEmitSoundToClient(victim, location);
  1130. //PrintToChat(victim, "CL_Victim: %s", location);
  1131. }
  1132.  
  1133. } else if (StrEqual(playto, "both", false)) // Send to attacker & victim
  1134. {
  1135. if (IsValidClient(attacker) && checkClientCookies(attacker, CHK_EVENTS) && !g_bPlayedEvent2Client[attacker])
  1136. {
  1137. PrepareAndEmitSoundToClient(attacker, location);
  1138. g_bPlayedEvent2Client[attacker] = true;
  1139. CreateTimer(3.0, reset_PlayedEvent2Client, attacker);
  1140. //PrintToChat(attacker, "Both attacker: %s", location);
  1141. }
  1142. if (IsValidClient(victim)&& checkClientCookies(victim, CHK_EVENTS))
  1143. {
  1144. PrepareAndEmitSoundToClient(victim, location);
  1145. //PrintToChat(victim, "Both victim: %s", location);
  1146. }
  1147.  
  1148. }
  1149. else if (StrEqual(playto, "ateam", false)) // Send to attacker team
  1150. {
  1151. //if (!g_bPlayedEvent2Client[attacker]){
  1152. new aTeam = GetClientTeam(attacker);
  1153. for (new i = 1; i <= MaxClients; i++)
  1154. {
  1155. if(IsValidClient(i) && GetClientTeam(i) == aTeam && checkClientCookies(i, CHK_EVENTS))
  1156. //clientlist[clientcount++] = i;
  1157. PrepareAndEmitSoundToClient(i, location);
  1158. }
  1159. //PrepareAndEmitSound(clientlist, clientcount, location);
  1160. //g_bPlayedEvent2Client[attacker] = true;
  1161. //CreateTimer(3.0, reset_PlayedEvent2Client, attacker);
  1162. //PrintToChatAll("ATeam: %s", location);
  1163. //}
  1164.  
  1165. } else if (StrEqual(playto, "vteam", false)){ // Send to victim team
  1166.  
  1167. //if (!g_bPlayedEvent2Client[victim]){
  1168. new vTeam = GetClientTeam(victim);
  1169. for (new i = 1; i <= MaxClients; i++)
  1170. {
  1171. if(IsValidClient(i) && GetClientTeam(i) == vTeam && checkClientCookies(i, CHK_EVENTS))
  1172. //clientlist[clientcount++] = i;
  1173. PrepareAndEmitSoundToClient(i, location);
  1174. }
  1175. //PrepareAndEmitSound(clientlist, clientcount, location);
  1176. //g_bPlayedEvent2Client[victim] = true;
  1177. //CreateTimer(3.0, reset_PlayedEvent2Client, victim);
  1178. //PrintToChatAll("VTeam: %s", location);
  1179. //}
  1180. } else if (StrEqual(playto, "RoundEvent", false)){ // RoundEvent
  1181.  
  1182. for (new i = 1; i <= MaxClients; i++)
  1183. {
  1184. //if(IsValidClient(i) && GetClientTeam(i) == g_BroadcastAudioTeam && checkClientCookies(i, _, _, true))
  1185. if(IsValidClient(i)) /* && checkClientCookies(i, _, _, true)) */
  1186. {
  1187. if(GetClientTeam(i) == iTeam)
  1188. PrepareAndEmitSoundToClient(i, location);
  1189. /*if(GetClientTeam(i) != g_BroadcastAudioTeam && GetClientTeam(i) != 0)
  1190. PrepareAndEmitSoundToClient(i, location);*/
  1191. }
  1192. }
  1193. /*PrepareAndEmitSound(clientlist, clientcount, location);
  1194. g_bPlayedEvent2Client[victim] = true;
  1195. CreateTimer(3.0, reset_PlayedEvent2Client, victim);
  1196. PrintToChatAll("VTeam: %s", location); */
  1197. }
  1198. else // Send to all clients
  1199. {
  1200. for (new i = 1; i <= MaxClients; i++)
  1201. {
  1202. if(IsValidClient(i) && checkClientCookies(i, CHK_EVENTS))
  1203. //clientlist[clientcount++] = i;
  1204. PrepareAndEmitSoundToClient(i, location);
  1205. }
  1206. //PrepareAndEmitSound(clientlist, clientcount, location);
  1207. }
  1208. //ReadPackString(pack, location, sizeof(location));
  1209. //PrepareAndEmitSound(clientlist, clientcount, location);
  1210. }
  1211.  
  1212. //*****************************************************************
  1213. // ------------------------------------------------------------- *
  1214. // *** Join/Exit Sounds *** *
  1215. // ------------------------------------------------------------- *
  1216. //*****************************************************************
  1217. public OnClientPostAdminCheck(client)
  1218. {
  1219. decl String:auth[64];
  1220. if (GetClientAuthString(client,auth,sizeof(auth)))
  1221. {
  1222. if(IsValidClient(client) && !GetConVarBool(cvarjoinspawn))
  1223. CheckJoin(client, auth);
  1224.  
  1225. if (g_hSoundCountTrie == INVALID_HANDLE ||
  1226. !GetTrieValue(g_hSoundCountTrie, auth, SndCount[client]))
  1227. {
  1228. SndCount[client] = 0;
  1229. }
  1230. }
  1231. else
  1232. SndCount[client] = 0;
  1233. }
  1234.  
  1235. //####### Player Spawn #######
  1236. public PlayerSpawn(Handle:event,const String:name[],bool:dontBroadcast)
  1237. {
  1238. if(GetConVarBool(cvarjoinspawn) && GetConVarBool(cvarjoinexit))
  1239. {
  1240. new userid = GetEventInt(event,"userid");
  1241. if (userid)
  1242. {
  1243. new index=GetClientOfUserId(userid);
  1244. if (index)
  1245. {
  1246. if(!IsFakeClient(index))
  1247. {
  1248. if (firstSpawn[index])
  1249. {
  1250. decl String:auth[64];
  1251. GetClientAuthString(index,auth,sizeof(auth));
  1252. CheckJoin(index, auth);
  1253. firstSpawn[index] = false;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. }
  1260.  
  1261. //####### Check Join #######
  1262. public CheckJoin(client, const String:auth[])
  1263. {
  1264. /* if(listfile == INVALID_HANDLE)
  1265. return;*/
  1266.  
  1267. if(GetConVarBool(cvarspecificjoinexit))
  1268. {
  1269. decl String:filelocation[PLATFORM_MAX_PATH+1];
  1270. KvRewind(listfile);
  1271. if (KvJumpToKey(listfile, auth) && !checkClientCookies(client, CHK_GREETED))
  1272. {
  1273. filelocation[0] = '\0';
  1274. KvGetString(listfile, "join", filelocation, sizeof(filelocation), "");
  1275. if (filelocation[0] != '\0')
  1276. {
  1277. Send_Sound(client,filelocation, "", true, false);
  1278. //SndCount[client] = 0;
  1279. //greeted[client] = true;
  1280. SetClientCookie(client, g_ssgreeted_cookie, "1");
  1281. return;
  1282. }
  1283. else if (Submit_Sound(client, "", true, false))
  1284. {
  1285. //SndCount[client] = 0;
  1286. //greeted[client] = true;
  1287. SetClientCookie(client, g_ssgreeted_cookie, "1");
  1288. return;
  1289. }
  1290. }
  1291. }
  1292.  
  1293. if(GetConVarBool(cvarjoinexit) || GetConVarBool(cvarjoinspawn))
  1294. {
  1295. KvRewind(listfile);
  1296. if (KvJumpToKey(listfile, "JoinSound") && !checkClientCookies(client, CHK_GREETED))
  1297. {
  1298. Submit_Sound(client,"", true, false);
  1299. //SndCount[client] = 0;
  1300. //greeted[client] = true;
  1301. SetClientCookie(client, g_ssgreeted_cookie, "1");
  1302. }
  1303. }
  1304. }
  1305.  
  1306. //####### Client Connect #######
  1307. /*public OnClientConnected(client)
  1308. {
  1309. greeted[client] = false;
  1310. }*/
  1311.  
  1312. //####### Client Disconnect #######
  1313. public OnClientDisconnect(client)
  1314. {
  1315. if(GetConVarBool(cvarjoinexit) && listfile != INVALID_HANDLE)
  1316. {
  1317. //SndCount[client] = 0;
  1318. //LastSound[client] = 0.0;
  1319. firstSpawn[client] = true;
  1320. //greeted[client] = false;
  1321.  
  1322. if(GetConVarBool(cvarspecificjoinexit))
  1323. {
  1324. decl String:auth[64];
  1325. GetClientAuthString(client,auth,63);
  1326.  
  1327. decl String:filelocation[PLATFORM_MAX_PATH+1];
  1328. KvRewind(listfile);
  1329. if (KvJumpToKey(listfile, auth))
  1330. {
  1331. filelocation[0] = '\0';
  1332. KvGetString(listfile, "exit", filelocation, sizeof(filelocation), "");
  1333. if (filelocation[0] != '\0')
  1334. {
  1335. Send_Sound(client,filelocation, "", false, true);
  1336. //SndCount[client] = 0;
  1337. return;
  1338. }
  1339. else if (Submit_Sound(client,"", false, true))
  1340. {
  1341. //SndCount[client] = 0;
  1342. return;
  1343. }
  1344. }
  1345. }
  1346.  
  1347. KvRewind(listfile);
  1348. if (KvJumpToKey(listfile, "ExitSound"))
  1349. {
  1350. Submit_Sound(client,"", false, true);
  1351. //SndCount[client] = 0;
  1352. }
  1353. }
  1354. }
  1355.  
  1356. public OnClientAuthorized(client, const String:auth[])
  1357. {
  1358. if(client != 0)
  1359. {
  1360. //SndCount[client] = 0;
  1361. //LastSound[client] = 0.0;
  1362. firstSpawn[client]=true;
  1363. /*if(!GetConVarBool(cvarjoinspawn))
  1364. CheckJoin(client, auth);
  1365. */
  1366. }
  1367. }
  1368.  
  1369. //*****************************************************************
  1370. // ------------------------------------------------------------- *
  1371. // *** Say Command Handling *** *
  1372. // ------------------------------------------------------------- *
  1373. //*****************************************************************
  1374. //####### Command Say #######
  1375. public Action:Command_Say(client, const String:command[], argc){
  1376.  
  1377. if(IsValidClient(client)){
  1378.  
  1379. // If sounds are not enabled, then skip this whole thing
  1380. if (!GetConVarBool(cvarsoundenable))
  1381. return Plugin_Continue;
  1382.  
  1383. // player is banned from playing sounds
  1384. if (checkClientCookies(client, CHK_BANNED))
  1385. return Plugin_Continue;
  1386.  
  1387. decl String:speech[192];
  1388. decl String:stopFlags[26];
  1389. stopFlags[0] = '\0';
  1390. decl String:confMenuFlags[26];
  1391. confMenuFlags[0] = '\0';
  1392.  
  1393. GetConVarString(cvarStopFlags, stopFlags, sizeof(stopFlags));
  1394. GetConVarString(cvarMenuSettingsFlags, confMenuFlags, sizeof(confMenuFlags));
  1395.  
  1396.  
  1397. if (GetCmdArgString(speech, sizeof(speech)) < 1)
  1398. return Plugin_Continue;
  1399.  
  1400. new startidx = 0;
  1401.  
  1402. if (speech[strlen(speech)-1] == '"')
  1403. {
  1404. speech[strlen(speech)-1] = '\0';
  1405. startidx = 1;
  1406. }
  1407.  
  1408. if (strcmp(command, "say2", false) == 0)
  1409. {
  1410. startidx += 4;
  1411. }
  1412. /* if (speech[0] == '"'){
  1413. startidx = 1;
  1414. // Strip the ending quote, if there is one
  1415. new len = strlen(speech);
  1416. if (speech[len-1] == '"'){
  1417. speech[len-1] = '\0';
  1418. }
  1419. } */
  1420.  
  1421. if(strcmp(speech[startidx],"!sounds",false) == 0 || strcmp(speech[startidx],"sounds",false) == 0){
  1422.  
  1423. if (confMenuFlags[0] == '\0' || HasClientFlags(confMenuFlags, client))
  1424. ShowClientPrefMenu(client);
  1425.  
  1426. return Plugin_Handled;
  1427.  
  1428. } else if(strcmp(speech[startidx],"!soundlist",false) == 0 || strcmp(speech[startidx],"soundlist",false) == 0){
  1429.  
  1430.  
  1431. if(GetConVarInt(cvarshowsoundmenu) == 1){
  1432. Sound_Menu(client,normal_sounds);
  1433.  
  1434.  
  1435. } else {
  1436. List_Sounds(client);
  1437. //PrintToChat(client,"\x04[Say Sounds]\x01 Check your console for a list of sound triggers");
  1438. PrintToChat(client,"\x04[Say Sounds]\x01%t", "Soundlist");
  1439. }
  1440. return Plugin_Handled;
  1441.  
  1442. } else if(strcmp(speech[startidx],"!soundmenu",false) == 0 || strcmp(speech[startidx],"soundmenu",false) == 0){
  1443.  
  1444.  
  1445. if(GetConVarInt(cvarshowsoundmenu) == 1){
  1446. Sound_Menu(client,normal_sounds);
  1447.  
  1448.  
  1449. }
  1450. return Plugin_Handled;
  1451. } else if(strcmp(speech[startidx],"!adminsounds",false) == 0 || strcmp(speech[startidx],"adminsounds",false) == 0){
  1452.  
  1453.  
  1454. Sound_Menu(client,admin_sounds);
  1455. return Plugin_Handled;
  1456.  
  1457. } else if(strcmp(speech[startidx],"!karaoke",false) == 0 || strcmp(speech[startidx],"karaoke",false) == 0){
  1458.  
  1459.  
  1460. Sound_Menu(client,karaoke_sounds);
  1461. return Plugin_Handled;
  1462.  
  1463. } else if(strcmp(speech[startidx],"!allsounds",false) == 0 || strcmp(speech[startidx],"allsounds",false) == 0){
  1464.  
  1465.  
  1466. Sound_Menu(client,all_sounds);
  1467. return Plugin_Handled;
  1468.  
  1469. } else if(strcmp(speech[startidx],"!stop",false) == 0){
  1470.  
  1471. if(SndPlaying[client][0] && (stopFlags[0] == '\0' || HasClientFlags(stopFlags, client)))
  1472. {
  1473. StopSound(client,SNDCHAN_AUTO,SndPlaying[client]);
  1474. SndPlaying[client] = "";
  1475. }
  1476. return Plugin_Handled;
  1477. }
  1478.  
  1479. // If player has turned sounds off and is restricted from playing sounds, skip
  1480. if(!GetConVarBool(cvarplayifclsndoff) && !checkClientCookies(client, CHK_SAYSOUNDS))
  1481. return Plugin_Continue;
  1482.  
  1483. KvRewind(listfile);
  1484. KvGotoFirstSubKey(listfile);
  1485. new bool:sentence = GetConVarBool(cvarsentence);
  1486. new bool:adult;
  1487. new bool:trigfound;
  1488. decl String:buffer[255];
  1489.  
  1490.  
  1491. do{
  1492. KvGetSectionName(listfile, buffer, sizeof(buffer));
  1493. adult = bool:KvGetNum(listfile, "adult",0);
  1494. if ((sentence && StrContains(speech[startidx],buffer,false) >= 0) ||
  1495. (strcmp(speech[startidx],buffer,false) == 0)){
  1496.  
  1497. Submit_Sound(client,buffer);
  1498. trigfound = true;
  1499. break;
  1500. }
  1501. } while (KvGotoNextKey(listfile));
  1502.  
  1503. if(GetConVarBool(cvarblocktrigger) && trigfound && !StrEqual(LastPlayedSound, buffer, false)){
  1504. return Plugin_Handled;
  1505. }else if(adult && trigfound){
  1506. return Plugin_Handled;
  1507. }else{
  1508. return Plugin_Continue;
  1509. }
  1510. }
  1511. return Plugin_Continue;
  1512. }
  1513.  
  1514. //*****************************************************************
  1515. // ------------------------------------------------------------- *
  1516. // *** Play Say Sound *** *
  1517. // ------------------------------------------------------------- *
  1518. //*****************************************************************
  1519. //####### Submit Sound #######
  1520. bool:Submit_Sound(client,const String:name[], bool:joinsound=false, bool:exitsound=false)
  1521. {
  1522. if (KvGetNum(listfile, "enable", 1))
  1523. {
  1524. decl String:filelocation[PLATFORM_MAX_PATH+1];
  1525. decl String:file[8] = "file";
  1526. new count = KvGetNum(listfile, "count", 1);
  1527. if (count > 1)
  1528. Format(file, sizeof(file), "file%d", GetRandomInt(1,count));
  1529.  
  1530. filelocation[0] = '\0';
  1531. KvGetString(listfile, file, filelocation, sizeof(filelocation));
  1532. if (filelocation[0] == '\0' && StrEqual(file, "file1"))
  1533. KvGetString(listfile, "file", filelocation, sizeof(filelocation), "");
  1534.  
  1535. if (filelocation[0] != '\0')
  1536. {
  1537. decl String:karaoke[PLATFORM_MAX_PATH+1];
  1538. karaoke[0] = '\0';
  1539. KvGetString(listfile, "karaoke", karaoke, sizeof(karaoke));
  1540. if (karaoke[0] != '\0')
  1541. Load_Karaoke(client, filelocation, name, karaoke);
  1542. else
  1543. Send_Sound(client, filelocation, name, joinsound, exitsound);
  1544.  
  1545. return true;
  1546. }
  1547. }
  1548. return false;
  1549. }
  1550.  
  1551. //####### Send Sound #######
  1552. Send_Sound(client, const String:filelocation[], const String:name[], bool:joinsound=false, bool:exitsound=false)
  1553. {
  1554. new tmp_joinsound;
  1555.  
  1556. new adminonly = KvGetNum(listfile, "admin",0);
  1557. new adultonly = KvGetNum(listfile, "adult",0);
  1558. new singleonly = KvGetNum(listfile, "single",0);
  1559.  
  1560. decl String:txtmsg[256];
  1561. txtmsg[0] = '\0';
  1562.  
  1563. if (joinsound)
  1564. KvGetString(listfile, "text", txtmsg, sizeof(txtmsg));
  1565. if (exitsound)
  1566. KvGetString(listfile, "etext", txtmsg, sizeof(txtmsg));
  1567. if (!joinsound && !exitsound)
  1568. KvGetString(listfile, "text", txtmsg, sizeof(txtmsg));
  1569.  
  1570. new actiononly = KvGetNum(listfile, "actiononly",0);
  1571.  
  1572. decl String:accflags[26];
  1573. accflags[0] = '\0';
  1574.  
  1575. KvGetString(listfile, "flags", accflags, sizeof(accflags));
  1576.  
  1577. if (joinsound || exitsound)
  1578. tmp_joinsound = 1;
  1579. else
  1580. tmp_joinsound = 0;
  1581.  
  1582. //####### DURATION #######
  1583. // Get the handle to the soundfile
  1584.  
  1585. new timebuf;
  1586. new samplerate;
  1587.  
  1588. if (!IsGameSound(filelocation)){
  1589. new Handle:h_Soundfile = INVALID_HANDLE;
  1590. h_Soundfile = OpenSoundFile(filelocation,true);
  1591.  
  1592. if(h_Soundfile != INVALID_HANDLE)
  1593. {
  1594. // get the sound length
  1595. timebuf = GetSoundLength(h_Soundfile);
  1596. // get the sample rate
  1597. samplerate = GetSoundSamplingRate(h_Soundfile);
  1598. // close the handle
  1599. CloseHandle(h_Soundfile);
  1600. }
  1601. else
  1602. LogError("<Send_Sound> INVALID_HANDLE for file \"%s\" ", filelocation);
  1603.  
  1604. // Check the sample rate and leave a message if it's above 44.1 kHz;
  1605. if (samplerate > 44100)
  1606. {
  1607. LogError("Invalid sample rate (\%d Hz) for file \"%s\", sample rate should not be above 44100 Hz", samplerate, filelocation);
  1608. PrintToChat(client, "\x04[Say Sounds] \x01Invalid sample rate (\x04%d Hz\x01) for file \x04%s\x01, sample rate should not be above \x0444100 Hz", samplerate, filelocation);
  1609. return;
  1610. }
  1611. }
  1612.  
  1613. new Float:duration = float(timebuf);
  1614.  
  1615. new Float:defVol = GetConVarFloat(cvarvolume);
  1616. new Float:volume = KvGetFloat(listfile, "volume", defVol);
  1617. if (volume == 0.0 || volume == 1.0)
  1618. volume = defVol; // do this check because of possibly "stupid" values in cfg file
  1619.  
  1620. // ### Delay ###
  1621. new Float:delay = KvGetFloat(listfile, "delay", 0.1);
  1622. if(delay < 0.1)
  1623. delay = 0.1;
  1624. else if (delay > 60.0)
  1625. delay = 60.0;
  1626.  
  1627. new Handle:pack;
  1628. CreateDataTimer(delay,Play_Sound_Timer,pack, TIMER_FLAG_NO_MAPCHANGE);
  1629. WritePackCell(pack, client);
  1630. WritePackCell(pack, adminonly);
  1631. WritePackCell(pack, adultonly);
  1632. WritePackCell(pack, singleonly);
  1633. WritePackCell(pack, actiononly);
  1634. WritePackFloat(pack, duration);
  1635. WritePackFloat(pack, volume); // mod by Woody
  1636. WritePackString(pack, filelocation);
  1637. WritePackString(pack, name);
  1638. WritePackCell(pack, tmp_joinsound);
  1639. WritePackString(pack, txtmsg);
  1640. WritePackString(pack, accflags);
  1641. ResetPack(pack);
  1642. }
  1643.  
  1644. //####### Play Sound #######
  1645. Play_Sound(const String:filelocation[], Float:volume)
  1646. {
  1647. new clientlist[MAXPLAYERS+1];
  1648. new clientcount = 0;
  1649. //new playersconnected = GetMaxClients();
  1650. for (new i = 1; i <= MaxClients; i++)
  1651. {
  1652. if(IsValidClient(i) && checkClientCookies(i, CHK_SAYSOUNDS) && HearSound(i))
  1653. {
  1654. clientlist[clientcount++] = i;
  1655. if (GetConVarBool(cvarinterruptsound))
  1656. StopSound(i, SNDCHAN_AUTO, SndPlaying[i]);
  1657. strcopy(SndPlaying[i], sizeof(SndPlaying[]), filelocation);
  1658. }
  1659. }
  1660. if (clientcount)
  1661. PrepareAndEmitSound(clientlist, clientcount, filelocation, .volume=volume);
  1662. }
  1663.  
  1664. //*****************************************************************
  1665. // ------------------------------------------------------------- *
  1666. // *** Play Sound Timer *** *
  1667. // ------------------------------------------------------------- *
  1668. //*****************************************************************
  1669. public Action:Play_Sound_Timer(Handle:timer,Handle:pack)
  1670. {
  1671. decl String:filelocation[PLATFORM_MAX_PATH+1];
  1672. decl String:name[PLATFORM_MAX_PATH+1];
  1673. decl String:chatBuffer[256];
  1674. decl String:txtmsg[256];
  1675. txtmsg[0] = '\0';
  1676. decl String:accflags[26];
  1677. accflags[0] = '\0';
  1678. new client = ReadPackCell(pack);
  1679. new adminonly = ReadPackCell(pack);
  1680. new adultonly = ReadPackCell(pack);
  1681. new singleonly = ReadPackCell(pack);
  1682. /* ####FernFerret#### */
  1683. new actiononly = ReadPackCell(pack);
  1684. /* ################## */
  1685. new Float:duration = ReadPackFloat(pack);
  1686. new Float:volume = ReadPackFloat(pack); // mod by Woody
  1687. ReadPackString(pack, filelocation, sizeof(filelocation));
  1688. ReadPackString(pack, name , sizeof(name));
  1689. new joinsound = ReadPackCell(pack);
  1690. ReadPackString(pack, txtmsg , sizeof(txtmsg));
  1691. ReadPackString(pack, accflags , sizeof(accflags));
  1692.  
  1693. /* ####FernFerret#### */
  1694. // Checks for Action Only sounds and messages user telling them why they can't play an action only sound
  1695. if (IsValidClient(client))
  1696. {
  1697. //new AdminId:aid = GetUserAdmin(client);
  1698. //isadmin = (aid != INVALID_ADMIN_ID) && GetAdminFlag(aid, Admin_Generic, Access_Effective);
  1699. if(actiononly == 1)
  1700. {
  1701. //PrintToChat(client,"[Action Sounds] Sorry, this is an action sound!");
  1702. PrintToChat(client,"\x04[Action Sounds] \x01%t", "ActionSounds");
  1703. return Plugin_Handled;
  1704. }
  1705. }
  1706. /* ################## */
  1707.  
  1708. new Float:waitTime = GetConVarFloat(cvartimebetween);
  1709. new Float:adminTime = GetConVarFloat(cvaradmintime);
  1710. decl String:waitTimeFlags[26];
  1711. waitTimeFlags[0] = '\0';
  1712. GetConVarString(cvartimebetweenFlags, waitTimeFlags, sizeof(waitTimeFlags));
  1713.  
  1714. new bool:isadmin = false;
  1715. if (IsValidClient(client))
  1716. {
  1717.  
  1718. new AdminId:aid = GetUserAdmin(client);
  1719. isadmin = (aid != INVALID_ADMIN_ID) && GetAdminFlag(aid, Admin_Generic, Access_Effective);
  1720. if(adminonly && !isadmin)
  1721. {
  1722. //PrintToChat(client,"\x04[Say Sounds]\x01 Sorry, you are not authorized to play this sound!");
  1723. PrintToChat(client,"\x04[Say Sounds] \x01%t", "AdminSounds");
  1724. return Plugin_Handled;
  1725. }
  1726. // Has the client access to this sound
  1727. if (accflags[0] != '\0' && !HasClientFlags(accflags, client))
  1728. {
  1729. PrintToChat(client,"\x04[Say Sounds] \x01%t", "NoAccess");
  1730. return Plugin_Handled;
  1731. }
  1732. }
  1733.  
  1734. new Float:thetime = GetGameTime();
  1735. //if (LastSound[client] >= thetime)
  1736. // Spam Sounds
  1737. // Only if the user is not admin or he is admin and the adminTime is not -1 for bypassing
  1738. if (globalLastSound > 0.0)
  1739. {
  1740. if (waitTimeFlags[0] == '\0' || !HasClientFlags(waitTimeFlags, client))
  1741. {
  1742. if ((!isadmin && globalLastSound > thetime) || (isadmin && adminTime >= 0.0 && globalLastSound > thetime))
  1743. {
  1744. if(IsValidClient(client))
  1745. {
  1746. //PrintToChat(client,"\x04[Say Sounds]\x01 Please don't spam the sounds!");
  1747. PrintToChat(client,"\x04[Say Sounds] \x01%t", "SpamSounds");
  1748. }
  1749. return Plugin_Handled;
  1750. }
  1751. }
  1752. }
  1753.  
  1754.  
  1755. // new Float:waitTime = GetConVarFloat(cvartimebetween);
  1756. if (waitTime > 0.0 && waitTime < duration)
  1757. waitTime = duration;
  1758. //else if (waitTime <= 0.0)
  1759. //duration = waitTime;
  1760.  
  1761. // new Float:adminTime = GetConVarFloat(cvaradmintime);
  1762. if (adminonly)
  1763. {
  1764. if (globalLastAdminSound >= thetime)
  1765. {
  1766. if(IsValidClient(client))
  1767. {
  1768. //PrintToChat(client,"\x04[Say Sounds]\x01 Please don't spam the admin sounds!");
  1769. PrintToChat(client,"\x04[Say Sounds] \x01%t", "SpamAdminSounds");
  1770. }
  1771. return Plugin_Handled;
  1772. }
  1773.  
  1774. // adminTime = GetConVarFloat(cvaradmintime);
  1775.  
  1776. if(adminTime > 0.0 && adminTime < duration)
  1777. adminTime = duration;
  1778. }
  1779.  
  1780. if(GetConVarBool(cvarexcludelastsound) && IsValidClient(client) && joinsound != 1 && StrEqual(LastPlayedSound, name, false))
  1781. {
  1782. //PrintToChat(client, "\x04[Say Sounds]\x01 Sorry, this sound was recently played.");
  1783. PrintToChat(client, "\x04[Say Sounds] \x01%t", "RecentlyPlayed");
  1784. return Plugin_Handled;
  1785. }
  1786.  
  1787. if(GetConVarBool(cvarfilterifdead))
  1788. {
  1789. if(IsDeadClient(client))
  1790. hearalive = false;
  1791. else
  1792. hearalive = true;
  1793. }
  1794.  
  1795. decl String:soundFlags[26];
  1796. soundFlags[0] = '\0';
  1797. GetConVarString(cvarsoundFlags, soundFlags, sizeof(soundFlags));
  1798.  
  1799. new soundLimit;
  1800.  
  1801. if (isadmin)
  1802. soundLimit = GetConVarInt(cvaradminlimit);
  1803. else if (soundFlags[0] != '\0' && HasClientFlags(soundFlags, client))
  1804. soundLimit = GetConVarInt(cvarsoundFlagsLimit);
  1805. else
  1806. soundLimit = GetConVarInt(cvarsoundlimit);
  1807.  
  1808. //new soundLimit = isadmin ? GetConVarInt(cvaradminlimit) : GetConVarInt(cvarsoundlimit);
  1809.  
  1810. decl String:soundLimitFlags[26];
  1811. soundLimitFlags[0] = '\0';
  1812. GetConVarString(cvarsoundlimitFlags, soundLimitFlags, sizeof(soundLimitFlags));
  1813.  
  1814. if (soundLimit <= 0 || SndCount[client] < soundLimit)
  1815. {
  1816. if (joinsound == 1)
  1817. {
  1818. //SndCount[client] = 0;
  1819. if (txtmsg[0] != '\0')
  1820. //PrintToChatAll("%s", txtmsg);
  1821. dispatchChatMessage(client, txtmsg, "");
  1822. }
  1823. else
  1824. {
  1825. if (soundLimitFlags[0] == '\0' || !HasClientFlags(soundLimitFlags, client))
  1826. SndCount[client]++;
  1827. //LastSound[client] = thetime + waitTime;
  1828. globalLastSound = thetime + waitTime;
  1829. }
  1830. if (adminonly)
  1831. globalLastAdminSound = thetime + adminTime;
  1832.  
  1833. if (singleonly && joinsound == 1)
  1834. {
  1835. if(checkClientCookies(client, CHK_SAYSOUNDS) && IsValidClient(client))
  1836. {
  1837. PrepareAndEmitSoundToClient(client, filelocation, .volume=volume);
  1838. strcopy(SndPlaying[client], sizeof(SndPlaying[]), filelocation);
  1839. if (GetConVarBool(cvarlogging))
  1840. {
  1841. LogToGame("[Say Sounds Log] %s%N played %s%s(%s)", isadmin ? "Admin " : "", client,
  1842. adminonly ? "admin sound " : "", name, filelocation);
  1843. }
  1844. }
  1845. }
  1846. else
  1847. {
  1848. Play_Sound(filelocation, volume);
  1849. LastPlayedSound = name;
  1850. if (name[0] && IsValidClient(client))
  1851. {
  1852. if (GetConVarBool(cvarannounce))
  1853. {
  1854. if(adultonly && GetConVarBool(cvaradult))
  1855. {
  1856. if (txtmsg[0] != '\0')
  1857. {
  1858. //PrintToChatAll("\x04%N\x01: %s", client , txtmsg);
  1859. Format(chatBuffer, sizeof(chatBuffer), "\x04%N\x01: %s", client , txtmsg);
  1860. dispatchChatMessage(client, chatBuffer, "");
  1861. }
  1862. else
  1863. {
  1864. //PrintToChatAll("%t", "PlayedAdultSound", client);
  1865. dispatchChatMessage(client, "PlayedAdultSound", "", true);
  1866. }
  1867. }
  1868. else
  1869. {
  1870. if (txtmsg[0] != '\0')
  1871. {
  1872. //PrintToChatAll("\x04%N\x01: %s", client , txtmsg);
  1873. Format(chatBuffer, sizeof(chatBuffer), "\x04%N\x01: %s", client , txtmsg);
  1874. dispatchChatMessage(client, chatBuffer, "");
  1875. }
  1876. else
  1877. {
  1878. //PrintToChatAll("%t", "PlayedSound", client, name);
  1879. dispatchChatMessage(client, "PlayedSound", name, true);
  1880. }
  1881. }
  1882. }
  1883. if (GetConVarBool(cvarlogging))
  1884. {
  1885. LogToGame("[Say Sounds Log] %s%N played %s%s(%s)", isadmin ? "Admin " : "", client,
  1886. adminonly ? "admin sound " : "", name, filelocation);
  1887. }
  1888. }
  1889. else if (GetConVarBool(cvarlogging))
  1890. {
  1891. LogToGame("[Say Sounds Log] played %s", filelocation);
  1892. }
  1893. }
  1894. }
  1895.  
  1896. if(soundLimit > 0 && IsValidClient(client))
  1897. {
  1898. if (SndCount[client] > soundLimit)
  1899. {
  1900. //PrintToChat(client,"\x04[Say Sounds]\x01 Sorry, you have reached your sound quota!");
  1901. PrintToChat(client,"\x04[Say Sounds] \x01%t", "QuotaReched");
  1902. }
  1903. else if (SndCount[client] == soundLimit && joinsound != 1)
  1904. {
  1905. //PrintToChat(client,"\x04[Say Sounds]\x01 You have no sounds left to use!");
  1906. PrintToChat(client,"\x04[Say Sounds] \x01%t", "NoSoundsLeft");
  1907. SndCount[client]++; // Increment so we get the sorry message next time.
  1908. }
  1909. else
  1910. {
  1911. new soundWarn = isadmin ? GetConVarInt(cvaradminwarn) : GetConVarInt(cvarsoundwarn);
  1912. if (soundWarn <= 0 || SndCount[client] >= soundWarn)
  1913. {
  1914. if (joinsound != 1 && (soundLimitFlags[0] == '\0' || !HasClientFlags(soundLimitFlags, client)))
  1915. {
  1916. new numberleft = (soundLimit - SndCount[client]);
  1917. if (numberleft == 1)
  1918. {
  1919. //PrintToChat(client,"\x04[Say Sounds]\x01 You only have \x04%d \x01sound left to use!",numberleft);
  1920. PrintToChat(client,"\x04[Say Sounds] \x01%t", "SoundLeft",numberleft);
  1921. }
  1922. else
  1923. {
  1924. //PrintToChat(client,"\x04[Say Sounds]\x01 You only have \x04%d \x01sounds left to use!",numberleft);
  1925. PrintToChat(client,"\x04[Say Sounds] \x01%t", "SoundLeftPlural",numberleft);
  1926. }
  1927. }
  1928. }
  1929. }
  1930. }
  1931. return Plugin_Handled;
  1932. }
  1933.  
  1934. //*****************************************************************
  1935. // ------------------------------------------------------------- *
  1936. // *** Dispatch Chat Messages *** *
  1937. // ------------------------------------------------------------- *
  1938. //*****************************************************************
  1939. dispatchChatMessage(client, const String:message[], const String:name[], bool:translate=false)
  1940. {
  1941. for(new i = 1; i <= MaxClients; i++)
  1942. {
  1943. if(IsValidClient(i) && checkClientCookies(i, CHK_CHATMSG))
  1944. {
  1945. if(translate && StrEqual(name, ""))
  1946. PrintToChat(i, "%t", message);
  1947. else if(translate && !StrEqual(name, ""))
  1948. PrintToChat(i, "%t", message, client, name);
  1949. else
  1950. PrintToChat(i, message);
  1951. }
  1952. }
  1953. }
  1954.  
  1955. //*****************************************************************
  1956. // ------------------------------------------------------------- *
  1957. // *** KARAOKE Handling *** *
  1958. // ------------------------------------------------------------- *
  1959. //*****************************************************************
  1960. //####### Load Karaoke #######
  1961. public Load_Karaoke(client, const String:filelocation[], const String:name[], const String:karaoke[])
  1962. {
  1963. new adminonly = KvGetNum(listfile, "admin", 1); // Karaoke sounds default to admin only
  1964. new bool:isadmin = false;
  1965. if (IsValidClient(client))
  1966. {
  1967. new AdminId:aid = GetUserAdmin(client);
  1968. isadmin = (aid != INVALID_ADMIN_ID) && GetAdminFlag(aid, Admin_Generic, Access_Effective);
  1969. if(adminonly && !isadmin)
  1970. {
  1971. //PrintToChat(client,"\x04[Say Sounds]\x01 Sorry, you are not authorized to play this sound!");
  1972. PrintToChat(client,"\x04[Say Sounds] \x01%t", "AdminSounds");
  1973. return;
  1974. }
  1975. }
  1976.  
  1977. decl String:karaokecfg[PLATFORM_MAX_PATH+1];
  1978. BuildPath(Path_SM,karaokecfg,sizeof(karaokecfg),"configs/%s",karaoke);
  1979. if(!FileExists(karaokecfg))
  1980. {
  1981. LogError("%s not parsed...file doesnt exist!", karaokecfg);
  1982. Send_Sound(client, filelocation, name);
  1983. }
  1984. else
  1985. {
  1986. if (karaokeFile != INVALID_HANDLE){
  1987. CloseHandle(karaokeFile);
  1988. }
  1989. karaokeFile = CreateKeyValues(name);
  1990. FileToKeyValues(karaokeFile,karaokecfg);
  1991. KvRewind(karaokeFile);
  1992. decl String:title[128];
  1993. title[0] = '\0';
  1994. KvGetSectionName(karaokeFile, title, sizeof(title));
  1995. if (KvGotoFirstSubKey(karaokeFile))
  1996. {
  1997. new Float:time = GetConVarFloat(cvarkaraokedelay);
  1998. if (time > 0.0)
  1999. Karaoke_Countdown(client, filelocation, title[0] ? title : name, time, true);
  2000. else
  2001. Karaoke_Start(client, filelocation, name);
  2002. }
  2003. else
  2004. {
  2005. LogError("%s not parsed...No subkeys found!", karaokecfg);
  2006. Send_Sound(client, filelocation, name);
  2007. }
  2008. }
  2009. }
  2010.  
  2011. //####### Karaoke Countdown #######
  2012. Karaoke_Countdown(client, const String:filelocation[], const String:name[], Float:time, bool:attention)
  2013. {
  2014. new Float:next=0.0;
  2015.  
  2016. decl String:announcement[128];
  2017. if (attention)
  2018. {
  2019. Show_Message("%s\nKaraoke will begin in %2.0f seconds", name, time);
  2020. if (GetGameType() == tf2)
  2021. strcopy(announcement, sizeof(announcement), TF2_ATTENTION);
  2022. else
  2023. strcopy(announcement, sizeof(announcement), HL2_ATTENTION);
  2024.  
  2025. if (time >= 20.0)
  2026. next = 20.0;
  2027. else if (time >= 10.0)
  2028. next = 10.0;
  2029. else if (time > 5.0)
  2030. next = 5.0;
  2031. else
  2032. next = time - 1.0;
  2033. }
  2034. else
  2035. {
  2036. if (GetGameType() == tf2)
  2037. Format(announcement, sizeof(announcement), "vo/announcer_begins_%dsec.wav", RoundToFloor(time));
  2038. else
  2039. {
  2040. if (time == 10.0)
  2041. strcopy(announcement, sizeof(announcement), HL2_10_SECONDS);
  2042. else if (time == 5.0)
  2043. strcopy(announcement, sizeof(announcement), HL2_5_SECONDS);
  2044. else if (time == 4.0)
  2045. strcopy(announcement, sizeof(announcement), HL2_4_SECONDS);
  2046. else if (time == 3.0)
  2047. strcopy(announcement, sizeof(announcement), HL2_3_SECONDS);
  2048. else if (time == 2.0)
  2049. strcopy(announcement, sizeof(announcement), HL2_2_SECONDS);
  2050. else if (time == 1.0)
  2051. strcopy(announcement, sizeof(announcement), HL2_1_SECOND);
  2052. else
  2053. announcement[0] = '\0';
  2054. }
  2055. switch (time)
  2056. {
  2057. case 20.0: next = 10.0;
  2058. case 10.0: next = 5.0;
  2059. case 5.0: next = 4.0;
  2060. case 4.0: next = 3.0;
  2061. case 3.0: next = 2.0;
  2062. case 2.0: next = 1.0;
  2063. case 1.0: next = 0.0;
  2064. }
  2065. }
  2066.  
  2067. if (time > 0.0)
  2068. {
  2069. if (announcement[0] != '\0')
  2070. Play_Sound(announcement, 1.0);
  2071.  
  2072. new Handle:pack;
  2073. karaokeTimer = CreateDataTimer(time - next, Karaoke_Countdown_Timer, pack, TIMER_FLAG_NO_MAPCHANGE);
  2074. WritePackCell(pack, client);
  2075. WritePackFloat(pack, next);
  2076. WritePackString(pack, filelocation);
  2077. WritePackString(pack, name);
  2078. ResetPack(pack);
  2079. }
  2080. else
  2081. Karaoke_Start(client, filelocation, name);
  2082. }
  2083.  
  2084. //####### Karaoke Start #######
  2085. Karaoke_Start(client, const String:filelocation[], const String:name[])
  2086. {
  2087. decl String:text[3][128], String:timebuf[64];
  2088. timebuf[0] = '\0';
  2089. text[0][0] = '\0';
  2090. text[1][0] = '\0';
  2091. text[2][0] = '\0';
  2092.  
  2093. KvGetString(karaokeFile,"text",text[0],sizeof(text[]));
  2094. KvGetString(karaokeFile,"text1",text[1],sizeof(text[]));
  2095. KvGetString(karaokeFile,"text2",text[2],sizeof(text[]));
  2096. KvGetString(karaokeFile,"time",timebuf,sizeof(timebuf));
  2097.  
  2098. new Float:time = Convert_Time(timebuf);
  2099. if (time == 0.0)
  2100. {
  2101. Karaoke_Message(text);
  2102. if (KvGotoNextKey(karaokeFile))
  2103. {
  2104. text[0][0] = '\0';
  2105. text[1][0] = '\0';
  2106. text[2][0] = '\0';
  2107. KvGetString(karaokeFile,"text",text[0],sizeof(text[]));
  2108. KvGetString(karaokeFile,"text1",text[1],sizeof(text[]));
  2109. KvGetString(karaokeFile,"text2",text[2],sizeof(text[]));
  2110. KvGetString(karaokeFile,"time",timebuf,sizeof(timebuf));
  2111. time = Convert_Time(timebuf);
  2112. }
  2113. else
  2114. {
  2115. CloseHandle(karaokeFile);
  2116. karaokeFile = INVALID_HANDLE;
  2117. time = 0.0;
  2118. }
  2119. }
  2120.  
  2121. if (time > 0.0)
  2122. {
  2123. cvaradvertisements = FindConVar("sm_advertisements_enabled");
  2124. if (cvaradvertisements != INVALID_HANDLE)
  2125. {
  2126. advertisements_enabled = GetConVarBool(cvaradvertisements);
  2127. SetConVarBool(cvaradvertisements, false);
  2128. }
  2129.  
  2130. new Handle:pack;
  2131. karaokeTimer = CreateDataTimer(time, Karaoke_Timer, pack, TIMER_FLAG_NO_MAPCHANGE);
  2132. WritePackString(pack, text[0]);
  2133. WritePackString(pack, text[1]);
  2134. WritePackString(pack, text[2]);
  2135. ResetPack(pack);
  2136. }
  2137. else
  2138. {
  2139. karaokeTimer = INVALID_HANDLE;
  2140. }
  2141.  
  2142. karaokeStartTime = GetEngineTime();
  2143. Send_Sound(client, filelocation, name, true);
  2144. }
  2145.  
  2146. //####### Convert Time #######
  2147. Float:Convert_Time(const String:buffer[])
  2148. {
  2149. decl String:part[5];
  2150. new pos = SplitString(buffer, ":", part, sizeof(part));
  2151. if (pos == -1)
  2152. return StringToFloat(buffer);
  2153. else
  2154. {
  2155. // Convert from mm:ss to seconds
  2156. return (StringToFloat(part)*60.0) +
  2157. StringToFloat(buffer[pos]);
  2158. }
  2159. }
  2160.  
  2161. //####### Karaoke Message #######
  2162. Karaoke_Message(const String:text[3][])
  2163. {
  2164. //new playersconnected = GetMaxClients();
  2165. for (new i = 1; i <= MaxClients; i++)
  2166. {
  2167. if(IsValidClient(i) && checkClientCookies(i, CHK_KARAOKE))
  2168. {
  2169. new team = GetClientTeam(i) - 1;
  2170. if (team >= 1 && text[team][0] != '\0')
  2171. PrintCenterText(i, text[team]);
  2172. else
  2173. PrintCenterText(i, text[0]);
  2174. }
  2175. }
  2176. }
  2177.  
  2178. //####### Show Message #######
  2179. Show_Message(const String:fmt[], any:...)
  2180. {
  2181. decl String:text[128];
  2182. VFormat(text, sizeof(text), fmt, 2);
  2183.  
  2184. //new playersconnected = GetMaxClients();
  2185. for (new i = 1; i <= MaxClients; i++)
  2186. {
  2187. if(IsValidClient(i) && checkClientCookies(i, CHK_KARAOKE))
  2188. PrintCenterText(i, text);
  2189. }
  2190. }
  2191.  
  2192. //####### Timer Karaoke Countdown #######
  2193. public Action:Karaoke_Countdown_Timer(Handle:timer,Handle:pack)
  2194. {
  2195. decl String:filelocation[PLATFORM_MAX_PATH+1];
  2196. decl String:name[PLATFORM_MAX_PATH+1];
  2197. new client = ReadPackCell(pack);
  2198. new Float:time = ReadPackFloat(pack);
  2199. ReadPackString(pack, filelocation , sizeof(filelocation));
  2200. ReadPackString(pack, name , sizeof(name));
  2201. Karaoke_Countdown(client, filelocation, name, time, false);
  2202. }
  2203.  
  2204. //####### Timer Karaoke #######
  2205. public Action:Karaoke_Timer(Handle:timer,Handle:pack)
  2206. {
  2207. decl String:text[3][128], String:timebuf[64];
  2208. timebuf[0] = '\0';
  2209. text[0][0] = '\0';
  2210. text[1][0] = '\0';
  2211. text[2][0] = '\0';
  2212.  
  2213. ReadPackString(pack, text[0], sizeof(text[]));
  2214. ReadPackString(pack, text[1], sizeof(text[]));
  2215. ReadPackString(pack, text[2], sizeof(text[]));
  2216. Karaoke_Message(text);
  2217.  
  2218. if (karaokeFile != INVALID_HANDLE)
  2219. {
  2220. if (KvGotoNextKey(karaokeFile))
  2221. {
  2222. text[0][0] = '\0';
  2223. text[1][0] = '\0';
  2224. text[2][0] = '\0';
  2225. KvGetString(karaokeFile,"text",text[0],sizeof(text[]));
  2226. KvGetString(karaokeFile,"text1",text[1],sizeof(text[]));
  2227. KvGetString(karaokeFile,"text2",text[2],sizeof(text[]));
  2228. KvGetString(karaokeFile,"time",timebuf,sizeof(timebuf));
  2229. new Float:time = Convert_Time(timebuf);
  2230. new Float:current_time = GetEngineTime() - karaokeStartTime;
  2231.  
  2232. new Handle:next_pack;
  2233. karaokeTimer = CreateDataTimer(time-current_time, Karaoke_Timer, next_pack, TIMER_FLAG_NO_MAPCHANGE);
  2234. WritePackString(next_pack, text[0]);
  2235. WritePackString(next_pack, text[1]);
  2236. WritePackString(next_pack, text[2]);
  2237. ResetPack(next_pack);
  2238. }
  2239. else
  2240. {
  2241. CloseHandle(karaokeFile);
  2242. karaokeFile = INVALID_HANDLE;
  2243. karaokeTimer = INVALID_HANDLE;
  2244. karaokeStartTime = 0.0;
  2245.  
  2246. if (cvaradvertisements != INVALID_HANDLE)
  2247. {
  2248. SetConVarBool(cvaradvertisements, advertisements_enabled);
  2249. CloseHandle(cvaradvertisements);
  2250. cvaradvertisements = INVALID_HANDLE;
  2251. }
  2252. }
  2253. }
  2254. else
  2255. {
  2256. karaokeTimer = INVALID_HANDLE;
  2257. }
  2258. }
  2259.  
  2260. //*****************************************************************
  2261. // ------------------------------------------------------------- *
  2262. // *** Command Handling *** *
  2263. // ------------------------------------------------------------- *
  2264. //*****************************************************************
  2265. //####### Command Sound Reset #######
  2266. public Action:Command_Sound_Reset(client, args)
  2267. {
  2268. if (args < 1)
  2269. {
  2270. //ReplyToCommand(client, "[Say Sounds] Usage: sm_sound_reset <user | all> : Resets sound quota for user, or everyone if all");
  2271. ReplyToCommand(client, "\x04[Say Sounds] \x01%t", "QuotaResetUsage");
  2272. return Plugin_Handled;
  2273. }
  2274.  
  2275. new String:arg[64];
  2276. GetCmdArg(1, arg, sizeof(arg));
  2277.  
  2278. if (strcmp(arg,"all",false) == 0 )
  2279. {
  2280. for (new i = 1; i <= MAXPLAYERS; i++)
  2281. SndCount[i] = 0;
  2282.  
  2283. if(client !=0)
  2284. {
  2285. //ReplyToCommand(client, "[Say Sounds] Quota has been reset for all players");
  2286. ReplyToCommand(client, "\x04[Say Sounds] \x01%t", "QuotaResetAll");
  2287. }
  2288. }
  2289. else
  2290. {
  2291. decl String:name[64];
  2292. new bool:isml,clients[MAXPLAYERS+1];
  2293. new count=ProcessTargetString(arg,client,clients,MAXPLAYERS+1,COMMAND_FILTER_NO_BOTS,name,sizeof(name),isml);
  2294. if (count > 0)
  2295. {
  2296. for(new x=0;x<count;x++)
  2297. {
  2298. new player=clients[x];
  2299. if(IsPlayerAlive(player))
  2300. {
  2301. SndCount[player] = 0;
  2302. new String:clientname[64];
  2303. GetClientName(player,clientname,MAXPLAYERS);
  2304. //ReplyToCommand(client, "[Say Sounds] Quota has been reset for %s", clientname);
  2305. ReplyToCommand(client, "\x04[Say Sounds] \x01%t", "QuotaResetUser", clientname);
  2306. }
  2307. }
  2308. }
  2309. else
  2310. ReplyToTargetError(client, count);
  2311. }
  2312. return Plugin_Handled;
  2313. }
  2314.  
  2315. //####### Command Sound Ban #######
  2316. public Action:Command_Sound_Ban(client, args)
  2317. {
  2318. if (args < 1)
  2319. {
  2320. //ReplyToCommand(client, "[Say Sounds] Usage: sm_sound_ban <user> : Bans a player from using sounds");
  2321. ReplyToCommand(client, "\x04[Say Sounds] \x01%t", "SoundBanUsage");
  2322. return Plugin_Handled;
  2323. }
  2324.  
  2325. new String:arg[64];
  2326. GetCmdArg(1, arg, sizeof(arg));
  2327.  
  2328. decl String:name[64];
  2329. new bool:isml,clients[MAXPLAYERS+1];
  2330. new count=ProcessTargetString(arg,client,clients,MAXPLAYERS+1,COMMAND_FILTER_NO_BOTS,name,sizeof(name),isml);
  2331. if (count > 0)
  2332. {
  2333. for(new x=0;x<count;x++)
  2334. {
  2335. new player=clients[x];
  2336. if(IsClientConnected(player) && IsClientInGame(player))
  2337. {
  2338. new String:clientname[64];
  2339. GetClientName(player,clientname,MAXPLAYERS);
  2340. if (checkClientCookies(player, CHK_BANNED))
  2341. {
  2342. //ReplyToCommand(client, "[Say Sounds] %s is already banned!", clientname);
  2343. ReplyToCommand(client, "\x04[Say Sounds] \x01%t", "AlreadyBanned", clientname);
  2344. }
  2345. else
  2346. {
  2347. SetClientCookie(player, g_ssban_cookie, "on");
  2348. //restrict_playing_sounds[player]=1;
  2349. //ReplyToCommand(client,"[Say Sounds] %s has been banned!", clientname);
  2350. ReplyToCommand(client,"\x04[Say Sounds] \x01%t", "PlayerBanned", clientname);
  2351. }
  2352. }
  2353. }
  2354. }
  2355. else
  2356. ReplyToTargetError(client, count);
  2357.  
  2358. return Plugin_Handled;
  2359. }
  2360.  
  2361. //####### Command Sound Unban #######
  2362. public Action:Command_Sound_Unban(client, args)
  2363. {
  2364. if (args < 1)
  2365. {
  2366. //ReplyToCommand(client, "[Say Sounds] Usage: sm_sound_unban <user> <1|0> : Unbans a player from using sounds");
  2367. ReplyToCommand(client, "\x04[Say Sounds] \x01%t", "SoundUnbanUsage");
  2368. return Plugin_Handled;
  2369. }
  2370.  
  2371. new String:arg[64];
  2372. GetCmdArg(1, arg, sizeof(arg));
  2373.  
  2374. decl String:name[64];
  2375. new bool:isml,clients[MAXPLAYERS+1];
  2376. new count=ProcessTargetString(arg,client,clients,MAXPLAYERS+1,COMMAND_FILTER_NO_BOTS,name,sizeof(name),isml);
  2377. if (count > 0)
  2378. {
  2379. for(new x=0;x<count;x++)
  2380. {
  2381. new player=clients[x];
  2382. if(IsClientConnected(player) && IsClientInGame(player))
  2383. {
  2384. new String:clientname[64];
  2385. GetClientName(player,clientname,MAXPLAYERS);
  2386. if(!checkClientCookies(player, CHK_BANNED))
  2387. {
  2388. //ReplyToCommand(client,"[Say Sounds] %s is not banned!", clientname);
  2389. ReplyToCommand(client,"\x04[Say Sounds] \x01%t", "NotBanned", clientname);
  2390. }
  2391. else
  2392. {
  2393. SetClientCookie(player, g_ssban_cookie, "off");
  2394. //restrict_playing_sounds[player]=0;
  2395. //ReplyToCommand(client,"[Say Sounds] %s has been unbanned!", clientname);
  2396. ReplyToCommand(client,"\x04[Say Sounds] \x01%t", "PlayerUnbanned", clientname);
  2397. }
  2398. }
  2399. }
  2400. }
  2401. else
  2402. ReplyToTargetError(client, count);
  2403.  
  2404. return Plugin_Handled;
  2405. }
  2406.  
  2407. //####### Command Sound List #######
  2408. public Action:Command_Sound_List(client, args)
  2409. {
  2410. List_Sounds(client);
  2411. }
  2412.  
  2413. //####### List Sounds #######
  2414. List_Sounds(client)
  2415. {
  2416. KvRewind(listfile);
  2417. if (KvJumpToKey(listfile, "ExitSound", false))
  2418. KvGotoNextKey(listfile, true);
  2419. else
  2420. KvGotoFirstSubKey(listfile);
  2421.  
  2422. decl String:buffer[PLATFORM_MAX_PATH+1];
  2423. do
  2424. {
  2425. KvGetSectionName(listfile, buffer, sizeof(buffer));
  2426. PrintToConsole(client, buffer);
  2427. } while (KvGotoNextKey(listfile));
  2428. }
  2429.  
  2430. public Action:Command_Sound_Menu(client, args)
  2431. {
  2432. Sound_Menu(client,normal_sounds);
  2433. }
  2434.  
  2435. public Action:Command_Admin_Sounds(client, args)
  2436. {
  2437. Sound_Menu(client,admin_sounds);
  2438. }
  2439.  
  2440. public Action:Command_Karaoke(client, args)
  2441. {
  2442. Sound_Menu(client,karaoke_sounds);
  2443. }
  2444.  
  2445. public Action:Command_All_Sounds(client, args)
  2446. {
  2447. Sound_Menu(client,all_sounds);
  2448. }
  2449.  
  2450. //*****************************************************************
  2451. // ------------------------------------------------------------- *
  2452. // *** Clear SoundCount Trie *** *
  2453. // ------------------------------------------------------------- *
  2454. //*****************************************************************
  2455. ClearSoundCountTrie()
  2456. {
  2457. // if there are no limits, there is no need to save counts
  2458. if (GetConVarBool(cvarTrackDisconnects) &&
  2459. (GetConVarInt(cvarsoundlimit) > 0 ||
  2460. GetConVarInt(cvaradminlimit) > 0))
  2461. {
  2462. if (g_hSoundCountTrie == INVALID_HANDLE)
  2463. g_hSoundCountTrie = CreateTrie();
  2464. else
  2465. ClearTrie(g_hSoundCountTrie);
  2466. }
  2467. else if (g_hSoundCountTrie)
  2468. {
  2469. CloseHandle(g_hSoundCountTrie);
  2470. g_hSoundCountTrie = INVALID_HANDLE;
  2471. }
  2472. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement