sharivan

roundsound_zmbr

Nov 15th, 2014 (edited)
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.69 KB | Source Code | 0 0
  1. /* *
  2.  * RoundSound BY TUMMIETUM (TUMTUM) and modified by SHARIVAN from ΖмBя.™ Clan
  3.  * -------------------------
  4.  * Changelog Original Roundsound++ by ANTiCHRiST
  5.  * -------------------------
  6.  * by TanaToS aka ANTiCHRiST
  7.  */
  8.  
  9. #include <sourcemod>
  10. #include <sdktools>
  11. #include <smlib>
  12.  
  13. #pragma semicolon 1
  14.  
  15. #define PLUGIN_VERSION "1.2.0"
  16.  
  17. #define MAX_SOUND_PER_TEAM          256
  18. #define MAX_FILE_NAME_LENGTH        256
  19.  
  20. new t_win_snd_count;
  21. new String:t_win_snd[MAX_SOUND_PER_TEAM][MAX_FILE_NAME_LENGTH];
  22. new ct_win_snd_count;
  23. new String:ct_win_snd[MAX_SOUND_PER_TEAM][MAX_FILE_NAME_LENGTH];
  24.  
  25. new Handle:g_hEnabled = INVALID_HANDLE;
  26. new bool:g_bEnabled = true;
  27.  
  28. public Plugin:myinfo = {
  29.     name = "Round Sound CS:GO",
  30.     author = "ANTiCHRiST Edited by TumTum, SilentBr  from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan",
  31.     description = "Plays a Sound at RoundEnd.",
  32.     version = PLUGIN_VERSION,
  33.     url = "http://www.zmbrasil.com.br"
  34. };
  35.  
  36. public OnPluginStart() {
  37.     CreateConVar("sm_roundsound_version", PLUGIN_VERSION, "Versão.", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  38.     g_hEnabled = CreateConVar("roundsound_enable", "1", "Habilita ou desabilita este plugin.", FCVAR_PLUGIN|FCVAR_NOTIFY);
  39.    
  40.     AutoExecConfig(true, "roundsound_zmbr");
  41.  
  42.     HookEvent("round_end", OnRoundEnd);
  43.    
  44.     HookConVarChange(g_hEnabled, OnConVarChanged);
  45.    
  46.     t_win_snd_count = 0;
  47.     ct_win_snd_count = 0;
  48. }
  49.  
  50. public OnPluginEnd() {
  51.     UnhookEvent("round_end", OnRoundEnd);
  52.    
  53.     UnhookConVarChange(g_hEnabled, OnConVarChanged);
  54. }
  55.  
  56. public OnMapStart() {
  57.     t_win_snd_count = 0;
  58.     ct_win_snd_count = 0;
  59.    
  60.     new Handle:hFile = CreateKeyValues("roundsound");
  61.     KvSetEscapeSequences(hFile, true);
  62.    
  63.     decl String:sPath[PLATFORM_MAX_PATH];
  64.     BuildPath(Path_SM, sPath, sizeof(sPath), "configs/roundsound.cfg");
  65.     if (!FileExists(sPath)) {
  66.         LogMessage("Config file '%s' not found.", sPath);
  67.         return;
  68.     }
  69.    
  70.     if (!FileToKeyValues(hFile, sPath)) {
  71.         LogError("Error on loading key values config file '%s'.", sPath);
  72.         return;
  73.     }
  74.  
  75.     decl String:soundName[MAX_FILE_NAME_LENGTH];
  76.     if (KvJumpToKey(hFile, "terrorists", false)) {
  77.         KvGotoFirstSubKey(hFile, false);
  78.         do {
  79.             KvGetString(hFile, NULL_STRING, soundName, sizeof(soundName));
  80.             if (strlen(soundName) == 0)
  81.                 continue;
  82.  
  83.             AddTSound(soundName);
  84.         } while (KvGotoNextKey(hFile, false));
  85.     }
  86.     KvRewind(hFile);
  87.     if (KvJumpToKey(hFile, "counter-terrorists", false)) {
  88.         KvGotoFirstSubKey(hFile, false);
  89.         do {
  90.             KvGetString(hFile, NULL_STRING, soundName, sizeof(soundName));
  91.             if (strlen(soundName) == 0)
  92.                 continue;
  93.  
  94.             AddCTSound(soundName);
  95.         } while (KvGotoNextKey(hFile, false));
  96.     }
  97.  
  98.     CloseHandle(hFile);
  99. }
  100.  
  101. public OnConfigsExecuted() {
  102.     g_bEnabled = GetConVarBool(g_hEnabled);
  103. }
  104.  
  105. public OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast) {
  106.     if (!g_bEnabled)
  107.         return;
  108.        
  109.     SetRandomSeed(GetTime());
  110.     new winner = GetEventInt(event, "winner");
  111.     switch (winner) {
  112.         case 2: {
  113.             new random = GetRandomInt(0, t_win_snd_count - 1);
  114.             PlaySoundToAll(t_win_snd[random]);
  115.         }
  116.         case 3: {
  117.             new random = GetRandomInt(0, ct_win_snd_count - 1);
  118.             PlaySoundToAll(ct_win_snd[random]);
  119.         }
  120.     }
  121. }
  122.  
  123. public OnConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[]) {
  124.     if (convar == g_hEnabled)
  125.         g_bEnabled = GetConVarBool(g_hEnabled);
  126. }
  127.  
  128. AddCTSound(const String:soundName[]) {
  129.     decl String:soundFile1[MAX_FILE_NAME_LENGTH];
  130.     Format(soundFile1, sizeof(soundFile1), "roundsound/%s", soundName);
  131.     decl String:soundFile2[MAX_FILE_NAME_LENGTH];
  132.     Format(soundFile2, sizeof(soundFile2), "sound/%s", soundFile1);
  133.     if (FileExists(soundFile2)) {
  134.         strcopy(ct_win_snd[ct_win_snd_count++], MAX_FILE_NAME_LENGTH, soundName);
  135.         AddFileToDownloadsTable(soundFile2);
  136.         PrecacheSound(soundFile1, true);
  137.         LogMessage("Counter-Terrorist sound added: %s", soundName);
  138.     } else
  139.         LogError("Counter-Terrorist sound '%s' not found.", soundName);
  140. }
  141.  
  142. AddTSound(const String:soundName[]) {
  143.     decl String:soundFile1[MAX_FILE_NAME_LENGTH];
  144.     Format(soundFile1, sizeof(soundFile1), "roundsound/%s", soundName);
  145.     decl String:soundFile2[MAX_FILE_NAME_LENGTH];
  146.     Format(soundFile2, sizeof(soundFile2), "sound/%s", soundFile1);
  147.     if (FileExists(soundFile2)) {
  148.         strcopy(t_win_snd[t_win_snd_count++], MAX_FILE_NAME_LENGTH, soundName);
  149.         AddFileToDownloadsTable(soundFile2);
  150.         PrecacheSound(soundFile1, true);
  151.         LogMessage("Terrorist sound added: %s", soundName);
  152.     } else
  153.         LogError("Terrorist sound '%s' not found.", soundName);
  154. }
  155.  
  156. PlaySoundToAll(const String:soundName[]) {
  157.     for (new client = 1; client <= MaxClients; client++)
  158.         if(Client_IsIngame(client) && !IsFakeClient(client))
  159.             ClientCommand(client, "play *roundsound/%s", soundName);
  160. }
Advertisement
Add Comment
Please, Sign In to add comment