Преработка на "AFK Protection" добавяне на "flag"

В този раздел можете да подавате всякакви заявки за намиране, изработка или преработка на плъгини/модове.
Потребителски аватар

Автор на темата
M36
Потребител
Потребител
Мнения: 62
Регистриран: 19 фев 2019, 11:34
Се отблагодари: 7 пъти

Преработка на "AFK Protection" добавяне на "flag"

Мнение от M36 » 21 юни 2019, 21:58

Добър вечер ако може да се добави във плъгинът флаг "ADMIN_LEVEL_E"

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <hamsandwich>

#define VERSION "2.3"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)

/* Settings */

#define TAG "AFK Protection"	// Задаем тег
#define ICON					// Закомментируйте, если хотите убрать иконку (спрайт) афк.

/* End of Settigns */

enum _:Cvars
{
	EFFECTS,
	MESSAGE,
	TIME
}

new bool:g_IsAfk[MAX_PLAYERS + 1], Float:g_PlayerPosition[MAX_PLAYERS + 1][3], Float:g_ViewAngle[MAX_PLAYERS + 1][3];
new g_Cvar[Cvars], g_MoveTimer[MAX_PLAYERS + 1], g_Backup[MAX_PLAYERS + 1], g_iMsgScreenFade;

public plugin_init()
{
	register_plugin("AFK Protection", VERSION, "rapara13/Nordic Warrior");

	RegisterHam(Ham_Spawn, "player", "Player_spawns");
	RegisterHam(Ham_Killed, "player", "Player_killed");

	new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0);
	bind_pcvar_num(pCvar, g_Cvar[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_Cvar[MESSAGE]);

	pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0);
	bind_pcvar_num(pCvar, g_Cvar[TIME]);

	AutoExecConfig(true, "afk_protection");

	g_iMsgScreenFade = get_user_msgid("ScreenFade");

	set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat);
}

public plugin_natives()
{
	register_native("ap_is_user_afk", "native_check_afk");
}

public afkcheck()
{
	static Float:current_v_angle[3], Float:origin[3], Float:distance;
	static players[MAX_PLAYERS], pnum;

	get_players_ex(players, pnum, GetPlayers_ExcludeDead);

	for(new i, iPlayer; i < pnum; i++)
	{
		iPlayer = players[i];

		if(pev(iPlayer, pev_flags) & FL_INWATER)
			continue;

		pev(iPlayer, pev_origin, origin);
		pev(iPlayer, pev_angles, current_v_angle);

		distance = vector_distance(g_PlayerPosition[iPlayer], origin);

		if((distance <= 1) & (g_ViewAngle[iPlayer][0] == current_v_angle[0] || g_ViewAngle[iPlayer][1] == current_v_angle[1]))
		{
			g_MoveTimer[iPlayer]++;
			if(g_MoveTimer[iPlayer] > g_Cvar[TIME] * 2)
			{
				g_MoveTimer[iPlayer] = 0;
				afk(iPlayer);
			}
		}
		else
		{
			g_MoveTimer[iPlayer] = 0;
			g_ViewAngle[iPlayer][0] = current_v_angle[0];
			g_ViewAngle[iPlayer][1] = current_v_angle[1];
			back(iPlayer);
		}
		xs_vec_copy(origin, g_PlayerPosition[iPlayer]);
	}
}

