// Copyright © 2016 Vaqtincha
#define UNRELIABLE_MESSAGE
// #define DEBUG
#include <amxmodx>
#include <reapi>
// #define HEADSHOT_ONLY // раскомментируйте эту строку, если затемнение экрана должно быть только при убийстве в голову
enum Colors{ red, green, blue, alpha }
new g_iColors[Colors], g_pFadeTime, g_pHoldTime, g_pColors
new g_iMsgIdScreenFade, Float:g_flFadeTime, Float:g_flHoldTime
new bool:g_bScreenFade[MAX_CLIENTS+1], g_iPlayerColors[MAX_CLIENTS+1][Colors]
public plugin_init()
{
register_plugin("[ReApi] Killer ScreenFade", "0.0.4", "Vaqtincha")
register_clcmd("say /fade", "ClCmd_Switch")
register_clcmd("say_team /fade", "ClCmd_Switch")
register_event("HLTV", "Event_NewRound", "a", "1=0", "2=0")
RegisterHookChain(RG_CBasePlayer_Killed, "CBasePlayer_Killed", .post = true)
g_iMsgIdScreenFade = get_user_msgid("ScreenFade")
g_pColors = register_cvar("ks_default_colors", "0 200 20 40")
g_pFadeTime = register_cvar("ks_fadeouttime", "0.5") // плавное исчезновение
g_pHoldTime = register_cvar("ks_holdtime", "0.8") // продолжительность
Event_NewRound()
}
public Event_NewRound()
{
new szColors[16], szRed[4], szGreen[4], szBlue[4], szAlpha[4]
get_pcvar_string(g_pColors, szColors, charsmax(szColors))
if(parse(szColors, szRed, charsmax(szRed), szGreen, charsmax(szGreen), szBlue, charsmax(szBlue), szAlpha, charsmax(szAlpha)) == 4)
{
g_iColors[red] = clamp(str_to_num(szRed), 0, 255)
g_iColors[green] = clamp(str_to_num(szGreen), 0, 255)
g_iColors[blue] = clamp(str_to_num(szBlue), 0, 255)
g_iColors[alpha] = clamp(str_to_num(szAlpha), 0, 255)
g_flFadeTime = get_pcvar_float(g_pFadeTime)
g_flHoldTime = get_pcvar_float(g_pHoldTime)
}
}
public client_putinserver(id)
{
if(is_user_bot(id) || is_user_hltv(id))
return
g_bScreenFade[id] = true
new szUserColors[16], szRed[4], szGreen[4], szBlue[4], szAlpha[4]
get_user_info(id, "ks_colors", szUserColors, charsmax(szUserColors))
if(!szUserColors[0]) // default
{
g_iPlayerColors[id][red] = g_iColors[red]
g_iPlayerColors[id][green] = g_iColors[green]
g_iPlayerColors[id][blue] = g_iColors[blue]
g_iPlayerColors[id][alpha] = g_iColors[alpha]
}else{
if(parse(szUserColors, szRed, charsmax(szRed), szGreen, charsmax(szGreen), szBlue, charsmax(szBlue), szAlpha, charsmax(szAlpha)) == 4)
{
g_iPlayerColors[id][red] = clamp(str_to_num(szRed), 0, 255)
g_iPlayerColors[id][green] = clamp(str_to_num(szGreen), 0, 255)
g_iPlayerColors[id][blue] = clamp(str_to_num(szBlue), 0, 255)
g_iPlayerColors[id][alpha] = clamp(str_to_num(szAlpha), 0, 255)
#if defined DEBUG
server_print("^n[FADE] UserColors: Red = %d | Green = %d | Blue = %d | Alpha = %d", g_iPlayerColors[id][red], g_iPlayerColors[id][green], g_iPlayerColors[id][blue], g_iPlayerColors[id][alpha])
#endif
}
}
}
public ClCmd_Switch(id)
{
if(g_bScreenFade[id])
{
g_bScreenFade[id] = false
client_print(id, print_center, "ScreenFade disabled!")
}
else{
g_bScreenFade[id] = true
client_print(id, print_center, "ScreenFade enabled!")
}
return PLUGIN_HANDLED
}
public CBasePlayer_Killed(id, killer)
{
#if defined HEADSHOT_ONLY
if(get_member(id, m_bHeadshotKilled) && id != killer && is_user_alive(killer) && g_bScreenFade[killer] && !is_player_blinded(killer))
#else
if(id != killer && is_user_alive(killer) && g_bScreenFade[killer] && !is_player_blinded(killer))
#endif
__UTIL_ScreenFade(killer, g_iPlayerColors[killer], g_flFadeTime, g_flHoldTime)
return HC_CONTINUE
}
stock __UTIL_ScreenFade(id, iColor[Colors] = {0, 0, 0, 0}, Float:flFxTime = 1.0, Float:flHoldTime = 1.0)
{
const FFADE_IN = 0x0000
#if defined UNRELIABLE_MESSAGE
message_begin(MSG_ONE_UNRELIABLE, g_iMsgIdScreenFade, .player = id)
#else
message_begin(MSG_ONE, g_iMsgIdScreenFade, .player = id)
#endif
write_short(FixedUnsigned16(flFxTime, 1<<12))
write_short(FixedUnsigned16(flHoldTime, 1<<12))
write_short(FFADE_IN)
write_byte(iColor[red])
write_byte(iColor[green])
write_byte(iColor[blue])
write_byte(iColor[alpha])
message_end()
}
stock FixedUnsigned16(Float:flValue, iScale)
{
new iOutput
iOutput = floatround(flValue * iScale)
if(iOutput < 0)
iOutput = 0
if(iOutput > 0xFFFF)
iOutput = 0xFFFF
return iOutput
}
stock bool:is_player_blinded(id)
{
return bool:(Float:get_member(id, m_blindStartTime) + Float:get_member(id, m_blindFadeTime) >= get_gametime())
// /* m 2.*/ return bool:(Float:get_member(id, m_blindStartTime) + Float:get_member(id, m_blindFadeTime) + Float:get_member(id, m_blindHoldTime) >= get_gametime())
}