/*
Minimalism for smart © Zhelnov Vladimir
Coded by Zhelnov Vladimir aka Neatek
! Please dont delete my copyright
*/
#include <sourcemod>
#include <sdktools>
new KnifeNum, HeadsNum;
new Handle:KeyValues;
new String:KeyValuesPath[PLATFORM_MAX_PATH];
new String:SoundFiles[2][102][PLATFORM_MAX_PATH];
public Plugin:myinfo = {
name = "Quake:Knihead(Neatek)",
author = "Neatek",
version = "1.0"
};
public OnPluginStart()
{
LoadTranslations("plugin.knihead");
HookEvent("player_death", Event_Death, EventHookMode_Pre);
}
public OnMapStart()
{
if(KeyValues != INVALID_HANDLE)
KeyValues = INVALID_HANDLE;
BuildPath(Path_SM, KeyValuesPath, sizeof(KeyValuesPath), "configs/QuakeKnihead/soundlist.cfg");
KeyValues = CreateKeyValues("SoundList");
FileToKeyValues(KeyValues, KeyValuesPath);
LoadSounds();
//PrecacheSounds();
}
public Action:Event_Death(Handle:event, const String:name[], bool:dontBroadcast)
{
new client, attacker, bool:headshot, String:nickname[32];
client = GetClientOfUserId(GetEventInt(event,"userid"));
attacker = GetClientOfUserId(GetEventInt(event,"attacker"));
headshot = GetEventBool(event, "headshot");
if(client != attacker && client != 0)
{
if(!IsFakeClient(client))
{
GetClientName(client, nickname, sizeof(nickname));
}
else
{
nickname = "#bot";
}
if(headshot == false)
{
new String:weapon[64];
GetEventString(event, "weapon", weapon, sizeof(weapon));
if(StrEqual(weapon, "knife", true))
{
PrintCenterTextAll("%t", "knife", nickname);
PlayRandomSound("knife");
}
}
else
{
PrintCenterTextAll("%t", "headshot", nickname);
PlayRandomSound("headshot");
}
}
}
LoadSounds()
{
if(KeyValues != INVALID_HANDLE)
{
FillArray("knifesounds");
FillArray("headsounds");
}
}
stock PlayRandomSound(String:Category[82])
{
new randsound, String:Sound[PLATFORM_MAX_PATH];
if(StrEqual(Category, "knife", true))
{
randsound = GetRandomInt(0, KnifeNum);
Sound = SoundFiles[0][randsound];
}
else if(StrEqual(Category, "headshot", true))
{
randsound = GetRandomInt(0, HeadsNum);
Sound = SoundFiles[1][randsound];
}
//PrintToChatAll("sound: %s", Sound);
if(IsSoundPrecached(Sound))
{
EmitSoundToAll(Sound);
}
}
stock DownloadFile(String:File[PLATFORM_MAX_PATH])
{
new String:dlFile[PLATFORM_MAX_PATH]
Format(dlFile, PLATFORM_MAX_PATH, "sound/%s", File);
if(FileExists(dlFile))
{
AddFileToDownloadsTable(dlFile);
PrintToServer("[Quake:Knihead] File added to downloads - %s.", dlFile);
return true;
}
else
{
PrintToServer("[Quake:Knihead] File don't added to downloads - %s.", dlFile);
}
return false;
}
stock FillArray(String:FirstKey[82])
{
if(KvJumpToKey(KeyValues, FirstKey, false))
{
new Amount,String:num[32], String:Buffer[PLATFORM_MAX_PATH];
Amount = KvGetNum(KeyValues, "amount");
if(Amount > 0)
{
for (new i = 0; i < Amount; i++)
{
IntToString(i, num, sizeof(num));
if(KvJumpToKey(KeyValues, num, false))
{
KvGetString(KeyValues, "sound", Buffer, PLATFORM_MAX_PATH);
if(DownloadFile(Buffer))
{
PrecacheSound(Buffer, true);
if(StrEqual(FirstKey, "knifesounds", false))
{
SoundFiles[0][i] = Buffer;
KnifeNum += 1;
}
else
{
SoundFiles[1][i] = Buffer;
HeadsNum += 1;
}
}
KvGoBack(KeyValues);
}
else
{
PrintToServer("[Quake:Knihead] Can't jump to key: %s [%s]", num, FirstKey);
}
}
KvGoBack(KeyValues);
}
}
else
{
PrintToServer("[Quake:Knihead] Can't jump to key: %s", FirstKey);
}
if(StrEqual(FirstKey, "knifesounds", false))
KnifeNum -= 1;
else
HeadsNum -= 1;
}