afk(id)
{
	if(g_IsAfk[id])
		return;

	fm_set_user_godmode(id, true);
	set_pev(id, pev_solid, SOLID_NOT);

	set_bCantShoot(id, true);

	#if defined ICON
	add_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 120);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 130, ~0, ~0, 0x0004);
	}

	switch(g_Cvar[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, false);
	set_pev(id, pev_solid, SOLID_SLIDEBOX);

	set_bCantShoot(id, false);

	#if defined ICON
	remove_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, 0, 0, 0, kRenderTransAlpha, 0);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 100, 1<<10, 1<<10, 0x0000);
	}

	switch(g_Cvar[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 client_disconnected(id)
{
	g_IsAfk[id] = false;

	remove_task(id);
}

#if defined ICON
new g_Sprite;
public plugin_precache()
{
	g_Sprite = precache_model("sprites/afk/afk.spr");
}
#endif

public Player_spawns(id)
{
	new mapname[64];
	get_mapname(mapname, charsmax(mapname));

	if(equal(mapname, "35hp_", 5))
	{
		set_task(1.5, "Backup", id);
	}
	else
	{
		set_task(0.5, "Backup", id);
	}
}

public Player_killed(id)
{
	g_Backup[id] = g_MoveTimer[id];
}

public Backup(id)
{
	g_MoveTimer[id] = g_Backup[id];
}

#if defined ICON
public add_icon(id)
{
	new origin[3];
	get_user_origin(id, 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", id);
}

public remove_icon(id)
{
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_KILLPLAYERATTACHMENTS);
	write_byte(id);
	message_end();
	remove_task(id);
}
#endif

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();
}

public native_check_afk(amxx, params)
{
	enum { player = 1 }

	new iPlayer = get_param(player);

	if(!is_user_valid(iPlayer))
		abort(AMX_ERR_NATIVE, "Player out of range (id: %d)", iPlayer);

	return g_IsAfk[iPlayer];
}
Благодаря предварително !

Потребителски аватар

summertime vibes
Модератор
Модератор
Мнения: 1116
Регистриран: 27 ное 2016, 17:47
Местоположение: In the Heaven
Се отблагодари: 44 пъти
Получена благодарност: 97 пъти
Контакти:

Преработка на "AFK Protection" добавяне на "flag"

Мнение от summertime vibes » 21 юни 2019, 22:51

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <hamsandwich>

#define VERSION "2.3"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)

/* Settings */

#define TAG "AFK Protection"	// Задаем тег
#define ICON					// Закомментируйте, если хотите убрать иконку (спрайт) афк.

/* End of Settigns */

enum _:Cvars
{
	EFFECTS,
	MESSAGE,
	TIME
}

new bool:g_IsAfk[MAX_PLAYERS + 1], Float:g_PlayerPosition[MAX_PLAYERS + 1][3], Float:g_ViewAngle[MAX_PLAYERS + 1][3];
new g_Cvar[Cvars], g_MoveTimer[MAX_PLAYERS + 1], g_Backup[MAX_PLAYERS + 1], g_iMsgScreenFade;

public plugin_init()
{
	register_plugin("AFK Protection", VERSION, "rapara13/Nordic Warrior");

	RegisterHam(Ham_Spawn, "player", "Player_spawns");
	RegisterHam(Ham_Killed, "player", "Player_killed");

	new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0);
	bind_pcvar_num(pCvar, g_Cvar[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_Cvar[MESSAGE]);

	pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0);
	bind_pcvar_num(pCvar, g_Cvar[TIME]);

	AutoExecConfig(true, "afk_protection");

	g_iMsgScreenFade = get_user_msgid("ScreenFade");

	set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat);
}

public plugin_natives()
{
	register_native("ap_is_user_afk", "native_check_afk");
}

public afkcheck()
{
	static Float:current_v_angle[3], Float:origin[3], Float:distance;
	static players[MAX_PLAYERS], pnum;

	get_players_ex(players, pnum, GetPlayers_ExcludeDead);

	for(new i, iPlayer; i < pnum; i++)
	{
		iPlayer = players[i];

		if(pev(iPlayer, pev_flags) & FL_INWATER)
			continue;

		pev(iPlayer, pev_origin, origin);
		pev(iPlayer, pev_angles, current_v_angle);

		distance = vector_distance(g_PlayerPosition[iPlayer], origin);

		if((distance <= 1) & (g_ViewAngle[iPlayer][0] == current_v_angle[0] || g_ViewAngle[iPlayer][1] == current_v_angle[1]))
		{
			g_MoveTimer[iPlayer]++;
			if(g_MoveTimer[iPlayer] > g_Cvar[TIME] * 2)
			{
				g_MoveTimer[iPlayer] = 0;
				afk(iPlayer);
			}
		}
		else
		{
			g_MoveTimer[iPlayer] = 0;
			g_ViewAngle[iPlayer][0] = current_v_angle[0];
			g_ViewAngle[iPlayer][1] = current_v_angle[1];
			back(iPlayer);
		}
		xs_vec_copy(origin, g_PlayerPosition[iPlayer]);
	}
}

