#include <sourcemod>
#include <sdktools>
new Handle:g_hPath = INVALID_HANDLE;
new Handle:Array = INVALID_HANDLE;
new ArraySize;
public OnPluginStart()
{
g_hPath = CreateConVar("join_sound_path", "addons/sourcemod/configs/join_sound_list.cfg", "Укажите путь к файлу");
Array = CreateArray(255, 0);
}
public OnMapStart()
{
decl String:path[255];
GetConVarString(g_hPath, path, sizeof(path));
new Handle:file = OpenFile(path, "r");
if (file == INVALID_HANDLE)
{
LogError("Не удалось открыть файл '%s'", path);
}
else
{
new CountLine = 0;
decl String:line[150], String:buffer[255];
while (!IsEndOfFile(file) && CountLine <= 50 && ReadFileLine(file, line, sizeof(line)))
{
CountLine++;
TrimString(line);
PushArrayString(Array, line);
PrecacheSound(line);
Format(buffer, sizeof(buffer), "sound/%s", line);
AddFileToDownloadsTable(buffer);
}
ArraySize = GetArraySize(Array);
CloseHandle(file);
}
}
public OnClientPutInServer(client)
{
if (client > 0 && !IsFakeClient(client))
{
decl String:ArrayName[50];
GetArrayString(Array, GetRandomInt(0, ArraySize-1), ArrayName, sizeof(ArrayName));
ClientCommand(client, "playgamesound %s", ArrayName);
}
}