#include <sourcemod>
#include <sdktools>
#include <emitsoundany>
new Handle:g_EnableName, Handle:g_SoundType, Handle:g_SoundOrder, bool:g_cEnGame, g_cSoundType, g_cSoundOrder;
new p_SoundValue[MAXPLAYERS];
new Handle:g_SoundPath,
Handle:g_SoundNames;
int r_Int;
public Plugin:myinfo =
{
name = "dP_EndSound",
author = "Primo",
description = "Playing sounds on end round.",
version = "2.1",
}
public OnPluginStart()
{
RegConsoleCmd("dpsound", EnableSoundDP);
RegConsoleCmd("res", EnableSoundDP);
g_EnableName = CreateConVar("dp_esname_enable", "1", "1 -Включить, 0 - отключить название треков в чате");
g_SoundType = CreateConVar("dp_esound_type", "1", "1 - один трек для всех, 0 - для каждого свой");
g_SoundOrder = CreateConVar("dp_esound_order", "0", "1 - случайный, 0 - по порядку");
g_cEnGame = GetConVarBool(g_EnableName);
g_cSoundType = GetConVarInt(g_SoundType);
g_cSoundOrder = GetConVarInt(g_SoundOrder);
HookEvent("round_end", RoundEnd);
g_SoundPath = CreateArray(ByteCountToCells(128));
g_SoundNames = CreateArray(ByteCountToCells(128));
}
public Action:EnableSoundDP(client, args)
{
if(client > 0)
{
p_SoundValue[client] = !p_SoundValue[client];
PrintToChat(client, "[\x07DP\x01] Вы %s воспроизведение музыки в конце раунда.", p_SoundValue[client] ? "включили":"отключили")
}
}
public OnMapStart()
{
ClearArray(g_SoundPath);
ClearArray(g_SoundNames);
new Handle:h_Keys = CreateKeyValues("DPI");
if (FileToKeyValues(h_Keys, "addons/sourcemod/configs/dp_res.ini"))
{
if(KvGotoFirstSubKey(h_Keys))
{
decl String:ev_Sound[128];
do
{
KvGetString(h_Keys, "sound", ev_Sound, sizeof(ev_Sound));
Format(ev_Sound, sizeof(ev_Sound), "sound/%s", ev_Sound);
if(FileExists(ev_Sound))
{
AddFileToDownloadsTable(ev_Sound);
strcopy(ev_Sound, sizeof(ev_Sound), ev_Sound[6]);
PrecacheSoundAny(ev_Sound);
PushArrayString(g_SoundPath, ev_Sound);
KvGetSectionName(h_Keys, ev_Sound, sizeof(ev_Sound));
PushArrayString(g_SoundNames, ev_Sound);
}
else LogMessage("No such sound: %s", ev_Sound);
}
while (KvGotoNextKey(h_Keys));
}
else
{
CloseHandle(h_Keys);
SetFailState("Broken: addons/sourcemod/configs/res.ini");
return;
}
}
else
{
CloseHandle(h_Keys);
SetFailState("Broken: addons/sourcemod/configs/dp_res.ini");
return;
}
CloseHandle(h_Keys);
}
public RoundEnd(Handle:event, const String:name[], bool:dontBroadcast)
{
g_cEnGame = GetConVarBool(g_EnableName);
g_cSoundType = GetConVarInt(g_SoundType);
g_cSoundOrder = GetConVarInt(g_SoundOrder);
EmitSoundV();
}
public OnClientConnected(client)
{
p_SoundValue[client] = true;
}
EmitSoundV()
{
decl String:ev_SoundPath[128], String:ev_SoundName[128];
if(g_cSoundType == 1)
{
if(g_cSoundOrder != 0) r_Int = GetRandomInt(0, GetArraySize(g_SoundPath)-1);
else func_GetMaxInt();
GetArrayString(g_SoundPath, r_Int, ev_SoundPath, sizeof(ev_SoundPath));
}
for(new client=1; client<=MaxClients; client++)
{
if(p_SoundValue[client] && IsClientInGame(client) && !IsFakeClient(client))
{
if(g_cSoundType == 0)
{
if(g_cSoundOrder != 0) r_Int = GetRandomInt(0, GetArraySize(g_SoundPath)-1);
else func_GetMaxInt();
GetArrayString(g_SoundPath, r_Int, ev_SoundPath, sizeof(ev_SoundPath));
}
EmitSoundToClientAny(client, ev_SoundPath, SOUND_FROM_PLAYER, SNDCHAN_STATIC);
if(g_cEnGame == true)
{
GetArrayString(g_SoundNames, r_Int, ev_SoundName, sizeof(ev_SoundName));
PrintToChat(client, "Играет \x04 %s", ev_SoundName);
}
}
}
}
func_GetMaxInt()
{
r_Int++;
if(GetArraySize(g_SoundPath)-r_Int == 0)
{
r_Int = 0;
}
}