afk(id)
{
	if(g_IsAfk[id] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;

	fm_set_user_godmode(id, true);
	set_pev(id, pev_solid, SOLID_NOT);

	set_bCantShoot(id, true);

	#if defined ICON
	add_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 120);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 130, ~0, ~0, 0x0004);
	}

	switch(g_Cvar[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] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;

	fm_set_user_godmode(id, false);
	set_pev(id, pev_solid, SOLID_SLIDEBOX);

	set_bCantShoot(id, false);

	#if defined ICON
	remove_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, 0, 0, 0, kRenderTransAlpha, 0);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 100, 1<<10, 1<<10, 0x0000);
	}

	switch(g_Cvar[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 client_disconnected(id)
{
	g_IsAfk[id] = false;

	remove_task(id);
}

#if defined ICON
new g_Sprite;
public plugin_precache()
{
	g_Sprite = precache_model("sprites/afk/afk.spr");
}
#endif

public Player_spawns(id)
{
	new mapname[64];
	get_mapname(mapname, charsmax(mapname));

	if(equal(mapname, "35hp_", 5))
	{
		set_task(1.5, "Backup", id);
	}
	else
	{
		set_task(0.5, "Backup", id);
	}
}

public Player_killed(id)
{
	g_Backup[id] = g_MoveTimer[id];
}

public Backup(id)
{
	g_MoveTimer[id] = g_Backup[id];
}

#if defined ICON
public add_icon(id)
{
	new origin[3];
	get_user_origin(id, 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", id);
}

public remove_icon(id)
{
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_KILLPLAYERATTACHMENTS);
	write_byte(id);
	message_end();
	remove_task(id);
}
#endif

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();
}

public native_check_afk(amxx, params)
{
	enum { player = 1 }

	new iPlayer = get_param(player);

	if(!is_user_valid(iPlayer))
		abort(AMX_ERR_NATIVE, "Player out of range (id: %d)", iPlayer);

	return g_IsAfk[iPlayer];
}
тествай
Изображение
< PureServ.INFO SOON >
Изображение

Потребителски аватар

Автор на темата
M36
Потребител
Потребител
Мнения: 62
Регистриран: 19 фев 2019, 11:34
Се отблагодари: 7 пъти

Преработка на "AFK Protection" добавяне на "flag"

Мнение от M36 » 21 юни 2019, 23:20

не е станал , всички имат още

Потребителски аватар

mBFF-TheFucKBG tm
Потребител
Потребител
Мнения: 255
Регистриран: 09 ное 2018, 16:40
Местоположение: Сливен
Се отблагодари: 8 пъти
Получена благодарност: 5 пъти
Години: 15

Преработка на "AFK Protection" добавяне на "flag"

Мнение от mBFF-TheFucKBG tm » 22 юни 2019, 10:02

МНЕНИЕТО Е СКРИТО ОТ СТРАНА НА МОДЕРАТОР! ЦЪКНИ ВЪРХУ ЛЕНТАТА ЗА ДА ГО ПРЕГЛЕДАШ.
Последна промяна от summertime vibes на 22 юни 2019, 10:11, променено общо 1 път.
Причина: Безсмислен коментар! Следващият път +1 предупреждение.
A story about my life will tell in an epilogue, I grew a poor, honest boy, but with dreams in my heart. She was tight to me in every battle, every bad day, I have already made every dream come true, but I gave it to you. My wife did not cry for me, I do not deserve you, and you up on your own, shove everyone up to the end. My dear, you do not cry for me, we will be together in paradise, and now up there, I want you to win all. The story for me continues, shine, fake and many lies, I want to come back before, you have nothing, but you are with her. She was tight to me in every battle, every bad day, I have already made every dream come true, but I betrayed her.

Потребителски аватар

summertime vibes
Модератор
Модератор
Мнения: 1116
Регистриран: 27 ное 2016, 17:47
Местоположение: In the Heaven
Се отблагодари: 44 пъти
Получена благодарност: 97 пъти
Контакти:

Преработка на "AFK Protection" добавяне на "flag"

Мнение от summertime vibes » 22 юни 2019, 10:20

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <hamsandwich>

#define VERSION "2.3"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)

/* Settings */

#define TAG "AFK Protection"	// Задаем тег
#define ICON					// Закомментируйте, если хотите убрать иконку (спрайт) афк.

/* End of Settigns */

enum _:Cvars
{
	EFFECTS,
	MESSAGE,
	TIME
}

new bool:g_IsAfk[MAX_PLAYERS + 1], Float:g_PlayerPosition[MAX_PLAYERS + 1][3], Float:g_ViewAngle[MAX_PLAYERS + 1][3];
new g_Cvar[Cvars], g_MoveTimer[MAX_PLAYERS + 1], g_Backup[MAX_PLAYERS + 1], g_iMsgScreenFade;

public plugin_init()
{
	register_plugin("AFK Protection", VERSION, "rapara13/Nordic Warrior");

	RegisterHam(Ham_Spawn, "player", "Player_spawns");
	RegisterHam(Ham_Killed, "player", "Player_killed");

	new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0);
	bind_pcvar_num(pCvar, g_Cvar[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_Cvar[MESSAGE]);

	pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0);
	bind_pcvar_num(pCvar, g_Cvar[TIME]);

	AutoExecConfig(true, "afk_protection");

	g_iMsgScreenFade = get_user_msgid("ScreenFade");

	set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat);
}

