sharivan

roundsound_zmbr

Nov 21st, 2014 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 31.56 KB | Source Code | 0 0
  1. /* *
  2.  * RoundSound BY TUMMIETUM (TUMTUM) and modified by SilentBr from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan
  3.  * -------------------------
  4.  * Changelog Original Roundsound++ by ANTiCHRiST
  5.  * -------------------------
  6.  * by TanaToS aka ANTiCHRiST, SilentBr from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan
  7.  */
  8.  
  9. #include <sourcemod>
  10. #include <sdktools>
  11. #include <clientprefs>
  12. #include <cstrike>
  13. #include <smlib>
  14. #include <emitsoundany>
  15.  
  16. #pragma semicolon 1
  17.  
  18. #define PLUGIN_VERSION "1.4.0"
  19.  
  20. #define MAX_SOUND_PER_TEAM          256
  21. #define MAX_EDICTS                  2048
  22.  
  23. #define ROUND_STATE_UNDEFINED       0
  24. #define ROUND_STATE_STARTED         1
  25. #define ROUND_STATE_STOPED          2
  26.  
  27. #define MAX_AUTHID_LENGTH           64
  28. #define MAX_CLIENTNAME_LENGTH       64
  29.  
  30. enum client_data {
  31.     String:steamid[MAX_AUTHID_LENGTH],
  32.     String:last_name[MAX_CLIENTNAME_LENGTH]
  33. }
  34.  
  35. enum music_data {
  36.     String:music_name[PLATFORM_MAX_PATH],
  37.     String:file_name[PLATFORM_MAX_PATH],
  38.     String:artist[PLATFORM_MAX_PATH],
  39.     String:title[PLATFORM_MAX_PATH],
  40.     music_team,
  41.     Handle:likes,
  42.     Handle:dislikes
  43. }
  44.  
  45. // cvars
  46. new Handle:roundsound_enable = INVALID_HANDLE;
  47. new bool:g_bEnabled = true;
  48.  
  49. // cookies
  50. new Handle:c_RoundSoundEnable = INVALID_HANDLE;
  51.  
  52. new Handle:roundsound_round_restart_delay = INVALID_HANDLE;
  53. new Float:g_iRoundRestartDelay = -1;
  54.  
  55. // globals
  56. new g_iRoundState = ROUND_STATE_UNDEFINED;
  57.  
  58. new g_iSoundEnts[MAX_EDICTS] = {INVALID_ENT_REFERENCE, ...};
  59. new g_iNumSounds = 0;
  60.  
  61. new t_win_snd_count = 0;
  62. new t_win_snd_pos = 0;
  63. new t_win_snd[MAX_SOUND_PER_TEAM][music_data];
  64.  
  65. new ct_win_snd_count = 0;
  66. new ct_win_snd_pos = 0;
  67. new ct_win_snd[MAX_SOUND_PER_TEAM][music_data];
  68.  
  69. new g_bMusicIsPlaying = false;
  70. new g_CurrentMusic[music_data];
  71.  
  72. new bool:g_bSoundEnabled[MAXPLAYERS + 1] = {true, ...};
  73. new bool:g_bPlayingMusic[MAXPLAYERS + 1] = {false, ...};
  74. new g_MusicPlaying[MAXPLAYERS + 1][music_data];
  75.  
  76. new Handle:g_hDatabase = INVALID_HANDLE;
  77. new bool:g_bIsMYSQL = false;
  78.  
  79. new bool:g_bMapLoaded = false;
  80. new bool:g_bLikesLoaded = false;
  81.  
  82. public Plugin:myinfo = {
  83.     name = "Round Sound CS:GO",
  84.     author = "ANTiCHRiST Edited by TumTum, SilentBr from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan",
  85.     description = "Plays a Sound at RoundEnd.",
  86.     version = PLUGIN_VERSION,
  87.     url = "http://www.zmbrasil.com.br/"
  88. };
  89.  
  90. public OnPluginStart() {
  91.     CreateConVar("roundsound_version", PLUGIN_VERSION, "Versão.", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_CHEAT|FCVAR_DONTRECORD);
  92.     roundsound_enable = CreateConVar("roundsound_enable", "1", "Habilita ou desabilita este plugin.", FCVAR_PLUGIN|FCVAR_NOTIFY);
  93.     roundsound_round_restart_delay = CreateConVar("roundsound_round_restart_delay", "-1", "Tempo (em segundos) entre o final do round e o início do round posterior (numa mesma partida). Sete para -1 para usar o padrão do servidor.", FCVAR_PLUGIN|FCVAR_NOTIFY);
  94.    
  95.     RegConsoleCmd("sm_roundsound", Command_RoundSound, "Abre o menu de opções para as músicas de fim de round.");
  96.     RegConsoleCmd("sm_music", Command_RoundSound, "O mesmo que sm_roundsound.");
  97.     RegConsoleCmd("sm_musics", Command_RoundSound, "O mesmo que sm_roundsound.");
  98.     RegConsoleCmd("sm_musica", Command_RoundSound, "O mesmo que sm_roundsound.");
  99.     RegConsoleCmd("sm_musicas", Command_RoundSound, "O mesmo que sm_roundsound.");
  100.     RegConsoleCmd("sm_song", Command_RoundSound, "O mesmo que sm_roundsound.");
  101.     RegConsoleCmd("sm_songs", Command_RoundSound, "O mesmo que sm_roundsound.");
  102.     RegConsoleCmd("sm_sound", Command_RoundSound, "O mesmo que sm_roundsound.");
  103.     RegConsoleCmd("sm_sounds", Command_RoundSound, "O mesmo que sm_roundsound.");
  104.    
  105.     AddCommandListener(Command_PlayMusic, "sm_play");
  106.    
  107.     c_RoundSoundEnable = RegClientCookie("RoundSoundEnable", "Round Sound Enable", CookieAccess_Private);
  108.    
  109.     AutoExecConfig(true, "roundsound_zmbr");
  110.    
  111.     LoadTranslations("common.phrases");
  112.     LoadTranslations("roundsound.phrases");
  113.  
  114.     HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
  115.     HookEvent("round_end", OnRoundEnd);
  116.    
  117.     HookConVarChange(roundsound_enable, OnConVarChanged);
  118.     HookConVarChange(roundsound_round_restart_delay, OnConVarChanged);
  119.    
  120.     AddAmbientSoundHook(AmbientSHook);
  121. }
  122.  
  123. public OnPluginEnd() {
  124.     UnhookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
  125.     UnhookEvent("round_end", OnRoundEnd);
  126.    
  127.     UnhookConVarChange(roundsound_enable, OnConVarChanged);
  128.     UnhookConVarChange(roundsound_round_restart_delay, OnConVarChanged);
  129.    
  130.     RemoveAmbientSoundHook(AmbientSHook);
  131. }
  132.  
  133. bool:ReadMusicData(Handle:hFile, music[music_data], team) {
  134.     decl String:buff[256];
  135.     KvGetSectionName(hFile, buff, sizeof(buff));
  136.     if (strlen(buff) == 0)
  137.         return false;
  138.        
  139.     strcopy(music[music_name], PLATFORM_MAX_PATH, buff);
  140.    
  141.     decl client[client_data];
  142.     music[likes] = CreateArray(sizeof(client));
  143.     music[dislikes] = CreateArray(sizeof(client));
  144.     music[music_team] = team;
  145.    
  146.     KvGetString(hFile, "file", buff, sizeof(buff));
  147.     strcopy(music[file_name], PLATFORM_MAX_PATH, buff);
  148.    
  149.     KvGetString(hFile, "artist", buff, sizeof(buff));
  150.     strcopy(music[artist], PLATFORM_MAX_PATH, buff);
  151.    
  152.     KvGetString(hFile, "title", buff, sizeof(buff));
  153.     strcopy(music[title], PLATFORM_MAX_PATH, buff);
  154.    
  155.     LoadLike(music);
  156.    
  157.     return true;
  158. }
  159.  
  160. public OnMapStart() {
  161.     g_bMapLoaded = true;
  162.    
  163.     SetRandomSeed(GetTime());
  164.    
  165.     g_iRoundState = ROUND_STATE_UNDEFINED;
  166.    
  167.     t_win_snd_count = 0;
  168.     t_win_snd_pos = 0;
  169.     ct_win_snd_count = 0;
  170.     ct_win_snd_pos = 0;
  171.    
  172.     new Handle:hFile = CreateKeyValues("roundsound");
  173.     KvSetEscapeSequences(hFile, true);
  174.    
  175.     decl String:sPath[PLATFORM_MAX_PATH];
  176.     BuildPath(Path_SM, sPath, sizeof(sPath), "configs/roundsound.cfg");
  177.     if (!FileExists(sPath)) {
  178.         LogMessage("Config file '%s' not found.", sPath);
  179.         return;
  180.     }
  181.    
  182.     if (!FileToKeyValues(hFile, sPath)) {
  183.         LogError("Error on loading key values config file '%s'.", sPath);
  184.         return;
  185.     }
  186.  
  187.     decl String:soundName[PLATFORM_MAX_PATH];
  188.     if (KvJumpToKey(hFile, "terrorists", false)) {
  189.         KvGotoFirstSubKey(hFile, false);
  190.         do {
  191.             decl music[music_data];
  192.             if (ReadMusicData(hFile, music, CS_TEAM_T))
  193.                 AddTSound(music);
  194.         } while (KvGotoNextKey(hFile, false));
  195.     }
  196.     for (new i = 0; i < t_win_snd_count; i++) {
  197.         new random = GetRandomInt(0, t_win_snd_count - 1);
  198.         decl temp[music_data];
  199.         temp = t_win_snd[i];
  200.         t_win_snd[i] = t_win_snd[random];
  201.         t_win_snd[random] = temp;
  202.     }
  203.    
  204.     KvRewind(hFile);
  205.     if (KvJumpToKey(hFile, "counter-terrorists", false)) {
  206.         KvGotoFirstSubKey(hFile, false);
  207.         do {
  208.             //KvGetString(hFile, NULL_STRING, soundName, sizeof(soundName));
  209.             decl music[music_data];
  210.             if (ReadMusicData(hFile, music, CS_TEAM_CT))
  211.                 AddCTSound(music);
  212.         } while (KvGotoNextKey(hFile, false));
  213.     }
  214.     for (new i = 0; i < ct_win_snd_count; i++) {
  215.         new random = GetRandomInt(0, ct_win_snd_count - 1);
  216.         decl temp[music_data];
  217.         temp = ct_win_snd[i];
  218.         ct_win_snd[i] = ct_win_snd[random];
  219.         ct_win_snd[random] = temp;
  220.     }
  221.  
  222.     CloseHandle(hFile);
  223. }
  224.  
  225. public OnMapEnd() {
  226.     g_bMapLoaded = false;
  227.     g_bLikesLoaded = false;
  228. }
  229.  
  230. public OnConfigsExecuted() {
  231.     g_bEnabled = GetConVarBool(roundsound_enable);
  232.     g_iRoundRestartDelay = GetConVarInt(roundsound_round_restart_delay);
  233.    
  234.     if(g_hDatabase == INVALID_HANDLE)
  235.         SQL_TConnect(SQL_ConnectCall, "storage-local");
  236. }
  237.  
  238. public SQL_ConnectCall(Handle:owner, Handle:hndl, const String:error[], any:data) {
  239.     if(hndl == INVALID_HANDLE || strlen(error) > 0) {
  240.         LogError("RoundSound was unable to establish a database connection!");
  241.         decl String:_sError[512];
  242.         if(hndl != INVALID_HANDLE && SQL_GetError(hndl, _sError, 512))
  243.             LogError("- SQL_ConnectCall: %s", _sError);
  244.         else
  245.             LogError("- SQL_ConnectCall: %s", error);
  246.     } else {
  247.         g_hDatabase = hndl;
  248.         sqldbtable();
  249.     }
  250. }
  251.  
  252. sqldbtable() {
  253.     decl String:sdbtype[64];
  254.     decl String:squery[256];
  255.     SQL_ReadDriver(g_hDatabase, sdbtype, sizeof(sdbtype));
  256.     if(StrEqual(sdbtype, "sqlite", false)) {
  257.         g_bIsMYSQL = false;
  258.         squery = "CREATE TABLE IF NOT EXISTS likes (music VARCHAR(64) NOT NULL, steamid VARCHAR(64) NOT NULL, lastname TEXT NULL, like INT NULL DEFAULT 0, PRIMARY KEY (music, steamid));";
  259.     }
  260.     else {
  261.         g_bIsMYSQL = true;
  262.         squery = "CREATE TABLE IF NOT EXISTS likes (music VARCHAR(64) NOT NULL, steamid VARCHAR(64) NOT NULL, lastname TEXT NULL, like INT NULL DEFAULT 0, PRIMARY KEY (music, steamid)) ENGINE = InnoDB;";
  263.     }
  264.     SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
  265.    
  266.     LoadLikes();
  267. }
  268.  
  269. LoadLikes() {
  270.     if (!g_bMapLoaded || g_bLikesLoaded || g_hDatabase == INVALID_HANDLE)
  271.         return;
  272.  
  273.     for (new index = 0; index < t_win_snd_count; index++)
  274.         LoadLike(t_win_snd[index]);
  275.    
  276.     for (new index = 0; index < ct_win_snd_count; index++)
  277.         LoadLike(ct_win_snd[index]);
  278.    
  279.     g_bLikesLoaded = true;
  280. }
  281.  
  282. LoadLike(music[music_data]) {
  283.     if (!g_bMapLoaded || g_bLikesLoaded || g_hDatabase == INVALID_HANDLE)
  284.         return;
  285.  
  286.     decl String:squery[256];
  287.     decl String:sqlMusic[64];
  288.     SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
  289.     Format(squery, sizeof(squery), "SELECT * FROM likes WHERE music = '%s'", sqlMusic);
  290.     SQL_TQuery(g_hDatabase, sqlT_GetLikes, squery);
  291. }
  292.  
  293. public sqlT_GetLikes(Handle:owner, Handle:hndl, const String:error[], any:data) {
  294.     if (hndl == INVALID_HANDLE)
  295.         LogError("%s", error);
  296.     else
  297.         while (SQL_FetchRow(hndl)) {
  298.             decl String:musicName[PLATFORM_MAX_PATH];
  299.             SQL_FetchString(hndl, 0, musicName, sizeof(musicName));
  300.            
  301.             decl music[music_data];
  302.             if (!GetMusicByName(musicName, music))
  303.                 continue;
  304.                
  305.             decl clientData[client_data];
  306.             SQL_FetchString(hndl, 1, clientData[steamid], MAX_AUTHID_LENGTH);
  307.             SQL_FetchString(hndl, 2, clientData[last_name], MAX_CLIENTNAME_LENGTH);
  308.            
  309.             new like = SQL_FetchInt(hndl, 3);
  310.            
  311.             switch (like) {
  312.                 case 1: // like
  313.                     PushArrayArray(music[likes], clientData, sizeof(clientData));
  314.                 case 2: // dislike
  315.                     PushArrayArray(music[dislikes], clientData, sizeof(clientData));
  316.             }
  317.         }
  318. }
  319.  
  320. public sqlT_Generic(Handle:owner, Handle:hndl, const String:error[], any:data) {
  321.     if (hndl == INVALID_HANDLE)
  322.         LogError("%s", error);
  323. }
  324.  
  325. public OnClientPutInServer(client) {
  326.     g_bPlayingMusic[client] = false;
  327. }
  328.  
  329. public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast) {
  330.     if (g_bMusicIsPlaying) {
  331.         g_bMusicIsPlaying = false;
  332.         StopSoundOnAll(g_CurrentMusic);
  333.     }
  334.    
  335.     g_iNumSounds = 0;
  336.    
  337.     decl String:sSound[PLATFORM_MAX_PATH];
  338.     new entity = INVALID_ENT_REFERENCE;
  339.     while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE) {
  340.         GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
  341.        
  342.         new len = strlen(sSound);
  343.         if (len > 4 && (StrEqual(sSound[len - 3], "mp3") || StrEqual(sSound[len - 3], "wav"))) {
  344.             g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
  345.         }
  346.     }
  347.    
  348.     g_iRoundState = ROUND_STATE_STARTED;
  349. }
  350.  
  351. public OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast) {
  352.     if (!g_bEnabled)
  353.         return;
  354.        
  355.     g_iRoundState = ROUND_STATE_STOPED;
  356.    
  357.     if (g_bMusicIsPlaying) {
  358.         StopSoundOnAll(g_CurrentMusic);
  359.         g_bMusicIsPlaying = false;
  360.     }
  361.    
  362.     new winner = GetEventInt(event, "winner");
  363.     switch (winner) {
  364.         case CS_TEAM_T: {
  365.             if (t_win_snd_count > 0) {
  366.                 g_CurrentMusic = t_win_snd[t_win_snd_pos];
  367.                 g_bMusicIsPlaying = true;
  368.                 t_win_snd_pos = (t_win_snd_pos + 1) % t_win_snd_count;
  369.             }
  370.         }
  371.         case CS_TEAM_CT: {
  372.             if (ct_win_snd_count > 0) {
  373.                 g_CurrentMusic = ct_win_snd[ct_win_snd_pos];
  374.                 g_bMusicIsPlaying = true;
  375.                 ct_win_snd_pos = (ct_win_snd_pos + 1) % ct_win_snd_count;
  376.             }
  377.         }
  378.     }
  379.    
  380.     if (!g_bMusicIsPlaying)
  381.         return;
  382.    
  383.     for (new client = 1; client <= MaxClients; client++)
  384.         if (IsClientInGame(client) && !IsFakeClient(client) && g_bSoundEnabled[client] && !IsMusicDislikedByClient(g_CurrentMusic, client))
  385.             ClientCommand(client, "playgamesound Music.StopAllMusic");
  386.        
  387.     // Run StopSound on all ambient sounds in the map.
  388.     decl String:sSound[PLATFORM_MAX_PATH];
  389.     for (new i = 0; i < g_iNumSounds; i++) {
  390.         new entity = EntRefToEntIndex(g_iSoundEnts[i]);
  391.        
  392.         if (entity != INVALID_ENT_REFERENCE) {
  393.             GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
  394.             for (new client = 1; client < MaxClients; client++)
  395.                 if (Client_IsIngame(client) && !IsFakeClient(client) && g_bSoundEnabled[client] && !IsMusicDislikedByClient(g_CurrentMusic, client))
  396.                     EmitSoundToClient(client, sSound, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
  397.         }
  398.     }
  399.  
  400.     CreateTimer(0.0, PlayMusicTimer, _, TIMER_FLAG_NO_MAPCHANGE);
  401. }
  402.  
  403. public Action:PlayMusicTimer(Handle:timer) {
  404.     if (g_bMusicIsPlaying)
  405.         PlaySoundToAll(g_CurrentMusic);
  406.        
  407.     return Plugin_Stop;
  408. }
  409.  
  410. public Action:CS_OnTerminateRound(&Float:delay, &CSRoundEndReason:reason) {
  411.     if (!g_bEnabled || g_iRoundState == ROUND_STATE_UNDEFINED || g_iRoundRestartDelay == -1)
  412.         return Plugin_Continue;
  413.  
  414.     delay = float(g_iRoundRestartDelay);
  415.    
  416.     return Plugin_Changed;
  417. }
  418.  
  419. public OnConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[]) {
  420.     if (convar == roundsound_enable)
  421.         g_bEnabled = GetConVarBool(roundsound_enable);
  422.     else if (convar == roundsound_round_restart_delay)
  423.         g_iRoundRestartDelay = GetConVarInt(roundsound_round_restart_delay);
  424. }
  425.  
  426. public OnClientCookiesCached(client) {
  427.     new String:strValue[16];
  428.     GetClientCookie(client, c_RoundSoundEnable, strValue, sizeof(strValue));
  429.     g_bSoundEnabled[client] = StrEqual(strValue, "") || StrEqual(strValue, "1") || StrEqual(strValue, "true");
  430.    
  431.     //LogMessage("Cookie for %N: '%s'", client, strValue);
  432. }
  433.  
  434. public Action:Command_RoundSound(client, args) {
  435.     MenuRoundSonund(client);
  436.    
  437.     return Plugin_Handled;
  438. }
  439.  
  440. MenuRoundSonund(client) {
  441.     new Handle:menu = CreateMenu(MenuHandlerRoundSound);
  442.    
  443.     decl String:buffer[256];
  444.    
  445.     Format(buffer, sizeof(buffer), "%T", "roundsound menu", client);
  446.     SetMenuTitle(menu, buffer);
  447.    
  448.     if (g_bSoundEnabled[client])
  449.         Format(buffer, sizeof(buffer), "%T", "roundsound disable", client);
  450.     else
  451.         Format(buffer, sizeof(buffer), "%T", "roundsound enable", client);
  452.     AddMenuItem(menu, "roundsound enabled", buffer);
  453.    
  454.     Format(buffer, sizeof(buffer), "%T", "terrorist musics", client);
  455.     AddMenuItem(menu, "terrorist musics", buffer);
  456.    
  457.     Format(buffer, sizeof(buffer), "%T", "counter-terrorist musics", client);
  458.     AddMenuItem(menu, "counter-terrorist musics", buffer);
  459.    
  460.     SetMenuExitButton(menu, true);
  461.    
  462.     DisplayMenu(menu, client, MENU_TIME_FOREVER);
  463. }
  464.  
  465. SubMenuTMusics(client) {
  466.     new Handle:menu = CreateMenu(SubMenuMusicsHandler);
  467.    
  468.     decl String:buffer[256];
  469.    
  470.     Format(buffer, sizeof(buffer), "%T", "terrorist musics", client);
  471.     SetMenuTitle(menu, buffer);
  472.    
  473.     for (new index = 0; index < t_win_snd_count; index++)
  474.         AddMenuItem(menu, t_win_snd[index][music_name], t_win_snd[index][music_name]);
  475.        
  476.     SetMenuExitBackButton(menu, true);
  477.        
  478.     DisplayMenu(menu, client, MENU_TIME_FOREVER);
  479. }
  480.  
  481. SubMenuCTMusics(client) {
  482.     new Handle:menu = CreateMenu(SubMenuMusicsHandler);
  483.    
  484.     decl String:buffer[256];
  485.    
  486.     Format(buffer, sizeof(buffer), "%T", "counter-terrorist musics", client);
  487.     SetMenuTitle(menu, buffer);
  488.    
  489.     for (new index = 0; index < ct_win_snd_count; index++)
  490.         AddMenuItem(menu, ct_win_snd[index][music_name], ct_win_snd[index][music_name]);
  491.        
  492.     SetMenuExitBackButton(menu, true);
  493.        
  494.     DisplayMenu(menu, client, MENU_TIME_FOREVER);
  495. }
  496.  
  497. SubMenuShowMusicInfo(client, music[music_data]) {
  498.     new Handle:menu = CreateMenu(SubMenuMusicInfoHandler);
  499.    
  500.     decl String:buffer[256];
  501.    
  502.     Format(buffer, sizeof(buffer), music[music_name]);
  503.     SetMenuTitle(menu, buffer);
  504.    
  505.     new bool:playing = g_bPlayingMusic[client] && StrEqual(g_MusicPlaying[client][music_name], music[music_name]);
  506.     new bool:liked = IsMusicLikedByClient(music, client);
  507.     new bool:disliked = IsMusicDislikedByClient(music, client);
  508.    
  509.     Format(buffer, sizeof(buffer), "%T", "play", client);
  510.     AddMenuItem(menu, "play", buffer, playing ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  511.     Format(buffer, sizeof(buffer), "%T", "stop", client);
  512.     AddMenuItem(menu, "stop", buffer, !playing ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  513.     Format(buffer, sizeof(buffer), "%T", "like", client);
  514.     AddMenuItem(menu, "like", buffer, liked ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  515.     Format(buffer, sizeof(buffer), "%T", "dislike", client);
  516.     AddMenuItem(menu, "dislike", buffer, disliked ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
  517.     Format(buffer, sizeof(buffer), "%T", "neutral", client);
  518.     AddMenuItem(menu, "neutral", buffer, (liked && !disliked || !liked && disliked) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
  519.        
  520.     SetMenuExitBackButton(menu, true);
  521.        
  522.     DisplayMenu(menu, client, MENU_TIME_FOREVER);
  523. }
  524.  
  525. public MenuHandlerRoundSound(Handle:menu, MenuAction:action, client, choice) {
  526.     switch (action) {
  527.         case MenuAction_Select: {
  528.             switch (choice) {
  529.                 case 0: { // enable/disable
  530.                     if (g_bSoundEnabled[client]) {
  531.                         g_bSoundEnabled[client] = false;
  532.                         SetClientCookie(client, c_RoundSoundEnable, "false");
  533.                         PrintToChat(client, " \x04[RS]\x01 %T.", "you disabled the roundsound", client);
  534.                        
  535.                         if (g_bMusicIsPlaying)
  536.                             StopSoundOnClient(g_CurrentMusic, client);
  537.                     }
  538.                     else {
  539.                         g_bSoundEnabled[client] = true;
  540.                         SetClientCookie(client, c_RoundSoundEnable, "true");
  541.                         PrintToChat(client, " \x04[RS]\x01 %T.", "you enabled the roundsound", client);
  542.                     }
  543.                     MenuRoundSonund(client);
  544.                 }
  545.                 case 1: { // terrorist musics
  546.                     SubMenuTMusics(client);
  547.                 }
  548.                 case 2: { // couter-terrorist musics
  549.                     SubMenuCTMusics(client);
  550.                 }
  551.             }
  552.         }
  553.         case MenuAction_End:
  554.             CloseHandle(menu);
  555.     }
  556. }
  557.  
  558. public SubMenuMusicsHandler(Handle:menu, MenuAction:action, client, choice) {
  559.     switch (action) {
  560.         case MenuAction_Select: {
  561.             decl String:musicName[PLATFORM_MAX_PATH];
  562.             GetMenuItem(menu, choice, musicName, sizeof(musicName));
  563.            
  564.             decl music[music_data];
  565.             if (GetMusicByName(musicName, music))
  566.                 SubMenuShowMusicInfo(client, music);
  567.             else
  568.                 MenuRoundSonund(client);
  569.         }
  570.         case MenuAction_Cancel: {
  571.             if (choice == MenuCancel_ExitBack)
  572.                 MenuRoundSonund(client);
  573.         }
  574.         case MenuAction_End:
  575.             CloseHandle(menu);
  576.     }
  577. }
  578.  
  579. public SubMenuMusicInfoHandler(Handle:menu, MenuAction:action, client, choice) {
  580.     switch (action) {
  581.         case MenuAction_Select: {
  582.             decl String:musicName[PLATFORM_MAX_PATH];
  583.             GetMenuTitle(menu, musicName, sizeof(musicName));
  584.            
  585.             decl music[music_data];
  586.             if (GetMusicByName(musicName, music)) {
  587.                 switch (choice) {
  588.                     case 0: PlaySoundToClient(music, client, true);
  589.                     case 1: StopSoundOnClient(music, client);
  590.                     case 2: LikeMusic(client, music);
  591.                     case 3: DislikeMusic(client, music);
  592.                     case 4: NeutralMusic(client, music);
  593.                 }
  594.                 SubMenuShowMusicInfo(client, music);
  595.             } else
  596.                 MenuRoundSonund(client);
  597.         }
  598.         case MenuAction_Cancel: {
  599.             if (choice == MenuCancel_ExitBack) {
  600.                 decl String:musicName[PLATFORM_MAX_PATH];
  601.                 GetMenuTitle(menu, musicName, sizeof(musicName));
  602.                
  603.                 decl music[music_data];
  604.                 if (GetMusicByName(musicName, music))
  605.                     switch (music[music_team]) {
  606.                         case CS_TEAM_T:
  607.                             SubMenuTMusics(client);
  608.                         case CS_TEAM_CT:
  609.                             SubMenuCTMusics(client);
  610.                     }
  611.                 else
  612.                     MenuRoundSonund(client);
  613.             }
  614.         }
  615.         case MenuAction_End:
  616.             CloseHandle(menu);
  617.     }
  618. }
  619.  
  620. LikeMusic(client, music[music_data]) {
  621.     if (IsMusicLikedByClient(music, client))
  622.         return;
  623.        
  624.     decl String:steamID[MAX_AUTHID_LENGTH];
  625.     steamID[0] = '\0';
  626.     GetClientAuthString(client, steamID, sizeof(steamID));
  627.        
  628.     new size = GetArraySize(music[dislikes]);
  629.     for (new index = 0; index < size; index++) {
  630.         decl clientData[client_data];
  631.         GetArrayArray(music[dislikes], index, clientData, sizeof(clientData));
  632.         if (StrEqual(steamID, clientData[steamid])) {
  633.             RemoveFromArray(music[dislikes], index);
  634.             break;
  635.         }
  636.     }
  637.    
  638.     decl clientData[client_data];
  639.     strcopy(clientData[steamid], MAX_AUTHID_LENGTH, steamID);
  640.     decl String:lastName[MAX_CLIENTNAME_LENGTH];
  641.     GetClientName(client, lastName, sizeof(lastName));
  642.     strcopy(clientData[last_name], MAX_AUTHID_LENGTH, steamID);
  643.     PushArrayArray(music[likes], clientData, sizeof(clientData));
  644.    
  645.     if (g_hDatabase != INVALID_HANDLE) {
  646.         decl String:squery[256];
  647.         decl String:sqlMusic[64];
  648.         SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
  649.         decl String:sqlSteamID[64];
  650.         SQL_EscapeString(g_hDatabase, steamID, sqlSteamID, sizeof(sqlSteamID));
  651.         decl String:sqlLastName[64];
  652.         SQL_EscapeString(g_hDatabase, lastName, sqlLastName, sizeof(sqlLastName));
  653.         Format(squery, sizeof(squery), "REPLACE INTO likes VALUES ('%s','%s','%s',%d)", sqlMusic, sqlSteamID, sqlLastName, 1);
  654.         SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
  655.     }
  656. }
  657.  
  658. DislikeMusic(client, music[music_data]) {
  659.     if (IsMusicDislikedByClient(music, client))
  660.         return;
  661.        
  662.     decl String:steamID[MAX_AUTHID_LENGTH];
  663.     steamID[0] = '\0';
  664.     GetClientAuthString(client, steamID, sizeof(steamID));
  665.        
  666.     new size = GetArraySize(music[likes]);
  667.     for (new index = 0; index < size; index++) {
  668.         decl clientData[client_data];
  669.         GetArrayArray(music[likes], index, clientData, sizeof(clientData));
  670.         if (StrEqual(steamID, clientData[steamid])) {
  671.             RemoveFromArray(music[likes], index);
  672.             break;
  673.         }
  674.     }
  675.    
  676.     decl clientData[client_data];
  677.     strcopy(clientData[steamid], MAX_AUTHID_LENGTH, steamID);
  678.     decl String:lastName[MAX_CLIENTNAME_LENGTH];
  679.     GetClientName(client, lastName, sizeof(lastName));
  680.     strcopy(clientData[last_name], MAX_AUTHID_LENGTH, steamID);
  681.     PushArrayArray(music[dislikes], clientData, sizeof(clientData));
  682.    
  683.     if (g_hDatabase != INVALID_HANDLE) {
  684.         decl String:squery[256];
  685.         decl String:sqlMusic[64];
  686.         SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
  687.         decl String:sqlSteamID[64];
  688.         SQL_EscapeString(g_hDatabase, steamID, sqlSteamID, sizeof(sqlSteamID));
  689.         decl String:sqlLastName[64];
  690.         SQL_EscapeString(g_hDatabase, lastName, sqlLastName, sizeof(sqlLastName));
  691.         Format(squery, sizeof(squery), "REPLACE INTO likes VALUES ('%s','%s','%s',%d)", sqlMusic, sqlSteamID, sqlLastName, 2);
  692.         SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
  693.     }
  694. }
  695.  
  696. NeutralMusic(client, music[music_data]) {
  697.     decl String:steamID[MAX_AUTHID_LENGTH];
  698.     steamID[0] = '\0';
  699.     GetClientAuthString(client, steamID, sizeof(steamID));
  700.     decl String:lastName[MAX_CLIENTNAME_LENGTH];
  701.     GetClientName(client, lastName, sizeof(lastName));
  702.    
  703.     new size = GetArraySize(music[likes]);
  704.     for (new index = 0; index < size; index++) {
  705.         decl clientData[client_data];
  706.         GetArrayArray(music[likes], index, clientData, sizeof(clientData));
  707.         if (StrEqual(steamID, clientData[steamid])) {
  708.             RemoveFromArray(music[likes], index);
  709.             break;
  710.         }
  711.     }
  712.        
  713.     size = GetArraySize(music[dislikes]);
  714.     for (new index = 0; index < size; index++) {
  715.         decl clientData[client_data];
  716.         GetArrayArray(music[dislikes], index, clientData, sizeof(clientData));
  717.         if (StrEqual(steamID, clientData[steamid])) {
  718.             RemoveFromArray(music[dislikes], index);
  719.             break;
  720.         }
  721.     }
  722.    
  723.     if (g_hDatabase != INVALID_HANDLE) {
  724.         decl String:squery[256];
  725.         decl String:sqlMusic[64];
  726.         SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
  727.         decl String:sqlSteamID[64];
  728.         SQL_EscapeString(g_hDatabase, steamID, sqlSteamID, sizeof(sqlSteamID));
  729.         decl String:sqlLastName[64];
  730.         SQL_EscapeString(g_hDatabase, lastName, sqlLastName, sizeof(sqlLastName));
  731.         Format(squery, sizeof(squery), "REPLACE INTO likes VALUES ('%s','%s','%s',%d)", sqlMusic, sqlSteamID, sqlLastName, 0);
  732.         SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
  733.     }
  734. }
  735.  
  736. public Action:Command_PlayMusic(client, const String:command[], args) {
  737.     if (args < 2) {
  738.         ReplyToCommand(client, "[SM] Uso: sm_play <#userid|name> <sample> [channel] [level]");
  739.         return Plugin_Handled;
  740.     }
  741.    
  742.     decl String:target_name[MAX_TARGET_LENGTH];
  743.     decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
  744.  
  745.     decl String:strTarget[192];
  746.     GetCmdArg(1, strTarget, sizeof(strTarget));
  747.    
  748.     target_count = ProcessTargetString(
  749.             strTarget,
  750.             client,
  751.             target_list,
  752.             MAXPLAYERS,
  753.             COMMAND_FILTER_CONNECTED,
  754.             target_name,
  755.             sizeof(target_name),
  756.             tn_is_ml);
  757.            
  758.  
  759.     if (target_count <= 0) {
  760.         ReplyToCommand(client, "[SM] Nenhum alvo foi encontrado.");
  761.         return Plugin_Handled;
  762.     }
  763.    
  764.     decl String:sample[PLATFORM_MAX_PATH];
  765.     GetCmdArg(2, sample, sizeof(sample));
  766.    
  767.     decl channel;
  768.     if (args >= 3) {
  769.         decl String:strChannel[16];
  770.         GetCmdArg(3, strChannel, sizeof(strChannel));
  771.         channel = StringToInt(strChannel);
  772.         if (channel <= 0)
  773.             channel = SNDCHAN_AUTO;
  774.     } else
  775.         channel = SNDCHAN_STATIC;
  776.        
  777.     decl level;
  778.     if (args >= 4) {
  779.         decl String:strLevel[16];
  780.         GetCmdArg(4, strLevel, sizeof(strLevel));
  781.         level = StringToInt(strLevel);
  782.         if (level <= 0)
  783.             channel = SNDLEVEL_NONE;
  784.     } else
  785.         level = SNDLEVEL_NORMAL;
  786.    
  787.     new applieds = 0;
  788.     new first = 0;
  789.     new target;
  790.     for (new i = 0; i < target_count; i++) {
  791.         target = target_list[i];
  792.         if (Client_IsIngame(target) && !IsFakeClient(target)) {
  793.             EmitSoundToClientAny(target, sample, SOUND_FROM_PLAYER, channel, level);
  794.             if (applieds == 0)
  795.                 first = target;
  796.             applieds++;
  797.         }
  798.     }
  799.  
  800.     return Plugin_Stop;
  801. }
  802.  
  803. public Action:AmbientSHook(String:sample[PLATFORM_MAX_PATH], &entity, &Float:volume, &level, &pitch, Float:pos[3], &flags, &Float:delay) {
  804.     if (g_iRoundState == ROUND_STATE_STOPED)
  805.         return Plugin_Stop;
  806.    
  807.     return Plugin_Continue;
  808. }
  809.  
  810. bool:GetMusicByName(const String:musicName[], music[music_data]) {
  811.     for (new index = 0; index < t_win_snd_count; index++)
  812.         if (StrEqual(t_win_snd[index][music_name], musicName)) {
  813.             music = t_win_snd[index];
  814.             return true;
  815.         }
  816.  
  817.     for (new index = 0; index < ct_win_snd_count; index++)
  818.         if (StrEqual(ct_win_snd[index][music_name], musicName)) {
  819.             music = ct_win_snd[index];
  820.             return true;
  821.         }
  822.  
  823.     return false;
  824. }
  825.  
  826. bool:GetMusicByFileName(const String:fileName[], music[music_data]) {
  827.     for (new index = 0; index < t_win_snd_count; index++)
  828.         if (StrEqual(t_win_snd[index][file_name], fileName)) {
  829.             music = t_win_snd[index];
  830.             return true;
  831.         }
  832.        
  833.     for (new index = 0; index < ct_win_snd_count; index++)
  834.         if (StrEqual(ct_win_snd[index][file_name], fileName)) {
  835.             music = ct_win_snd[index];
  836.             return true;
  837.         }
  838.        
  839.     return false;
  840. }
  841.  
  842. bool:IsMusicLikedByClient(music[music_data], client) {
  843.     decl String:steamID[MAX_AUTHID_LENGTH];
  844.     steamID[0] = '\0';
  845.     GetClientAuthString(client, steamID, sizeof(steamID));
  846.    
  847.     new size = GetArraySize(music[likes]);
  848.     for (new index = 0; index < size; index++) {
  849.         decl clientData[client_data];
  850.         GetArrayArray(music[likes], index, clientData, sizeof(clientData));
  851.         if (StrEqual(clientData[steamid], steamID))
  852.             return true;
  853.     }
  854.    
  855.     return false;
  856. }
  857.  
  858. bool:IsMusicDislikedByClient(music[music_data], client) {
  859.     decl String:steamID[MAX_AUTHID_LENGTH];
  860.     steamID[0] = '\0';
  861.     GetClientAuthString(client, steamID, sizeof(steamID));
  862.    
  863.     new size = GetArraySize(music[dislikes]);
  864.     for (new index = 0; index < size; index++) {
  865.         decl clientData[client_data];
  866.         GetArrayArray(music[dislikes], index, clientData, sizeof(clientData));
  867.         if (StrEqual(clientData[steamid], steamID))
  868.             return true;
  869.     }
  870.    
  871.     return false;
  872. }
  873.  
  874. AddCTSound(const music[music_data]) {
  875.     decl String:soundFile1[PLATFORM_MAX_PATH];
  876.     Format(soundFile1, sizeof(soundFile1), "roundsound/%s", music[file_name]);
  877.     decl String:soundFile2[PLATFORM_MAX_PATH];
  878.     Format(soundFile2, sizeof(soundFile2), "sound/%s", soundFile1);
  879.     if (FileExists(soundFile2)) {
  880.         ct_win_snd[ct_win_snd_count++] = music;
  881.         AddFileToDownloadsTable(soundFile2);
  882.         PrecacheSoundAny(soundFile1, true);
  883.         LogMessage("Counter-Terrorist sound added: %s", music[file_name]);
  884.     } else
  885.         LogError("Counter-Terrorist sound '%s' not found.", music[file_name]);
  886. }
  887.  
  888. AddTSound(const music[music_data]) {
  889.     decl String:soundFile1[PLATFORM_MAX_PATH];
  890.     Format(soundFile1, sizeof(soundFile1), "roundsound/%s", music[file_name]);
  891.     decl String:soundFile2[PLATFORM_MAX_PATH];
  892.     Format(soundFile2, sizeof(soundFile2), "sound/%s", soundFile1);
  893.     if (FileExists(soundFile2)) {
  894.         t_win_snd[t_win_snd_count++] = music;
  895.         AddFileToDownloadsTable(soundFile2);
  896.         PrecacheSoundAny(soundFile1, true);
  897.         LogMessage("Terrorist sound added: %s", music[file_name]);
  898.     } else
  899.         LogError("Terrorist sound '%s' not found.", music[file_name]);
  900. }
  901.  
  902. PlaySoundToClient2(const String:sample[], client) {
  903.     EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_LIBRARY);
  904.     EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_HOME);
  905.     EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_NORMAL);
  906. }
  907.  
  908. StopSoundOnClient2(const String:sample[], client) {
  909.     /*EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_LIBRARY, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
  910.     EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_HOME, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
  911.     EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_NORMAL, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);*/
  912.     StopSoundAny(client, SNDCHAN_STATIC, sample);
  913.     StopSoundAny(client, SNDCHAN_STATIC, sample);
  914.     StopSoundAny(client, SNDCHAN_STATIC, sample);
  915. }
  916.  
  917. PlaySoundToClient(music[music_data], client, bool:ignoreDislike = false) {
  918.     if (!Client_IsIngame(client) || IsFakeClient(client))
  919.         return;
  920.  
  921.     decl bool:dislike;
  922.     if (ignoreDislike)
  923.         dislike = false;
  924.     else
  925.         dislike = !g_bSoundEnabled[client] || IsMusicDislikedByClient(music, client);
  926.     if (dislike)
  927.         return;
  928.    
  929.     decl String:sample[PLATFORM_MAX_PATH];
  930.     Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
  931.    
  932.     if (g_bPlayingMusic[client])
  933.         StopSoundOnClient(g_MusicPlaying[client], client);
  934.     g_bPlayingMusic[client] = true;
  935.     g_MusicPlaying[client] = music;
  936.    
  937.     PrintCenterText(client, "%T: %s - %s", "playing now", client, music[artist], music[title]);
  938.     PrintToChat(client, " \x04[RS]\x01 %T: \x03%s\x01 - \x0d%s\x01", "playing now", client, music[artist], music[title]);
  939.    
  940.     PlaySoundToClient2(sample, client);
  941. }
  942.  
  943. StopSoundOnClient(music[music_data], client) {
  944.     if (Client_IsIngame(client) && !IsFakeClient(client)) {
  945.         decl String:sample[PLATFORM_MAX_PATH];
  946.         Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
  947.        
  948.         if (g_bPlayingMusic[client] && StrEqual(g_MusicPlaying[client][music_name], music[music_name]))
  949.             g_bPlayingMusic[client] = false;
  950.        
  951.         StopSoundOnClient2(sample, client);
  952.     }
  953. }
  954.  
  955. PlaySoundToAll(music[music_data], bool:ignoreDislike = false) {
  956.     decl String:sample[PLATFORM_MAX_PATH];
  957.     Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
  958.    
  959.     for (new client = 1; client < MaxClients; client++) {
  960.         if (!Client_IsIngame(client) || IsFakeClient(client))
  961.             continue;
  962.  
  963.         decl bool:dislike;
  964.         if (ignoreDislike)
  965.             dislike = false;
  966.         else
  967.             dislike = !g_bSoundEnabled[client] || IsMusicDislikedByClient(music, client);
  968.         if (dislike)
  969.             continue;
  970.    
  971.         if (g_bPlayingMusic[client])
  972.             StopSoundOnClient(g_MusicPlaying[client], client);
  973.         g_bPlayingMusic[client] = true;
  974.         g_MusicPlaying[client] = music;
  975.        
  976.         PrintCenterText(client, "%T: %s - %s", "playing now", client, music[artist], music[title]);
  977.         PrintToChat(client, " \x04[RS]\x01 %T: \x03%s\x01 - \x0d%s\x01", "playing now", client, music[artist], music[title]);
  978.        
  979.         PlaySoundToClient2(sample, client);
  980.     }
  981. }
  982.  
  983. StopSoundOnAll(music[music_data]) {
  984.     decl String:sample[PLATFORM_MAX_PATH];
  985.     Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
  986.    
  987.     for (new client = 1; client < MaxClients; client++)
  988.         if (Client_IsIngame(client) && !IsFakeClient(client)) {
  989.             if (g_bPlayingMusic[client] && StrEqual(g_MusicPlaying[client][music_name], music[music_name]))
  990.                 g_bPlayingMusic[client] = false;
  991.            
  992.             StopSoundOnClient2(sample, client);
  993.         }
  994. }
Advertisement
Add Comment
Please, Sign In to add comment