Скриптер
Проверенный
Пользователь
- Сообщения
- 3,582
- Реакции
- 1,570
- Помог
- 137 раз(а)
wopox1337, с таким же макросом? wopox1337, как-то так.
12 Дек 2018
Код:
#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#define PLUGIN "AFK Protection"
#define VERSION "2.2.4"
#define AUTHOR "rapara13/Nordic Warrior"
#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)
#define TAG "AFK Protection" // Задаем тег
new bool:g_IsAfk[MAX_PLAYERS+1], Float:g_PlayerPosition[MAX_PLAYERS+1][3], Float:g_ViewAngle[MAX_PLAYERS+1][3], g_MoveTimer[MAX_PLAYERS+1]
new g_Effects, g_Message, g_Icon, g_CvarIcon, g_TimeAfk, g_Sprite, g_iMsgScreenFade
public plugin_init()
{
register_plugin(PLUGIN, VERSION, AUTHOR)
new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0)
bind_pcvar_num(pCvar, g_Effects)
pCvar = create_cvar("afk_type_message", "2", FCVAR_NONE, "Тип сообщений клиенту о переходе в режим АФК: 0 - выкл. 1 - hud, 2 - DHUD, 3 - чат", true, 0.0, true, 3.0)
bind_pcvar_num(pCvar, g_Message)
pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0)
bind_pcvar_num(pCvar, g_TimeAfk)
g_iMsgScreenFade = get_user_msgid("ScreenFade")
AutoExecConfig(true, "afk_protection")
set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat)
}
public plugin_natives() register_native("is_afk", "native_is_afk")
public client_disconnected(id) g_IsAfk[id] = false
public plugin_precache()
{
g_Icon = create_cvar("afk_icon", "1", FCVAR_NONE, "Иконка (спрайт) над игроком. 0 - выкл. 1 - вкл.", true, 0.0, true, 1.0)
g_CvarIcon = get_pcvar_num(g_Icon)
if(g_CvarIcon) g_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 <= MaxClients; i++)
{
if (!is_user_alive(i) || pev(i, pev_flags) & FL_INWATER)
continue
pev(i, pev_origin, origin)
pev(i, pev_angles, current_v_angle)
distance = vector_distance(g_PlayerPosition[i], origin)
if ((distance <= 1) & (g_ViewAngle[i][0] == current_v_angle[0] || g_ViewAngle[i][1] == current_v_angle[1]))
{
g_MoveTimer[i]++
if(g_MoveTimer[i] > g_TimeAfk * 2)
{
g_MoveTimer[i] = 0
afk(i)
}
}
else
{
g_MoveTimer[i] = 0
g_ViewAngle[i][0] = current_v_angle[0]
g_ViewAngle[i][1] = current_v_angle[1]
back(i)
}
xs_vec_copy(origin, g_PlayerPosition[i])
}
}
afk(id)
{
if(g_IsAfk[id])
return
fm_set_user_godmode(id, 1)
set_pev(id, pev_solid, SOLID_NOT)
set_bCantShoot(id, true)
if(g_CvarIcon) add_icon(id)
if(g_Effects == 1 || g_Effects == 3)
{
fm_set_rendering(id, kRenderFxNone,255,255,255,kRenderTransAlpha,120)
}
if(g_Effects == 2 || g_Effects == 3)
{
Screen_Fade(id, {0,0,0}, 130, ~0, ~0, 0x0004)
}
switch(g_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)
}
}
g_IsAfk[id] = true
}
back(id)
{
if(!g_IsAfk[id])
return
fm_set_user_godmode(id, 0)
set_pev(id, pev_solid, SOLID_SLIDEBOX)
set_bCantShoot(id, false)
if(g_CvarIcon) remove_icon(id)
if(g_Effects == 1 || g_Effects == 3)
{
fm_set_rendering(id,0,0,0,kRenderTransAlpha,0)
}
if(g_Effects == 2 || g_Effects == 3)
{
Screen_Fade(id, {0,0,0}, 100, 1<<10, 1<<10, 0x0000)
}
switch(g_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)
}
}
g_IsAfk[id] = false
}
public add_icon(index)
{
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(g_Sprite)
write_byte(5)
write_byte(120)
message_end()
set_task(2.0, "add_icon", index)
}
public remove_icon(index)
{
message_begin(MSG_ALL, SVC_TEMPENTITY)
write_byte(TE_KILLPLAYERATTACHMENTS)
write_byte(index)
message_end()
remove_task(index)
}
public native_is_afk(amxx, params)
{
enum { player = 1 }
new iPlayer = get_param(player)
if(!is_user_valid(iPlayer))
{
log_error(AMX_ERR_NATIVE, "[%s] Player out of range (id: %d)", TAG, iPlayer)
return PLUGIN_CONTINUE
}
return g_IsAfk[iPlayer]
}
stock Screen_Fade(const id, iColor[3], iAlpha, Duration, HoldTime, Flag)
{
message_begin(MSG_ONE, g_iMsgScreenFade, .player = id)
write_short(Duration)
write_short(HoldTime)
write_short(Flag)
write_byte(iColor[0])
write_byte(iColor[0])
write_byte(iColor[0])
write_byte(iAlpha)
message_end()
}