public plugin_natives()
{
	register_native("ap_is_user_afk", "native_check_afk");
}

public afkcheck()
{
	static Float:current_v_angle[3], Float:origin[3], Float:distance;
	static players[MAX_PLAYERS], pnum;

	get_players_ex(players, pnum, GetPlayers_ExcludeDead);

	for(new i, iPlayer; i < pnum; i++)
	{
		iPlayer = players[i];

		if(pev(iPlayer, pev_flags) & FL_INWATER)
			continue;

		pev(iPlayer, pev_origin, origin);
		pev(iPlayer, pev_angles, current_v_angle);

		distance = vector_distance(g_PlayerPosition[iPlayer], origin);

		if((distance <= 1) & (get_user_flags(iPlayer) & ADMIN_LEVEL_E) & (g_ViewAngle[iPlayer][0] == current_v_angle[0] || g_ViewAngle[iPlayer][1] == current_v_angle[1]))
		{
			g_MoveTimer[iPlayer]++;
			if(g_MoveTimer[iPlayer] > g_Cvar[TIME] * 2)
			{
				g_MoveTimer[iPlayer] = 0;
				afk(iPlayer);
			}
		}
		else
		{
			g_MoveTimer[iPlayer] = 0;
			g_ViewAngle[iPlayer][0] = current_v_angle[0];
			g_ViewAngle[iPlayer][1] = current_v_angle[1];
			back(iPlayer);
		}
		xs_vec_copy(origin, g_PlayerPosition[iPlayer]);
	}
}

afk(id)
{
	if(g_IsAfk[id] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;

	fm_set_user_godmode(id, true);
	set_pev(id, pev_solid, SOLID_NOT);

	set_bCantShoot(id, true);

	#if defined ICON
	add_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 120);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 130, ~0, ~0, 0x0004);
	}

	switch(g_Cvar[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] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;

	fm_set_user_godmode(id, false);
	set_pev(id, pev_solid, SOLID_SLIDEBOX);

	set_bCantShoot(id, false);

	#if defined ICON
	remove_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, 0, 0, 0, kRenderTransAlpha, 0);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 100, 1<<10, 1<<10, 0x0000);
	}

	switch(g_Cvar[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 client_disconnected(id)
{
	g_IsAfk[id] = false;

	remove_task(id);
}

#if defined ICON
new g_Sprite;
public plugin_precache()
{
	g_Sprite = precache_model("sprites/afk/afk.spr");
}
#endif

public Player_spawns(id)
{
	new mapname[64];
	get_mapname(mapname, charsmax(mapname));

	if(equal(mapname, "35hp_", 5))
	{
		set_task(1.5, "Backup", id);
	}
	else
	{
		set_task(0.5, "Backup", id);
	}
}

public Player_killed(id)
{
	g_Backup[id] = g_MoveTimer[id];
}

public Backup(id)
{
	g_MoveTimer[id] = g_Backup[id];
}

#if defined ICON
public add_icon(id)
{
	new origin[3];
	get_user_origin(id, 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", id);
}

public remove_icon(id)
{
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_KILLPLAYERATTACHMENTS);
	write_byte(id);
	message_end();
	remove_task(id);
}
#endif

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();
}

public native_check_afk(amxx, params)
{
	enum { player = 1 }

	new iPlayer = get_param(player);

	if(!is_user_valid(iPlayer))
		abort(AMX_ERR_NATIVE, "Player out of range (id: %d)", iPlayer);

	return g_IsAfk[iPlayer];
}
тествай така
Изображение
< PureServ.INFO SOON >
Изображение

Потребителски аватар

JackEyedJones
Потребител
Потребител
Мнения: 220
Регистриран: 10 сеп 2018, 17:26
Местоположение: Plovdiv, Bulgaria, Europe, Entire World
Се отблагодари: 3 пъти
Получена благодарност: 36 пъти
Години: 26
Контакти:

Преработка на "AFK Protection" добавяне на "flag"

Мнение от JackEyedJones » 22 юни 2019, 10:40

Код: Избери всички

if(g_IsAfk[id] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;
При сегашното условие, ако има флага, проверката спира до реда на който е тази проверка заради return-a.

--> Коригирайте го така.

Код: Избери всички

if(g_IsAfk[id] & !(get_user_flags(id) & ADMIN_LEVEL_E))
		return;

Потребителски аватар

Автор на темата
M36
Потребител
Потребител
Мнения: 62
Регистриран: 19 фев 2019, 11:34
Се отблагодари: 7 пъти

Преработка на "AFK Protection" добавяне на "flag"

Мнение от M36 » 22 юни 2019, 11:32

summertime vibes написа:
22 юни 2019, 10:20

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <hamsandwich>

#define VERSION "2.3"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)

/* Settings */

#define TAG "AFK Protection"	// Задаем тег
#define ICON					// Закомментируйте, если хотите убрать иконку (спрайт) афк.

/* End of Settigns */

enum _:Cvars
{
	EFFECTS,
	MESSAGE,
	TIME
}

new bool:g_IsAfk[MAX_PLAYERS + 1], Float:g_PlayerPosition[MAX_PLAYERS + 1][3], Float:g_ViewAngle[MAX_PLAYERS + 1][3];
new g_Cvar[Cvars], g_MoveTimer[MAX_PLAYERS + 1], g_Backup[MAX_PLAYERS + 1], g_iMsgScreenFade;

public plugin_init()
{
	register_plugin("AFK Protection", VERSION, "rapara13/Nordic Warrior");

	RegisterHam(Ham_Spawn, "player", "Player_spawns");
	RegisterHam(Ham_Killed, "player", "Player_killed");

	new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0);
	bind_pcvar_num(pCvar, g_Cvar[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_Cvar[MESSAGE]);

	pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0);
	bind_pcvar_num(pCvar, g_Cvar[TIME]);

	AutoExecConfig(true, "afk_protection");

	g_iMsgScreenFade = get_user_msgid("ScreenFade");

	set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat);
}

public plugin_natives()
{
	register_native("ap_is_user_afk", "native_check_afk");
}

public afkcheck()
{
	static Float:current_v_angle[3], Float:origin[3], Float:distance;
	static players[MAX_PLAYERS], pnum;

	get_players_ex(players, pnum, GetPlayers_ExcludeDead);

	for(new i, iPlayer; i < pnum; i++)
	{
		iPlayer = players[i];

		if(pev(iPlayer, pev_flags) & FL_INWATER)
			continue;

		pev(iPlayer, pev_origin, origin);
		pev(iPlayer, pev_angles, current_v_angle);

		distance = vector_distance(g_PlayerPosition[iPlayer], origin);

		if((distance <= 1) & (get_user_flags(iPlayer) & ADMIN_LEVEL_E) & (g_ViewAngle[iPlayer][0] == current_v_angle[0] || g_ViewAngle[iPlayer][1] == current_v_angle[1]))
		{
			g_MoveTimer[iPlayer]++;
			if(g_MoveTimer[iPlayer] > g_Cvar[TIME] * 2)
			{
				g_MoveTimer[iPlayer] = 0;
				afk(iPlayer);
			}
		}
		else
		{
			g_MoveTimer[iPlayer] = 0;
			g_ViewAngle[iPlayer][0] = current_v_angle[0];
			g_ViewAngle[iPlayer][1] = current_v_angle[1];
			back(iPlayer);
		}
		xs_vec_copy(origin, g_PlayerPosition[iPlayer]);
	}
}

afk(id)
{
	if(g_IsAfk[id] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;

	fm_set_user_godmode(id, true);
	set_pev(id, pev_solid, SOLID_NOT);

	set_bCantShoot(id, true);

	#if defined ICON
	add_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 120);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 130, ~0, ~0, 0x0004);
	}

	switch(g_Cvar[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] && get_user_flags(id) & ADMIN_LEVEL_E)
		return;

	fm_set_user_godmode(id, false);
	set_pev(id, pev_solid, SOLID_SLIDEBOX);

	set_bCantShoot(id, false);

	#if defined ICON
	remove_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, 0, 0, 0, kRenderTransAlpha, 0);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 100, 1<<10, 1<<10, 0x0000);
	}

	switch(g_Cvar[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 client_disconnected(id)
{
	g_IsAfk[id] = false;

	remove_task(id);
}

#if defined ICON
new g_Sprite;
public plugin_precache()
{
	g_Sprite = precache_model("sprites/afk/afk.spr");
}
#endif

public Player_spawns(id)
{
	new mapname[64];
	get_mapname(mapname, charsmax(mapname));

	if(equal(mapname, "35hp_", 5))
	{
		set_task(1.5, "Backup", id);
	}
	else
	{
		set_task(0.5, "Backup", id);
	}
}

public Player_killed(id)
{
	g_Backup[id] = g_MoveTimer[id];
}

public Backup(id)
{
	g_MoveTimer[id] = g_Backup[id];
}

#if defined ICON
public add_icon(id)
{
	new origin[3];
	get_user_origin(id, 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", id);
}

public remove_icon(id)
{
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_KILLPLAYERATTACHMENTS);
	write_byte(id);
	message_end();
	remove_task(id);
}
#endif

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();
}

public native_check_afk(amxx, params)
{
	enum { player = 1 }

	new iPlayer = get_param(player);

	if(!is_user_valid(iPlayer))
		abort(AMX_ERR_NATIVE, "Player out of range (id: %d)", iPlayer);

	return g_IsAfk[iPlayer];
}
тествай така
Отново не се получи ,човека с флага няма никакав протект ,а обикновнния играч има едно премигане на екрана афк протект

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5320
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 76 пъти
Получена благодарност: 560 пъти
Години: 21
Контакти:

Преработка на "AFK Protection" добавяне на "flag"

Мнение от OciXCrom TM » 22 юни 2019, 14:45

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <hamsandwich>

#define VERSION "2.3"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)

/* Settings */

#define TAG "AFK Protection"	// Задаем тег
#define ICON					// Закомментируйте, если хотите убрать иконку (спрайт) афк.

/* End of Settigns */

enum _:Cvars
{
	EFFECTS,
	MESSAGE,
	TIME
}

new bool:g_IsAfk[MAX_PLAYERS + 1], Float:g_PlayerPosition[MAX_PLAYERS + 1][3], Float:g_ViewAngle[MAX_PLAYERS + 1][3];
new g_Cvar[Cvars], g_MoveTimer[MAX_PLAYERS + 1], g_Backup[MAX_PLAYERS + 1], g_iMsgScreenFade;

public plugin_init()
{
	register_plugin("AFK Protection", VERSION, "rapara13/Nordic Warrior");

	RegisterHam(Ham_Spawn, "player", "Player_spawns");
	RegisterHam(Ham_Killed, "player", "Player_killed");

	new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0);
	bind_pcvar_num(pCvar, g_Cvar[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_Cvar[MESSAGE]);

	pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0);
	bind_pcvar_num(pCvar, g_Cvar[TIME]);

	AutoExecConfig(true, "afk_protection");

	g_iMsgScreenFade = get_user_msgid("ScreenFade");

	set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat);
}

public plugin_natives()
{
	register_native("ap_is_user_afk", "native_check_afk");
}

public afkcheck()
{
	static Float:current_v_angle[3], Float:origin[3], Float:distance;
	static players[MAX_PLAYERS], pnum;

	get_players_ex(players, pnum, GetPlayers_ExcludeDead);

	for(new i, iPlayer; i < pnum; i++)
	{
		iPlayer = players[i];

		if(get_user_flags(iPlayer) & ADMIN_LEVEL_E)
			continue;

		if(pev(iPlayer, pev_flags) & FL_INWATER)
			continue;

		pev(iPlayer, pev_origin, origin);
		pev(iPlayer, pev_angles, current_v_angle);

		distance = vector_distance(g_PlayerPosition[iPlayer], origin);

		if((distance <= 1) & (g_ViewAngle[iPlayer][0] == current_v_angle[0] || g_ViewAngle[iPlayer][1] == current_v_angle[1]))
		{
			g_MoveTimer[iPlayer]++;
			if(g_MoveTimer[iPlayer] > g_Cvar[TIME] * 2)
			{
				g_MoveTimer[iPlayer] = 0;
				afk(iPlayer);
			}
		}
		else
		{
			g_MoveTimer[iPlayer] = 0;
			g_ViewAngle[iPlayer][0] = current_v_angle[0];
			g_ViewAngle[iPlayer][1] = current_v_angle[1];
			back(iPlayer);
		}
		xs_vec_copy(origin, g_PlayerPosition[iPlayer]);
	}
}

afk(id)
{
	if(g_IsAfk[id])
		return;

	fm_set_user_godmode(id, true);
	set_pev(id, pev_solid, SOLID_NOT);

	set_bCantShoot(id, true);

	#if defined ICON
	add_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 120);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 130, ~0, ~0, 0x0004);
	}

	switch(g_Cvar[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, false);
	set_pev(id, pev_solid, SOLID_SLIDEBOX);

	set_bCantShoot(id, false);

	#if defined ICON
	remove_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, 0, 0, 0, kRenderTransAlpha, 0);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 100, 1<<10, 1<<10, 0x0000);
	}

	switch(g_Cvar[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 client_disconnected(id)
{
	g_IsAfk[id] = false;

	remove_task(id);
}

#if defined ICON
new g_Sprite;
public plugin_precache()
{
	g_Sprite = precache_model("sprites/afk/afk.spr");
}
#endif

public Player_spawns(id)
{
	new mapname[64];
	get_mapname(mapname, charsmax(mapname));

	if(equal(mapname, "35hp_", 5))
	{
		set_task(1.5, "Backup", id);
	}
	else
	{
		set_task(0.5, "Backup", id);
	}
}

public Player_killed(id)
{
	g_Backup[id] = g_MoveTimer[id];
}

public Backup(id)
{
	g_MoveTimer[id] = g_Backup[id];
}

#if defined ICON
public add_icon(id)
{
	new origin[3];
	get_user_origin(id, 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", id);
}

public remove_icon(id)
{
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_KILLPLAYERATTACHMENTS);
	write_byte(id);
	message_end();
	remove_task(id);
}
#endif

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();
}

public native_check_afk(amxx, params)
{
	enum { player = 1 }

	new iPlayer = get_param(player);

	if(!is_user_valid(iPlayer))
		abort(AMX_ERR_NATIVE, "Player out of range (id: %d)", iPlayer);

	return g_IsAfk[iPlayer];
}

Потребителски аватар

Автор на темата
M36
Потребител
Потребител
Мнения: 62
Регистриран: 19 фев 2019, 11:34
Се отблагодари: 7 пъти

Преработка на "AFK Protection" добавяне на "flag"

Мнение от M36 » 22 юни 2019, 15:34

OciXCrom написа:
22 юни 2019, 14:45

Код: Избери всички

#include <amxmodx>
#include <amxmisc>
#include <fakemeta_util>
#include <hamsandwich>

#define VERSION "2.3"

#define is_user_valid(%0) (1 <= %0 <= MaxClients)
#define set_bCantShoot(%1,%2) set_ent_data(%1, "CBasePlayer", "m_bIsDefusing", %2)

/* Settings */

#define TAG "AFK Protection"	// Задаем тег
#define ICON					// Закомментируйте, если хотите убрать иконку (спрайт) афк.

/* End of Settigns */

enum _:Cvars
{
	EFFECTS,
	MESSAGE,
	TIME
}

new bool:g_IsAfk[MAX_PLAYERS + 1], Float:g_PlayerPosition[MAX_PLAYERS + 1][3], Float:g_ViewAngle[MAX_PLAYERS + 1][3];
new g_Cvar[Cvars], g_MoveTimer[MAX_PLAYERS + 1], g_Backup[MAX_PLAYERS + 1], g_iMsgScreenFade;

public plugin_init()
{
	register_plugin("AFK Protection", VERSION, "rapara13/Nordic Warrior");

	RegisterHam(Ham_Spawn, "player", "Player_spawns");
	RegisterHam(Ham_Killed, "player", "Player_killed");

	new pCvar = create_cvar("afk_effects", "3", FCVAR_NONE, "Эффекты: 0 - выкл. 1 - прозрачность игрока, 2 - затемнение экрана игроку, 3 - всё вместе", true, 0.0, true, 3.0);
	bind_pcvar_num(pCvar, g_Cvar[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_Cvar[MESSAGE]);

	pCvar = create_cvar("afk_time", "15", FCVAR_NONE, "Время простоя игрока до входа в режим АФК. (в секундах)", true, 1.0);
	bind_pcvar_num(pCvar, g_Cvar[TIME]);

	AutoExecConfig(true, "afk_protection");

	g_iMsgScreenFade = get_user_msgid("ScreenFade");

	set_task_ex(0.5, "afkcheck", .flags = SetTask_Repeat);
}

public plugin_natives()
{
	register_native("ap_is_user_afk", "native_check_afk");
}

public afkcheck()
{
	static Float:current_v_angle[3], Float:origin[3], Float:distance;
	static players[MAX_PLAYERS], pnum;

	get_players_ex(players, pnum, GetPlayers_ExcludeDead);

	for(new i, iPlayer; i < pnum; i++)
	{
		iPlayer = players[i];

		if(get_user_flags(iPlayer) & ADMIN_LEVEL_E)
			continue;

		if(pev(iPlayer, pev_flags) & FL_INWATER)
			continue;

		pev(iPlayer, pev_origin, origin);
		pev(iPlayer, pev_angles, current_v_angle);

		distance = vector_distance(g_PlayerPosition[iPlayer], origin);

		if((distance <= 1) & (g_ViewAngle[iPlayer][0] == current_v_angle[0] || g_ViewAngle[iPlayer][1] == current_v_angle[1]))
		{
			g_MoveTimer[iPlayer]++;
			if(g_MoveTimer[iPlayer] > g_Cvar[TIME] * 2)
			{
				g_MoveTimer[iPlayer] = 0;
				afk(iPlayer);
			}
		}
		else
		{
			g_MoveTimer[iPlayer] = 0;
			g_ViewAngle[iPlayer][0] = current_v_angle[0];
			g_ViewAngle[iPlayer][1] = current_v_angle[1];
			back(iPlayer);
		}
		xs_vec_copy(origin, g_PlayerPosition[iPlayer]);
	}
}

afk(id)
{
	if(g_IsAfk[id])
		return;

	fm_set_user_godmode(id, true);
	set_pev(id, pev_solid, SOLID_NOT);

	set_bCantShoot(id, true);

	#if defined ICON
	add_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, kRenderFxNone, 255, 255, 255, kRenderTransAlpha, 120);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 130, ~0, ~0, 0x0004);
	}

	switch(g_Cvar[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, false);
	set_pev(id, pev_solid, SOLID_SLIDEBOX);

	set_bCantShoot(id, false);

	#if defined ICON
	remove_icon(id);
	#endif

	if(g_Cvar[EFFECTS] == 1 || g_Cvar[EFFECTS] == 3)
	{
		fm_set_rendering(id, 0, 0, 0, kRenderTransAlpha, 0);
	}
	if(g_Cvar[EFFECTS] == 2 || g_Cvar[EFFECTS] == 3)
	{
		Screen_Fade(id, { 0, 0, 0 }, 100, 1<<10, 1<<10, 0x0000);
	}

	switch(g_Cvar[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 client_disconnected(id)
{
	g_IsAfk[id] = false;

	remove_task(id);
}

#if defined ICON
new g_Sprite;
public plugin_precache()
{
	g_Sprite = precache_model("sprites/afk/afk.spr");
}
#endif

public Player_spawns(id)
{
	new mapname[64];
	get_mapname(mapname, charsmax(mapname));

	if(equal(mapname, "35hp_", 5))
	{
		set_task(1.5, "Backup", id);
	}
	else
	{
		set_task(0.5, "Backup", id);
	}
}

public Player_killed(id)
{
	g_Backup[id] = g_MoveTimer[id];
}

public Backup(id)
{
	g_MoveTimer[id] = g_Backup[id];
}

#if defined ICON
public add_icon(id)
{
	new origin[3];
	get_user_origin(id, 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", id);
}

public remove_icon(id)
{
	message_begin(MSG_ALL, SVC_TEMPENTITY);
	write_byte(TE_KILLPLAYERATTACHMENTS);
	write_byte(id);
	message_end();
	remove_task(id);
}
#endif

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();
}

public native_check_afk(amxx, params)
{
	enum { player = 1 }

	new iPlayer = get_param(player);

	if(!is_user_valid(iPlayer))
		abort(AMX_ERR_NATIVE, "Player out of range (id: %d)", iPlayer);

	return g_IsAfk[iPlayer];
}
сега имат само нормалните играчи ,играча със флаг нямат .

Потребителски аватар

OciXCrom TM
Администратор
Администратор
Мнения: 5320
Регистриран: 06 окт 2016, 19:20
Местоположение: /resetscore
Се отблагодари: 76 пъти
Получена благодарност: 560 пъти
Години: 21
Контакти:

Преработка на "AFK Protection" добавяне на "flag"

Мнение от OciXCrom TM » 22 юни 2019, 16:59

А, ти какво изобщо искаш?!

Заключена

Върни се в “Заявки за плъгини”

Кой е на линия

Потребители, разглеждащи този форум: Няма регистрирани потребители и 1 гост