Андрей Трегубенко
Участник
- Сообщения
- 13
- Реакции
- 0
По какой-то причине не играет музыка.
- Файлы качаются
- Название трека пишется в чат
- Музыка не играет
- Ошибок в консоли у клиента нет
- Ошибок в логах сервера нет
Я озадачен. Помогите.
- Файлы качаются
- Название трека пишется в чат
- Музыка не играет
- Ошибок в консоли у клиента нет
- Ошибок в логах сервера нет
Я озадачен. Помогите.
PHP:
#include <sourcemod>
#include <sdktools>
#include <sdktools_sound>
#define PLUGIN_VERSION "1.6"
#define MAX_FILE_LEN 150
#define MAX_DISPLAY_LENGTH 150
#define MAX_SOUNDS 100
#define MAX_PLAYERS 256
new Handle:EnName, EnN;
new SoundValue[MAXPLAYERS];
new Handle:g_hEnabled;
new Handle:g_hFile;
new g_numSounds;
new randomSound;
new String:g_displayNames[MAX_SOUNDS][MAX_FILE_LEN];
new String:g_soundNames[MAX_SOUNDS][MAX_DISPLAY_LENGTH];
public Plugin:myinfo =
{
name = "RES",
author = "Z3R0M1ND",
description = "Playing music on end round.",
version = PLUGIN_VERSION,
url = ""
}
public OnPluginStart()
{
RegConsoleCmd("res", ToggleRES);
RegAdminCmd("sm_soundtest", TestRES, ADMFLAG_ROOT);
EnName = CreateConVar("dp_esname_enable", "1", "Enable sound name");
EnN = GetConVarBool(EnName);
AutoExecConfig(true, "RoundEndSound");
CreateConVar("sm_res_version", PLUGIN_VERSION, "Round End Sound", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
g_hEnabled = CreateConVar("sm_res_enabled", "1", "Enable/disable displaying advertisements.");
g_hFile = CreateConVar("sm_res_file", "res_musiclist.txt", "File to read the advertisements from.");
HookEvent("round_end", RoundEnd);
ParseMusic();
}
public Action:ToggleRES(client, args)
{
if (client > 0)
{
switch(SoundValue[client])
{
case 1:
{
SoundValue[client] = 0;
PrintToChat(client, "Музыка включена");
}
case 0:
{
SoundValue[client] = 1;
PrintToChat(client, "Музыка отключена");
}
}
}
}
public Action:TestRES(client, args)
{
if (client > 0)
{
PlayMusic();
}
}
public OnClientConnected(client)
{
SoundValue[client] = 0;
}
public OnMapStart()
{
if (GetConVarBool(g_hEnabled))
for(new i = 0; i < g_numSounds; i++)
SoundDownload(g_soundNames[i]);
}
stock SoundDownload(const String:soundLocation[])
{
decl String:fullSoundPath[PLATFORM_MAX_PATH];
Format(fullSoundPath, sizeof(fullSoundPath), "sound/%s", soundLocation);
if (FileExists(fullSoundPath))
{
AddFileToDownloadsTable(fullSoundPath);
PrecacheSound(soundLocation);
}
}
ParseMusic()
{
if (GetConVarBool(g_hEnabled))
{
decl String:sFile[256], String:sPath[MAX_FILE_LEN];
GetConVarString(g_hFile, sFile, sizeof(sFile));
BuildPath(Path_SM, sPath, sizeof(sPath), "configs/%s", sFile);
new Handle:hFile = OpenFile(sPath, "r");
if (hFile == INVALID_HANDLE)
{
SetFailState("addons/sourcemod/configs/res_musiclist.txt not found");
return;
}
g_numSounds = 0;
while (!IsEndOfFile(hFile))
{
decl String:line[255];
if (!ReadFileLine(hFile, line, sizeof(line)))
{
break;
}
/* Trim comments */
new len = strlen( line );
new bool:ignoring = false;
for ( new i = 0; i < len; i++ )
{
if ( ignoring )
{
if ( line[ i ] == '"' )
{
ignoring = false;
}
} else {
if ( line[ i ] == '"' )
{
ignoring = true;
} else if ( line[ i ] == ';' ) {
line[ i ] = '\0';
break;
} else if ( line[ i ] == '/' && i != len - 1 && line[ i + 1 ] == '/')
{
line[ i ] = '\0';
break;
}
}
}
TrimString( line );
if ( ( line[ 0 ] == '/' && line[ 1 ] == '/' ) || (line[ 0 ] == ';' || line[ 0 ] == '\0' ) )
{
continue;
}
g_displayNames[ g_numSounds ][ 0 ] = 0;
g_soundNames[ g_numSounds ][ 0 ] = 0;
new String:file_name[MAX_DISPLAY_LENGTH];
new String:file_sound[MAX_FILE_LEN];
new cur_idx, idx;
cur_idx = BreakString(line, file_name, sizeof(file_name));
strcopy(g_displayNames[g_numSounds], sizeof(g_displayNames[]), file_name);
idx = cur_idx;
cur_idx = BreakString(line[idx], file_sound, sizeof(file_sound));
strcopy(g_soundNames[g_numSounds], sizeof(g_soundNames[]), file_sound);
g_numSounds++;
}
CloseHandle( hFile );
}
}
public RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
PlayMusic();
}
PlayMusic()
{
for (new client = 1; client <= MaxClients; client++)
{
if (SoundValue[client] == 0 && IsClientInGame(client))
{
randomSound = GetRandomInt(0, g_numSounds - 1);
EmitSoundToAll(g_soundNames[randomSound]);
if(EnN) PrintToChat(client, "[ МУЗЫКА ] \x04 %s", g_displayNames[randomSound]);
}
}
}