Advertisement
Guest User

Untitled

a guest
Jan 11th, 2015
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.57 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #include <sourcemod>
  4. #include <sdktools>
  5.  
  6. #define PLUGIN_NAME "Stop Map Music"
  7. #define PLUGIN_VERSION "1.0.0"
  8.  
  9. #define MAX_EDICTS 2048
  10.  
  11. new Float:g_fCmdTime[MAXPLAYERS+1];
  12. new g_iSoundEnts[MAX_EDICTS];
  13. new g_iNumSounds;
  14.  
  15. public Plugin:myinfo =
  16. {
  17. name = PLUGIN_NAME,
  18. author = "GoD-Tony",
  19. description = "Allows clients to stop ambient sounds played by the map",
  20. version = PLUGIN_VERSION,
  21. url = "http://www.sourcemod.net/"
  22. };
  23.  
  24. public OnPluginStart()
  25. {
  26. CreateConVar("sm_stopmusic_version", PLUGIN_VERSION, "Stop Map Music", FCVAR_PLUGIN|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  27.  
  28. HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
  29.  
  30. RegConsoleCmd("sm_stopmusic", Command_StopMusic, "Stops map music");
  31. }
  32.  
  33. public OnClientDisconnect_Post(client)
  34. {
  35. g_fCmdTime[client] = 0.0;
  36. }
  37.  
  38. public Event_RoundStart(Handle:event, const String:name[], bool:dontBroadcast)
  39. {
  40. // Ents are recreated every round.
  41. g_iNumSounds = 0;
  42.  
  43. // Find all ambient sounds played by the map.
  44. decl String:sSound[PLATFORM_MAX_PATH];
  45. new entity = INVALID_ENT_REFERENCE;
  46.  
  47. while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE)
  48. {
  49. GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
  50.  
  51. new len = strlen(sSound);
  52. if (len > 4 && (StrEqual(sSound[len-3], "mp3") || StrEqual(sSound[len-3], "wav")))
  53. {
  54. g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
  55. }
  56. }
  57. }
  58.  
  59. public Action:Command_StopMusic(client, args)
  60. {
  61. // Prevent this command from being spammed.
  62. if (!client || g_fCmdTime[client] > GetGameTime())
  63. return Plugin_Handled;
  64.  
  65. g_fCmdTime[client] = GetGameTime() + 5.0;
  66.  
  67. PrintToChat(client, "[SM] Stopping map music...");
  68.  
  69. // Run StopSound on all ambient sounds in the map.
  70. decl String:sSound[PLATFORM_MAX_PATH], entity;
  71.  
  72. for (new i = 0; i < g_iNumSounds; i++)
  73. {
  74. entity = EntRefToEntIndex(g_iSoundEnts[i]);
  75.  
  76. if (entity != INVALID_ENT_REFERENCE)
  77. {
  78. GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
  79. Client_StopSound(client, entity, SNDCHAN_STATIC, sSound);
  80. }
  81. }
  82.  
  83. return Plugin_Handled;
  84. }
  85.  
  86. /**
  87. * Stops a sound for one client.
  88. *
  89. * @param client Client index.
  90. * @param entity Entity index.
  91. * @param channel Channel number.
  92. * @param name Sound file name relative to the "sounds" folder.
  93. * @noreturn
  94. */
  95. stock Client_StopSound(client, entity, channel, const String:name[])
  96. {
  97. EmitSoundToClient(client, name, entity, channel, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement