#include <amxmodx>
#include <fakemeta>
#include <hamsandwich>
#define SAVE
#if defined(SAVE)
#include <nvault>
#define FILE_NAME "kills"
#define SAVE_TYPE 2
#define AUTORESET
#define AUTORESET_DAYS 30
new g_nVault;
#endif
#define MAX_CLIENTS 32
#define m_LastHitGroup 75
#define m_bitsDamageType 76
#define m_pActiveItem 373
#define m_iId 43
new g_iKillCount[ MAX_CLIENTS +1 ];
new bool: g_bszFirstBlood;
new bool:g_bszSoundsEnable[MAX_CLIENTS +1];
new const SOUNDS_KILL[ ][ ] =
{
"soundkills/firstkill.wav",
"soundkills/doublekill.wav",
"soundkills/tripplekill.wav",
"soundkills/multikill.wav",
"soundkills/crazy.wav",
"soundkills/rampage.wav",
"soundkills/headshot.wav",
"soundkills/knife.wav",
"soundkills/grenade.wav"
};
public plugin_init( )
{
register_plugin( "", "", "" );
register_logevent( "LogEV_RoundStart", 2, "1=Round_Start" );
register_clcmd( "say /sounds", "Command_Sounds" );
register_clcmd( "say_team /sounds", "Command_Sounds" );
RegisterHam( Ham_Killed, "player", "CPlayer__Killed_Post", .Post = 1 );
#if defined(SAVE)
g_nVault = nvault_open(FILE_NAME);
#if defined(AUTORESET)
nvault_prune(g_nVault, 0, get_systime() - (86400 * AUTORESET_DAYS));
#endif
#endif
}
#if defined(SAVE)
public plugin_end()
nvault_close(g_nVault);
save_data(id)
{
new trackid[64];
if (!get_trackid(id, trackid, charsmax(trackid)))
return 0;
new value[2];
formatex(value, charsmax(value), "%d", g_bszSoundsEnable[id] ? 1 : 2);
nvault_set(g_nVault, trackid, value);
return 1;
}
#if AMXX_VERSION_NUM >= 183 && SAVE_TYPE == 2
load_data(id, const trackid[])
#else
load_data(id)
#endif
{
#if AMXX_VERSION_NUM >= 183 && SAVE_TYPE == 2
if (!authid_is_valid(trackid))
return 0;
#else
new trackid[72];
if (!get_trackid(id, trackid, charsmax(trackid)))
return 0;
#endif
new nResult = nvault_get(g_nVault, trackid);
if (!nResult)
return 0;
#if defined(AUTORESET)
nvault_touch(g_nVault, trackid, -1);
#endif
g_bszSoundsEnable[id] = nResult == 1 ? true : false;
return 1;
}
get_trackid(id, trackid[], len)
{
#if SAVE_TYPE == 1
get_user_name(id, trackid, len);
#elseif SAVE_TYPE == 2
get_user_authid(id, trackid, len);
if (!authid_is_valid(trackid))
return 0;
#elseif SAVE_TYPE == 3
get_user_ip(id, trackid, len, 1);
#endif
return 1;
}
#if AMXX_VERSION_NUM >= 183 && SAVE_TYPE == 2
authid_is_valid(const authid[])
{
if (!strcmp(authid, "STEAM_ID_LAN") || !strcmp(authid, "VALVE_ID_LAN"))
return 0;
return 1;
}
#endif
#endif
public plugin_precache( )
{
for( new i = 0; i < sizeof SOUNDS_KILL; i++ )
engfunc( EngFunc_PrecacheSound, SOUNDS_KILL[ i ] );
}
public LogEV_RoundStart( )
{
g_bszFirstBlood = true;
for( new iPlayers = MAX_CLIENTS; iPlayers > 0; iPlayers-- )
g_iKillCount[ iPlayers ] = 0;
}
public Command_Sounds( iPlayer )
{
if( g_bszSoundsEnable[iPlayer] )
{
g_bszSoundsEnable[iPlayer] = false;
client_print( iPlayer, print_chat, "Звуки убийств отключены." );
}
else
{
g_bszSoundsEnable[iPlayer] = true;
client_print( iPlayer, print_chat, "Звуки убийств включены." );
}
#if defined(SAVE)
save_data(iPlayer);
#endif
return PLUGIN_HANDLED;
}
public CPlayer__Killed_Post( iVictim, iAttacker, iGib )
{
if( iVictim == iAttacker || !is_user_connected( iAttacker ) )
return;
if( !g_bszSoundsEnable[iAttacker] )
return;
new iBitsDamageType = get_pdata_int( iVictim, m_bitsDamageType );
new iLastHitGroup = get_pdata_int( iVictim, m_LastHitGroup );
new iActiveItem = get_pdata_cbase( iAttacker, m_pActiveItem );
if( pev_valid( iActiveItem ) != 2 )
return;
new iId = get_pdata_int( iActiveItem, m_iId, 4 );
g_iKillCount[ iAttacker ]++;
if( iLastHitGroup == HIT_HEAD )
{
if( g_bszFirstBlood )
{
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 0 ] );
g_bszFirstBlood = false;
}
else
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 6 ] );
return;
}
if( iId == CSW_KNIFE && iBitsDamageType & ( DMG_NEVERGIB | DMG_BULLET ) )
{
if( g_bszFirstBlood )
{
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 0 ] );
g_bszFirstBlood = false;
}
else
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 7 ] );
return;
}
if( ~iBitsDamageType & ( DMG_NEVERGIB | DMG_BULLET ) )
{
if( g_bszFirstBlood )
{
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 0 ] );
g_bszFirstBlood = false;
}
else
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 8 ] );
return;
}
if( g_bszFirstBlood )
{
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 0 ] );
g_bszFirstBlood = false;
}
else
{
switch( g_iKillCount[ iAttacker ] )
{
case 2: client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 1 ] );
case 3: client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 2 ] );
case 4: client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 3 ] );
case 5: client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 4 ] );
case 6:
{
client_cmd( iAttacker, "spk %s", SOUNDS_KILL[ 5 ] );
g_iKillCount[ iAttacker ] = 5;
}
}
}
}
#if defined(SAVE)
#if AMXX_VERSION_NUM >= 183 && SAVE_TYPE == 2
public client_authorized(iPlayer, const authid[])
#else
public client_authorized(iPlayer)
#endif
{
#if AMXX_VERSION_NUM >= 183 && SAVE_TYPE == 2
if (!load_data(iPlayer, authid))
#else
if (!load_data(iPlayer))
#endif
g_bszSoundsEnable[iPlayer] = true;
g_iKillCount[ iPlayer ] = 0;
}
#else
public client_authorized(iPlayer)
{
g_bszSoundsEnable[iPlayer] = true;
g_iKillCount[ iPlayer ] = 0;
}
#endif