Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* *
- * RoundSound BY TUMMIETUM (TUMTUM) and modified by SilentBr from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan
- * -------------------------
- * Changelog Original Roundsound++ by ANTiCHRiST
- * -------------------------
- * by TanaToS aka ANTiCHRiST, SilentBr from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan
- */
- #include <sourcemod>
- #include <sdktools>
- #include <clientprefs>
- #include <cstrike>
- #include <smlib>
- #include <emitsoundany>
- #pragma semicolon 1
- #define PLUGIN_VERSION "1.4.0"
- #define MAX_SOUND_PER_TEAM 256
- #define MAX_EDICTS 2048
- #define ROUND_STATE_UNDEFINED 0
- #define ROUND_STATE_STARTED 1
- #define ROUND_STATE_STOPED 2
- #define MAX_AUTHID_LENGTH 64
- #define MAX_CLIENTNAME_LENGTH 64
- enum client_data {
- String:steamid[MAX_AUTHID_LENGTH],
- String:last_name[MAX_CLIENTNAME_LENGTH]
- }
- enum music_data {
- String:music_name[PLATFORM_MAX_PATH],
- String:file_name[PLATFORM_MAX_PATH],
- String:artist[PLATFORM_MAX_PATH],
- String:title[PLATFORM_MAX_PATH],
- music_team,
- Handle:likes,
- Handle:dislikes
- }
- // cvars
- new Handle:roundsound_enable = INVALID_HANDLE;
- new bool:g_bEnabled = true;
- // cookies
- new Handle:c_RoundSoundEnable = INVALID_HANDLE;
- new Handle:roundsound_round_restart_delay = INVALID_HANDLE;
- new Float:g_iRoundRestartDelay = -1;
- // globals
- new g_iRoundState = ROUND_STATE_UNDEFINED;
- new g_iSoundEnts[MAX_EDICTS] = {INVALID_ENT_REFERENCE, ...};
- new g_iNumSounds = 0;
- new t_win_snd_count = 0;
- new t_win_snd_pos = 0;
- new t_win_snd[MAX_SOUND_PER_TEAM][music_data];
- new ct_win_snd_count = 0;
- new ct_win_snd_pos = 0;
- new ct_win_snd[MAX_SOUND_PER_TEAM][music_data];
- new g_bMusicIsPlaying = false;
- new g_CurrentMusic[music_data];
- new bool:g_bSoundEnabled[MAXPLAYERS + 1] = {true, ...};
- new bool:g_bPlayingMusic[MAXPLAYERS + 1] = {false, ...};
- new g_MusicPlaying[MAXPLAYERS + 1][music_data];
- new Handle:g_hDatabase = INVALID_HANDLE;
- new bool:g_bIsMYSQL = false;
- new bool:g_bMapLoaded = false;
- new bool:g_bLikesLoaded = false;
- public Plugin:myinfo = {
- name = "Round Sound CS:GO",
- author = "ANTiCHRiST Edited by TumTum, SilentBr from ΖмBя.™ Clan and SHARIVAN from ΖмBя.™ Clan",
- description = "Plays a Sound at RoundEnd.",
- version = PLUGIN_VERSION,
- url = "http://www.zmbrasil.com.br/"
- };
- public OnPluginStart() {
- CreateConVar("roundsound_version", PLUGIN_VERSION, "Versão.", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_CHEAT|FCVAR_DONTRECORD);
- roundsound_enable = CreateConVar("roundsound_enable", "1", "Habilita ou desabilita este plugin.", FCVAR_PLUGIN|FCVAR_NOTIFY);
- 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);
- RegConsoleCmd("sm_roundsound", Command_RoundSound, "Abre o menu de opções para as músicas de fim de round.");
- RegConsoleCmd("sm_music", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_musics", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_musica", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_musicas", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_song", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_songs", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_sound", Command_RoundSound, "O mesmo que sm_roundsound.");
- RegConsoleCmd("sm_sounds", Command_RoundSound, "O mesmo que sm_roundsound.");
- AddCommandListener(Command_PlayMusic, "sm_play");
- c_RoundSoundEnable = RegClientCookie("RoundSoundEnable", "Round Sound Enable", CookieAccess_Private);
- AutoExecConfig(true, "roundsound_zmbr");
- LoadTranslations("common.phrases");
- LoadTranslations("roundsound.phrases");
- HookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
- HookEvent("round_end", OnRoundEnd);
- HookConVarChange(roundsound_enable, OnConVarChanged);
- HookConVarChange(roundsound_round_restart_delay, OnConVarChanged);
- AddAmbientSoundHook(AmbientSHook);
- }
- public OnPluginEnd() {
- UnhookEvent("round_start", OnRoundStart, EventHookMode_PostNoCopy);
- UnhookEvent("round_end", OnRoundEnd);
- UnhookConVarChange(roundsound_enable, OnConVarChanged);
- UnhookConVarChange(roundsound_round_restart_delay, OnConVarChanged);
- RemoveAmbientSoundHook(AmbientSHook);
- }
- bool:ReadMusicData(Handle:hFile, music[music_data], team) {
- decl String:buff[256];
- KvGetSectionName(hFile, buff, sizeof(buff));
- if (strlen(buff) == 0)
- return false;
- strcopy(music[music_name], PLATFORM_MAX_PATH, buff);
- decl client[client_data];
- music[likes] = CreateArray(sizeof(client));
- music[dislikes] = CreateArray(sizeof(client));
- music[music_team] = team;
- KvGetString(hFile, "file", buff, sizeof(buff));
- strcopy(music[file_name], PLATFORM_MAX_PATH, buff);
- KvGetString(hFile, "artist", buff, sizeof(buff));
- strcopy(music[artist], PLATFORM_MAX_PATH, buff);
- KvGetString(hFile, "title", buff, sizeof(buff));
- strcopy(music[title], PLATFORM_MAX_PATH, buff);
- LoadLike(music);
- return true;
- }
- public OnMapStart() {
- g_bMapLoaded = true;
- SetRandomSeed(GetTime());
- g_iRoundState = ROUND_STATE_UNDEFINED;
- t_win_snd_count = 0;
- t_win_snd_pos = 0;
- ct_win_snd_count = 0;
- ct_win_snd_pos = 0;
- new Handle:hFile = CreateKeyValues("roundsound");
- KvSetEscapeSequences(hFile, true);
- decl String:sPath[PLATFORM_MAX_PATH];
- BuildPath(Path_SM, sPath, sizeof(sPath), "configs/roundsound.cfg");
- if (!FileExists(sPath)) {
- LogMessage("Config file '%s' not found.", sPath);
- return;
- }
- if (!FileToKeyValues(hFile, sPath)) {
- LogError("Error on loading key values config file '%s'.", sPath);
- return;
- }
- decl String:soundName[PLATFORM_MAX_PATH];
- if (KvJumpToKey(hFile, "terrorists", false)) {
- KvGotoFirstSubKey(hFile, false);
- do {
- decl music[music_data];
- if (ReadMusicData(hFile, music, CS_TEAM_T))
- AddTSound(music);
- } while (KvGotoNextKey(hFile, false));
- }
- for (new i = 0; i < t_win_snd_count; i++) {
- new random = GetRandomInt(0, t_win_snd_count - 1);
- decl temp[music_data];
- temp = t_win_snd[i];
- t_win_snd[i] = t_win_snd[random];
- t_win_snd[random] = temp;
- }
- KvRewind(hFile);
- if (KvJumpToKey(hFile, "counter-terrorists", false)) {
- KvGotoFirstSubKey(hFile, false);
- do {
- //KvGetString(hFile, NULL_STRING, soundName, sizeof(soundName));
- decl music[music_data];
- if (ReadMusicData(hFile, music, CS_TEAM_CT))
- AddCTSound(music);
- } while (KvGotoNextKey(hFile, false));
- }
- for (new i = 0; i < ct_win_snd_count; i++) {
- new random = GetRandomInt(0, ct_win_snd_count - 1);
- decl temp[music_data];
- temp = ct_win_snd[i];
- ct_win_snd[i] = ct_win_snd[random];
- ct_win_snd[random] = temp;
- }
- CloseHandle(hFile);
- }
- public OnMapEnd() {
- g_bMapLoaded = false;
- g_bLikesLoaded = false;
- }
- public OnConfigsExecuted() {
- g_bEnabled = GetConVarBool(roundsound_enable);
- g_iRoundRestartDelay = GetConVarInt(roundsound_round_restart_delay);
- if(g_hDatabase == INVALID_HANDLE)
- SQL_TConnect(SQL_ConnectCall, "storage-local");
- }
- public SQL_ConnectCall(Handle:owner, Handle:hndl, const String:error[], any:data) {
- if(hndl == INVALID_HANDLE || strlen(error) > 0) {
- LogError("RoundSound was unable to establish a database connection!");
- decl String:_sError[512];
- if(hndl != INVALID_HANDLE && SQL_GetError(hndl, _sError, 512))
- LogError("- SQL_ConnectCall: %s", _sError);
- else
- LogError("- SQL_ConnectCall: %s", error);
- } else {
- g_hDatabase = hndl;
- sqldbtable();
- }
- }
- sqldbtable() {
- decl String:sdbtype[64];
- decl String:squery[256];
- SQL_ReadDriver(g_hDatabase, sdbtype, sizeof(sdbtype));
- if(StrEqual(sdbtype, "sqlite", false)) {
- g_bIsMYSQL = false;
- 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));";
- }
- else {
- g_bIsMYSQL = true;
- 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;";
- }
- SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
- LoadLikes();
- }
- LoadLikes() {
- if (!g_bMapLoaded || g_bLikesLoaded || g_hDatabase == INVALID_HANDLE)
- return;
- for (new index = 0; index < t_win_snd_count; index++)
- LoadLike(t_win_snd[index]);
- for (new index = 0; index < ct_win_snd_count; index++)
- LoadLike(ct_win_snd[index]);
- g_bLikesLoaded = true;
- }
- LoadLike(music[music_data]) {
- if (!g_bMapLoaded || g_bLikesLoaded || g_hDatabase == INVALID_HANDLE)
- return;
- decl String:squery[256];
- decl String:sqlMusic[64];
- SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
- Format(squery, sizeof(squery), "SELECT * FROM likes WHERE music = '%s'", sqlMusic);
- SQL_TQuery(g_hDatabase, sqlT_GetLikes, squery);
- }
- public sqlT_GetLikes(Handle:owner, Handle:hndl, const String:error[], any:data) {
- if (hndl == INVALID_HANDLE)
- LogError("%s", error);
- else
- while (SQL_FetchRow(hndl)) {
- decl String:musicName[PLATFORM_MAX_PATH];
- SQL_FetchString(hndl, 0, musicName, sizeof(musicName));
- decl music[music_data];
- if (!GetMusicByName(musicName, music))
- continue;
- decl clientData[client_data];
- SQL_FetchString(hndl, 1, clientData[steamid], MAX_AUTHID_LENGTH);
- SQL_FetchString(hndl, 2, clientData[last_name], MAX_CLIENTNAME_LENGTH);
- new like = SQL_FetchInt(hndl, 3);
- switch (like) {
- case 1: // like
- PushArrayArray(music[likes], clientData, sizeof(clientData));
- case 2: // dislike
- PushArrayArray(music[dislikes], clientData, sizeof(clientData));
- }
- }
- }
- public sqlT_Generic(Handle:owner, Handle:hndl, const String:error[], any:data) {
- if (hndl == INVALID_HANDLE)
- LogError("%s", error);
- }
- public OnClientPutInServer(client) {
- g_bPlayingMusic[client] = false;
- }
- public OnRoundStart(Handle:event, const String:name[], bool:dontBroadcast) {
- if (g_bMusicIsPlaying) {
- g_bMusicIsPlaying = false;
- StopSoundOnAll(g_CurrentMusic);
- }
- g_iNumSounds = 0;
- decl String:sSound[PLATFORM_MAX_PATH];
- new entity = INVALID_ENT_REFERENCE;
- while ((entity = FindEntityByClassname(entity, "ambient_generic")) != INVALID_ENT_REFERENCE) {
- GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
- new len = strlen(sSound);
- if (len > 4 && (StrEqual(sSound[len - 3], "mp3") || StrEqual(sSound[len - 3], "wav"))) {
- g_iSoundEnts[g_iNumSounds++] = EntIndexToEntRef(entity);
- }
- }
- g_iRoundState = ROUND_STATE_STARTED;
- }
- public OnRoundEnd(Handle:event, const String:name[], bool:dontBroadcast) {
- if (!g_bEnabled)
- return;
- g_iRoundState = ROUND_STATE_STOPED;
- if (g_bMusicIsPlaying) {
- StopSoundOnAll(g_CurrentMusic);
- g_bMusicIsPlaying = false;
- }
- new winner = GetEventInt(event, "winner");
- switch (winner) {
- case CS_TEAM_T: {
- if (t_win_snd_count > 0) {
- g_CurrentMusic = t_win_snd[t_win_snd_pos];
- g_bMusicIsPlaying = true;
- t_win_snd_pos = (t_win_snd_pos + 1) % t_win_snd_count;
- }
- }
- case CS_TEAM_CT: {
- if (ct_win_snd_count > 0) {
- g_CurrentMusic = ct_win_snd[ct_win_snd_pos];
- g_bMusicIsPlaying = true;
- ct_win_snd_pos = (ct_win_snd_pos + 1) % ct_win_snd_count;
- }
- }
- }
- if (!g_bMusicIsPlaying)
- return;
- for (new client = 1; client <= MaxClients; client++)
- if (IsClientInGame(client) && !IsFakeClient(client) && g_bSoundEnabled[client] && !IsMusicDislikedByClient(g_CurrentMusic, client))
- ClientCommand(client, "playgamesound Music.StopAllMusic");
- // Run StopSound on all ambient sounds in the map.
- decl String:sSound[PLATFORM_MAX_PATH];
- for (new i = 0; i < g_iNumSounds; i++) {
- new entity = EntRefToEntIndex(g_iSoundEnts[i]);
- if (entity != INVALID_ENT_REFERENCE) {
- GetEntPropString(entity, Prop_Data, "m_iszSound", sSound, sizeof(sSound));
- for (new client = 1; client < MaxClients; client++)
- if (Client_IsIngame(client) && !IsFakeClient(client) && g_bSoundEnabled[client] && !IsMusicDislikedByClient(g_CurrentMusic, client))
- EmitSoundToClient(client, sSound, entity, SNDCHAN_STATIC, SNDLEVEL_NONE, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
- }
- }
- CreateTimer(0.0, PlayMusicTimer, _, TIMER_FLAG_NO_MAPCHANGE);
- }
- public Action:PlayMusicTimer(Handle:timer) {
- if (g_bMusicIsPlaying)
- PlaySoundToAll(g_CurrentMusic);
- return Plugin_Stop;
- }
- public Action:CS_OnTerminateRound(&Float:delay, &CSRoundEndReason:reason) {
- if (!g_bEnabled || g_iRoundState == ROUND_STATE_UNDEFINED || g_iRoundRestartDelay == -1)
- return Plugin_Continue;
- delay = float(g_iRoundRestartDelay);
- return Plugin_Changed;
- }
- public OnConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[]) {
- if (convar == roundsound_enable)
- g_bEnabled = GetConVarBool(roundsound_enable);
- else if (convar == roundsound_round_restart_delay)
- g_iRoundRestartDelay = GetConVarInt(roundsound_round_restart_delay);
- }
- public OnClientCookiesCached(client) {
- new String:strValue[16];
- GetClientCookie(client, c_RoundSoundEnable, strValue, sizeof(strValue));
- g_bSoundEnabled[client] = StrEqual(strValue, "") || StrEqual(strValue, "1") || StrEqual(strValue, "true");
- //LogMessage("Cookie for %N: '%s'", client, strValue);
- }
- public Action:Command_RoundSound(client, args) {
- MenuRoundSonund(client);
- return Plugin_Handled;
- }
- MenuRoundSonund(client) {
- new Handle:menu = CreateMenu(MenuHandlerRoundSound);
- decl String:buffer[256];
- Format(buffer, sizeof(buffer), "%T", "roundsound menu", client);
- SetMenuTitle(menu, buffer);
- if (g_bSoundEnabled[client])
- Format(buffer, sizeof(buffer), "%T", "roundsound disable", client);
- else
- Format(buffer, sizeof(buffer), "%T", "roundsound enable", client);
- AddMenuItem(menu, "roundsound enabled", buffer);
- Format(buffer, sizeof(buffer), "%T", "terrorist musics", client);
- AddMenuItem(menu, "terrorist musics", buffer);
- Format(buffer, sizeof(buffer), "%T", "counter-terrorist musics", client);
- AddMenuItem(menu, "counter-terrorist musics", buffer);
- SetMenuExitButton(menu, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- SubMenuTMusics(client) {
- new Handle:menu = CreateMenu(SubMenuMusicsHandler);
- decl String:buffer[256];
- Format(buffer, sizeof(buffer), "%T", "terrorist musics", client);
- SetMenuTitle(menu, buffer);
- for (new index = 0; index < t_win_snd_count; index++)
- AddMenuItem(menu, t_win_snd[index][music_name], t_win_snd[index][music_name]);
- SetMenuExitBackButton(menu, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- SubMenuCTMusics(client) {
- new Handle:menu = CreateMenu(SubMenuMusicsHandler);
- decl String:buffer[256];
- Format(buffer, sizeof(buffer), "%T", "counter-terrorist musics", client);
- SetMenuTitle(menu, buffer);
- for (new index = 0; index < ct_win_snd_count; index++)
- AddMenuItem(menu, ct_win_snd[index][music_name], ct_win_snd[index][music_name]);
- SetMenuExitBackButton(menu, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- SubMenuShowMusicInfo(client, music[music_data]) {
- new Handle:menu = CreateMenu(SubMenuMusicInfoHandler);
- decl String:buffer[256];
- Format(buffer, sizeof(buffer), music[music_name]);
- SetMenuTitle(menu, buffer);
- new bool:playing = g_bPlayingMusic[client] && StrEqual(g_MusicPlaying[client][music_name], music[music_name]);
- new bool:liked = IsMusicLikedByClient(music, client);
- new bool:disliked = IsMusicDislikedByClient(music, client);
- Format(buffer, sizeof(buffer), "%T", "play", client);
- AddMenuItem(menu, "play", buffer, playing ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
- Format(buffer, sizeof(buffer), "%T", "stop", client);
- AddMenuItem(menu, "stop", buffer, !playing ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
- Format(buffer, sizeof(buffer), "%T", "like", client);
- AddMenuItem(menu, "like", buffer, liked ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
- Format(buffer, sizeof(buffer), "%T", "dislike", client);
- AddMenuItem(menu, "dislike", buffer, disliked ? ITEMDRAW_DISABLED : ITEMDRAW_DEFAULT);
- Format(buffer, sizeof(buffer), "%T", "neutral", client);
- AddMenuItem(menu, "neutral", buffer, (liked && !disliked || !liked && disliked) ? ITEMDRAW_DEFAULT : ITEMDRAW_DISABLED);
- SetMenuExitBackButton(menu, true);
- DisplayMenu(menu, client, MENU_TIME_FOREVER);
- }
- public MenuHandlerRoundSound(Handle:menu, MenuAction:action, client, choice) {
- switch (action) {
- case MenuAction_Select: {
- switch (choice) {
- case 0: { // enable/disable
- if (g_bSoundEnabled[client]) {
- g_bSoundEnabled[client] = false;
- SetClientCookie(client, c_RoundSoundEnable, "false");
- PrintToChat(client, " \x04[RS]\x01 %T.", "you disabled the roundsound", client);
- if (g_bMusicIsPlaying)
- StopSoundOnClient(g_CurrentMusic, client);
- }
- else {
- g_bSoundEnabled[client] = true;
- SetClientCookie(client, c_RoundSoundEnable, "true");
- PrintToChat(client, " \x04[RS]\x01 %T.", "you enabled the roundsound", client);
- }
- MenuRoundSonund(client);
- }
- case 1: { // terrorist musics
- SubMenuTMusics(client);
- }
- case 2: { // couter-terrorist musics
- SubMenuCTMusics(client);
- }
- }
- }
- case MenuAction_End:
- CloseHandle(menu);
- }
- }
- public SubMenuMusicsHandler(Handle:menu, MenuAction:action, client, choice) {
- switch (action) {
- case MenuAction_Select: {
- decl String:musicName[PLATFORM_MAX_PATH];
- GetMenuItem(menu, choice, musicName, sizeof(musicName));
- decl music[music_data];
- if (GetMusicByName(musicName, music))
- SubMenuShowMusicInfo(client, music);
- else
- MenuRoundSonund(client);
- }
- case MenuAction_Cancel: {
- if (choice == MenuCancel_ExitBack)
- MenuRoundSonund(client);
- }
- case MenuAction_End:
- CloseHandle(menu);
- }
- }
- public SubMenuMusicInfoHandler(Handle:menu, MenuAction:action, client, choice) {
- switch (action) {
- case MenuAction_Select: {
- decl String:musicName[PLATFORM_MAX_PATH];
- GetMenuTitle(menu, musicName, sizeof(musicName));
- decl music[music_data];
- if (GetMusicByName(musicName, music)) {
- switch (choice) {
- case 0: PlaySoundToClient(music, client, true);
- case 1: StopSoundOnClient(music, client);
- case 2: LikeMusic(client, music);
- case 3: DislikeMusic(client, music);
- case 4: NeutralMusic(client, music);
- }
- SubMenuShowMusicInfo(client, music);
- } else
- MenuRoundSonund(client);
- }
- case MenuAction_Cancel: {
- if (choice == MenuCancel_ExitBack) {
- decl String:musicName[PLATFORM_MAX_PATH];
- GetMenuTitle(menu, musicName, sizeof(musicName));
- decl music[music_data];
- if (GetMusicByName(musicName, music))
- switch (music[music_team]) {
- case CS_TEAM_T:
- SubMenuTMusics(client);
- case CS_TEAM_CT:
- SubMenuCTMusics(client);
- }
- else
- MenuRoundSonund(client);
- }
- }
- case MenuAction_End:
- CloseHandle(menu);
- }
- }
- LikeMusic(client, music[music_data]) {
- if (IsMusicLikedByClient(music, client))
- return;
- decl String:steamID[MAX_AUTHID_LENGTH];
- steamID[0] = '\0';
- GetClientAuthString(client, steamID, sizeof(steamID));
- new size = GetArraySize(music[dislikes]);
- for (new index = 0; index < size; index++) {
- decl clientData[client_data];
- GetArrayArray(music[dislikes], index, clientData, sizeof(clientData));
- if (StrEqual(steamID, clientData[steamid])) {
- RemoveFromArray(music[dislikes], index);
- break;
- }
- }
- decl clientData[client_data];
- strcopy(clientData[steamid], MAX_AUTHID_LENGTH, steamID);
- decl String:lastName[MAX_CLIENTNAME_LENGTH];
- GetClientName(client, lastName, sizeof(lastName));
- strcopy(clientData[last_name], MAX_AUTHID_LENGTH, steamID);
- PushArrayArray(music[likes], clientData, sizeof(clientData));
- if (g_hDatabase != INVALID_HANDLE) {
- decl String:squery[256];
- decl String:sqlMusic[64];
- SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
- decl String:sqlSteamID[64];
- SQL_EscapeString(g_hDatabase, steamID, sqlSteamID, sizeof(sqlSteamID));
- decl String:sqlLastName[64];
- SQL_EscapeString(g_hDatabase, lastName, sqlLastName, sizeof(sqlLastName));
- Format(squery, sizeof(squery), "REPLACE INTO likes VALUES ('%s','%s','%s',%d)", sqlMusic, sqlSteamID, sqlLastName, 1);
- SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
- }
- }
- DislikeMusic(client, music[music_data]) {
- if (IsMusicDislikedByClient(music, client))
- return;
- decl String:steamID[MAX_AUTHID_LENGTH];
- steamID[0] = '\0';
- GetClientAuthString(client, steamID, sizeof(steamID));
- new size = GetArraySize(music[likes]);
- for (new index = 0; index < size; index++) {
- decl clientData[client_data];
- GetArrayArray(music[likes], index, clientData, sizeof(clientData));
- if (StrEqual(steamID, clientData[steamid])) {
- RemoveFromArray(music[likes], index);
- break;
- }
- }
- decl clientData[client_data];
- strcopy(clientData[steamid], MAX_AUTHID_LENGTH, steamID);
- decl String:lastName[MAX_CLIENTNAME_LENGTH];
- GetClientName(client, lastName, sizeof(lastName));
- strcopy(clientData[last_name], MAX_AUTHID_LENGTH, steamID);
- PushArrayArray(music[dislikes], clientData, sizeof(clientData));
- if (g_hDatabase != INVALID_HANDLE) {
- decl String:squery[256];
- decl String:sqlMusic[64];
- SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
- decl String:sqlSteamID[64];
- SQL_EscapeString(g_hDatabase, steamID, sqlSteamID, sizeof(sqlSteamID));
- decl String:sqlLastName[64];
- SQL_EscapeString(g_hDatabase, lastName, sqlLastName, sizeof(sqlLastName));
- Format(squery, sizeof(squery), "REPLACE INTO likes VALUES ('%s','%s','%s',%d)", sqlMusic, sqlSteamID, sqlLastName, 2);
- SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
- }
- }
- NeutralMusic(client, music[music_data]) {
- decl String:steamID[MAX_AUTHID_LENGTH];
- steamID[0] = '\0';
- GetClientAuthString(client, steamID, sizeof(steamID));
- decl String:lastName[MAX_CLIENTNAME_LENGTH];
- GetClientName(client, lastName, sizeof(lastName));
- new size = GetArraySize(music[likes]);
- for (new index = 0; index < size; index++) {
- decl clientData[client_data];
- GetArrayArray(music[likes], index, clientData, sizeof(clientData));
- if (StrEqual(steamID, clientData[steamid])) {
- RemoveFromArray(music[likes], index);
- break;
- }
- }
- size = GetArraySize(music[dislikes]);
- for (new index = 0; index < size; index++) {
- decl clientData[client_data];
- GetArrayArray(music[dislikes], index, clientData, sizeof(clientData));
- if (StrEqual(steamID, clientData[steamid])) {
- RemoveFromArray(music[dislikes], index);
- break;
- }
- }
- if (g_hDatabase != INVALID_HANDLE) {
- decl String:squery[256];
- decl String:sqlMusic[64];
- SQL_EscapeString(g_hDatabase, music[music_name], sqlMusic, sizeof(sqlMusic));
- decl String:sqlSteamID[64];
- SQL_EscapeString(g_hDatabase, steamID, sqlSteamID, sizeof(sqlSteamID));
- decl String:sqlLastName[64];
- SQL_EscapeString(g_hDatabase, lastName, sqlLastName, sizeof(sqlLastName));
- Format(squery, sizeof(squery), "REPLACE INTO likes VALUES ('%s','%s','%s',%d)", sqlMusic, sqlSteamID, sqlLastName, 0);
- SQL_TQuery(g_hDatabase, sqlT_Generic, squery);
- }
- }
- public Action:Command_PlayMusic(client, const String:command[], args) {
- if (args < 2) {
- ReplyToCommand(client, "[SM] Uso: sm_play <#userid|name> <sample> [channel] [level]");
- return Plugin_Handled;
- }
- decl String:target_name[MAX_TARGET_LENGTH];
- decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
- decl String:strTarget[192];
- GetCmdArg(1, strTarget, sizeof(strTarget));
- target_count = ProcessTargetString(
- strTarget,
- client,
- target_list,
- MAXPLAYERS,
- COMMAND_FILTER_CONNECTED,
- target_name,
- sizeof(target_name),
- tn_is_ml);
- if (target_count <= 0) {
- ReplyToCommand(client, "[SM] Nenhum alvo foi encontrado.");
- return Plugin_Handled;
- }
- decl String:sample[PLATFORM_MAX_PATH];
- GetCmdArg(2, sample, sizeof(sample));
- decl channel;
- if (args >= 3) {
- decl String:strChannel[16];
- GetCmdArg(3, strChannel, sizeof(strChannel));
- channel = StringToInt(strChannel);
- if (channel <= 0)
- channel = SNDCHAN_AUTO;
- } else
- channel = SNDCHAN_STATIC;
- decl level;
- if (args >= 4) {
- decl String:strLevel[16];
- GetCmdArg(4, strLevel, sizeof(strLevel));
- level = StringToInt(strLevel);
- if (level <= 0)
- channel = SNDLEVEL_NONE;
- } else
- level = SNDLEVEL_NORMAL;
- new applieds = 0;
- new first = 0;
- new target;
- for (new i = 0; i < target_count; i++) {
- target = target_list[i];
- if (Client_IsIngame(target) && !IsFakeClient(target)) {
- EmitSoundToClientAny(target, sample, SOUND_FROM_PLAYER, channel, level);
- if (applieds == 0)
- first = target;
- applieds++;
- }
- }
- return Plugin_Stop;
- }
- public Action:AmbientSHook(String:sample[PLATFORM_MAX_PATH], &entity, &Float:volume, &level, &pitch, Float:pos[3], &flags, &Float:delay) {
- if (g_iRoundState == ROUND_STATE_STOPED)
- return Plugin_Stop;
- return Plugin_Continue;
- }
- bool:GetMusicByName(const String:musicName[], music[music_data]) {
- for (new index = 0; index < t_win_snd_count; index++)
- if (StrEqual(t_win_snd[index][music_name], musicName)) {
- music = t_win_snd[index];
- return true;
- }
- for (new index = 0; index < ct_win_snd_count; index++)
- if (StrEqual(ct_win_snd[index][music_name], musicName)) {
- music = ct_win_snd[index];
- return true;
- }
- return false;
- }
- bool:GetMusicByFileName(const String:fileName[], music[music_data]) {
- for (new index = 0; index < t_win_snd_count; index++)
- if (StrEqual(t_win_snd[index][file_name], fileName)) {
- music = t_win_snd[index];
- return true;
- }
- for (new index = 0; index < ct_win_snd_count; index++)
- if (StrEqual(ct_win_snd[index][file_name], fileName)) {
- music = ct_win_snd[index];
- return true;
- }
- return false;
- }
- bool:IsMusicLikedByClient(music[music_data], client) {
- decl String:steamID[MAX_AUTHID_LENGTH];
- steamID[0] = '\0';
- GetClientAuthString(client, steamID, sizeof(steamID));
- new size = GetArraySize(music[likes]);
- for (new index = 0; index < size; index++) {
- decl clientData[client_data];
- GetArrayArray(music[likes], index, clientData, sizeof(clientData));
- if (StrEqual(clientData[steamid], steamID))
- return true;
- }
- return false;
- }
- bool:IsMusicDislikedByClient(music[music_data], client) {
- decl String:steamID[MAX_AUTHID_LENGTH];
- steamID[0] = '\0';
- GetClientAuthString(client, steamID, sizeof(steamID));
- new size = GetArraySize(music[dislikes]);
- for (new index = 0; index < size; index++) {
- decl clientData[client_data];
- GetArrayArray(music[dislikes], index, clientData, sizeof(clientData));
- if (StrEqual(clientData[steamid], steamID))
- return true;
- }
- return false;
- }
- AddCTSound(const music[music_data]) {
- decl String:soundFile1[PLATFORM_MAX_PATH];
- Format(soundFile1, sizeof(soundFile1), "roundsound/%s", music[file_name]);
- decl String:soundFile2[PLATFORM_MAX_PATH];
- Format(soundFile2, sizeof(soundFile2), "sound/%s", soundFile1);
- if (FileExists(soundFile2)) {
- ct_win_snd[ct_win_snd_count++] = music;
- AddFileToDownloadsTable(soundFile2);
- PrecacheSoundAny(soundFile1, true);
- LogMessage("Counter-Terrorist sound added: %s", music[file_name]);
- } else
- LogError("Counter-Terrorist sound '%s' not found.", music[file_name]);
- }
- AddTSound(const music[music_data]) {
- decl String:soundFile1[PLATFORM_MAX_PATH];
- Format(soundFile1, sizeof(soundFile1), "roundsound/%s", music[file_name]);
- decl String:soundFile2[PLATFORM_MAX_PATH];
- Format(soundFile2, sizeof(soundFile2), "sound/%s", soundFile1);
- if (FileExists(soundFile2)) {
- t_win_snd[t_win_snd_count++] = music;
- AddFileToDownloadsTable(soundFile2);
- PrecacheSoundAny(soundFile1, true);
- LogMessage("Terrorist sound added: %s", music[file_name]);
- } else
- LogError("Terrorist sound '%s' not found.", music[file_name]);
- }
- PlaySoundToClient2(const String:sample[], client) {
- EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_LIBRARY);
- EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_HOME);
- EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_NORMAL);
- }
- StopSoundOnClient2(const String:sample[], client) {
- /*EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_LIBRARY, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
- EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_HOME, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);
- EmitSoundToClientAny(client, sample, SOUND_FROM_PLAYER, SNDCHAN_STATIC, SNDLEVEL_NORMAL, SND_STOP, 0.0, SNDPITCH_NORMAL, _, _, _, true);*/
- StopSoundAny(client, SNDCHAN_STATIC, sample);
- StopSoundAny(client, SNDCHAN_STATIC, sample);
- StopSoundAny(client, SNDCHAN_STATIC, sample);
- }
- PlaySoundToClient(music[music_data], client, bool:ignoreDislike = false) {
- if (!Client_IsIngame(client) || IsFakeClient(client))
- return;
- decl bool:dislike;
- if (ignoreDislike)
- dislike = false;
- else
- dislike = !g_bSoundEnabled[client] || IsMusicDislikedByClient(music, client);
- if (dislike)
- return;
- decl String:sample[PLATFORM_MAX_PATH];
- Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
- if (g_bPlayingMusic[client])
- StopSoundOnClient(g_MusicPlaying[client], client);
- g_bPlayingMusic[client] = true;
- g_MusicPlaying[client] = music;
- PrintCenterText(client, "%T: %s - %s", "playing now", client, music[artist], music[title]);
- PrintToChat(client, " \x04[RS]\x01 %T: \x03%s\x01 - \x0d%s\x01", "playing now", client, music[artist], music[title]);
- PlaySoundToClient2(sample, client);
- }
- StopSoundOnClient(music[music_data], client) {
- if (Client_IsIngame(client) && !IsFakeClient(client)) {
- decl String:sample[PLATFORM_MAX_PATH];
- Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
- if (g_bPlayingMusic[client] && StrEqual(g_MusicPlaying[client][music_name], music[music_name]))
- g_bPlayingMusic[client] = false;
- StopSoundOnClient2(sample, client);
- }
- }
- PlaySoundToAll(music[music_data], bool:ignoreDislike = false) {
- decl String:sample[PLATFORM_MAX_PATH];
- Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
- for (new client = 1; client < MaxClients; client++) {
- if (!Client_IsIngame(client) || IsFakeClient(client))
- continue;
- decl bool:dislike;
- if (ignoreDislike)
- dislike = false;
- else
- dislike = !g_bSoundEnabled[client] || IsMusicDislikedByClient(music, client);
- if (dislike)
- continue;
- if (g_bPlayingMusic[client])
- StopSoundOnClient(g_MusicPlaying[client], client);
- g_bPlayingMusic[client] = true;
- g_MusicPlaying[client] = music;
- PrintCenterText(client, "%T: %s - %s", "playing now", client, music[artist], music[title]);
- PrintToChat(client, " \x04[RS]\x01 %T: \x03%s\x01 - \x0d%s\x01", "playing now", client, music[artist], music[title]);
- PlaySoundToClient2(sample, client);
- }
- }
- StopSoundOnAll(music[music_data]) {
- decl String:sample[PLATFORM_MAX_PATH];
- Format(sample, sizeof(sample), "roundsound/%s", music[file_name]);
- for (new client = 1; client < MaxClients; client++)
- if (Client_IsIngame(client) && !IsFakeClient(client)) {
- if (g_bPlayingMusic[client] && StrEqual(g_MusicPlaying[client][music_name], music[music_name]))
- g_bPlayingMusic[client] = false;
- StopSoundOnClient2(sample, client);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment