#include <amxmodx>
#include <fun>
#include <engine>
#include <fakemeta_util>
#define PLUGIN "AFK Protection"
#define VERSION "2.2"
#define AUTHOR "rapara13/Nordic Warrior"
#define TAG "AFK Менеджер" // Задаем тег
#define TIME_FOR_AFK 15 // Время "простоя" игрока до входа в режим АФК. (в секундах)
new isAfk[MAX_PLAYERS+1], Float:gPlayerPosition[MAX_PLAYERS+1][3], gMoveTimer[MAX_PLAYERS+1], Float:ViewAngle[MAX_PLAYERS+1][3]
new effects, message, icon, block, sprite
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
effects = create_cvar("afk_effects", "3") // Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе
message = create_cvar("afk_type_message", "2") // Тип сообщений клиенту о переходе в режим АФК: 0 - выкл. 1 - hud, 2 - DHUD, 3 - чат
icon = create_cvar("afk_icon", "1") // Иконка (спрайт) над игроком. 0 - выкл. 1 - вкл.
block = create_cvar("afk_block", "1") // Блокировать ли атаку афк-шнику: 0 - выкл. 1 - вкл.
if(block) register_forward(FM_CmdStart, "fw_CmdStart")
set_task(0.5, "afkcheck", 0, .flags="b")
}
public plugin_natives() register_native("is_afk", "native_is_afk")
public client_connect(id) isAfk[id] = false
public plugin_precache()
{
if(icon) sprite = precache_model("sprites/afk/afk.spr")
}
public afkcheck()
{
static Float:current_v_angle[3], Float:origin[3], Float:distance
for(new i = 1; i <= MAX_PLAYERS; i++)
{
if (!is_user_alive(i)) continue
if (pev(i, pev_flags) & FL_INWATER) continue
entity_get_vector(i, EV_VEC_origin, origin)
entity_get_vector(i, EV_VEC_v_angle, current_v_angle)
distance = vector_distance(gPlayerPosition[i], origin)
if ((distance <= 1) & (ViewAngle[i][0] == current_v_angle[0] || ViewAngle[i][1] == current_v_angle[1]))
{
gMoveTimer[i]++
if(gMoveTimer[i] > TIME_FOR_AFK * 2)
{
gMoveTimer[i] = 0
afk(i)
}
}
else
{
gMoveTimer[i] = 0
ViewAngle[i][0] = current_v_angle[0]
ViewAngle[i][1] = current_v_angle[1]
back(i)
}
gPlayerPosition[i][0] = origin[0]
gPlayerPosition[i][1] = origin[1]
gPlayerPosition[i][2] = origin[2]
}
}
public afk(id)
{
new cvar_effects = get_pcvar_num(effects)
if(isAfk[id])
return
if(is_user_alive(id))
{
set_user_godmode(id, 1)
if(cvar_effects == 1 || cvar_effects == 3)
{
set_user_rendering(id, kRenderFxNone,255,255,255,kRenderTransAlpha,120)
}
if(cvar_effects == 2 || cvar_effects == 3)
{
message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
write_short(~0)
write_short(~0)
write_short(0x0004)
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(130)
message_end()
}
if(icon) add_icon(id)
set_pev(id, pev_solid, SOLID_NOT)
switch(get_pcvar_num(message))
{
case 1:
{
set_hudmessage(0, 206, 209, -1.0, 0.1, 0, 1.0, 3.0, 0.1, 0.2, -1)
show_hudmessage(id, "[%s]^nТы перешел в режим АФК.", TAG)
}
case 2:
{
set_dhudmessage(0, 206, 209, -1.0, 0.1, 0, 1.0, 3.0, 0.1, 0.2)
show_dhudmessage(id, "[%s]^nТы перешел в режим АФК.", TAG)
}
case 3:
{
client_print_color(id, print_team_default, "^4[%s] ^1Ты перешел в ^3режим ^4AFK", TAG)
}
}
}
isAfk[id] = true
}
public back(id)
{
new cvar_effects = get_pcvar_num(effects)
if(!isAfk[id])
return
set_user_godmode(id, 0)
if(cvar_effects == 1 || cvar_effects == 3)
{
set_user_rendering(id,0,0,0,kRenderTransAlpha,0)
}
if(cvar_effects == 2 || cvar_effects == 3)
{
message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
write_short(1<<10)
write_short(1<<10)
write_short(0x0000)
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(100)
message_end()
}
if(icon) remove_icon(id)
set_pev(id, pev_solid, SOLID_SLIDEBOX)
switch(get_pcvar_num(message))
{
case 1:
{
set_hudmessage(148, 0, 211, -1.0, 0.2, 0, 1.0, 3.0, 0.1, 0.2, -1)
show_hudmessage(id, "[%s]^nТы вышел из режима АФК.", TAG)
}
case 2:
{
set_dhudmessage(148, 0, 211, -1.0, 0.2, 0, 1.0, 3.0, 0.1, 0.2)
show_dhudmessage(id, "[%s]^nТы вышел из режима АФК.", TAG)
}
case 3:
{
client_print_color(id, print_team_default, "^4[%s] ^1Ты вышел из ^3режима ^4AFK", TAG)
}
}
isAfk[id] = false
}
public fw_CmdStart(id, UC_Handle, Seed) // блокируем атаку афк-шнику
{
if(block)
{
if(isAfk[id])
{
new buttons = get_uc(UC_Handle, UC_Buttons)
if((buttons & IN_ATTACK))
{
buttons &= ~IN_ATTACK
set_uc(UC_Handle, UC_Buttons, buttons)
}
if((buttons & IN_ATTACK2))
{
buttons &= ~IN_ATTACK2
set_uc(UC_Handle, UC_Buttons, buttons)
}
}
}
}
public add_icon(index)
{
if(!is_user_connected(index))
return;
new origin[3]
get_user_origin(index, origin)
message_begin(MSG_ALL, SVC_TEMPENTITY);
write_byte(TE_SPRITE);
write_coord(origin[0] + 6)
write_coord(origin[1])
write_coord(origin[2] += 53)
write_short(sprite);
write_byte(5);
write_byte(120);
message_end();
set_task(2.0, "add_icon", index);
}
public remove_icon(index)
{
if(!is_user_connected(index))
return;
message_begin(MSG_ALL, SVC_TEMPENTITY)
write_byte(TE_KILLPLAYERATTACHMENTS);
write_byte(index);
message_end();
remove_task(index);
}
public native_is_afk(id) return isAfk[id]