Скриптер
Проверенный
Пользователь
- Сообщения
- 3,582
- Реакции
- 1,570
- Помог
- 137 раз(а)
Добрый вечер всем, не могу понять, как правильно отловить изменение угла обзора всех игроков, для плагина афк менеджер.
Одна из моих попыток:
и еще с десяток неудачных вариантов.
Исходник прилагаю.
Одна из моих попыток:
Код:
public angles(id)
{
pev(id, pev_v_angle, fAngles)
}
public angles2(id)
{
pev(id, pev_v_angle, pAngles)
}
public campcheck()
{
if(!get_pcvar_num(afk_protection_auto))
return
// Check all players to see if they've moved...
new origin[3]
new dx,dy,dz
for(new i = 1; i <= 32; i++) {
if (!is_user_alive(i)) continue
if (Entvars_Get_Int(i, EV_INT_flags)&FL_NOTARGET) continue
if (God_Mode(i) == 1 || !is_on_afk(i) || is_on_fire(i)) continue
get_user_origin(i,origin)
dx = gPlayerPosition[i][0] - origin[0]
dy = gPlayerPosition[i][1] - origin[1]
dz = gPlayerPosition[i][2] - origin[2]
new d = sqrt( dx*dx + dy*dy + dz*dz )
if (d <= get_pcvar_num(afk_movedist)) {
gMoveTimer[i]++
if(gMoveTimer[i] > get_pcvar_num(afk_camptime)) {
gMoveTimer[i]=0
afk(i)
}
} else {
gMoveTimer[i] = 0
back(i)
}
gPlayerPosition[i][0] = origin[0]
gPlayerPosition[i][1] = origin[1]
gPlayerPosition[i][2] = origin[2]
angles(i)
set_task(0.5, "angles2(i)", 123)
if(fAngles[0] != pAngles[0] || fAngles[1] != pAngles[1] || fAngles[2] != pAngles[2])
{
//gMoveTimer[i] = 0
back(i)
}
}
}
Исходник прилагаю.
Код:
#include <amxmodx>
#include <fun>
#include <fakemeta>
#include <fakemeta_util>
#include <engine>
#include <hamsandwich>
#include <Vexd_Utilities>
#include <godmode>
#include <sky>
#define VERSION "2.0"
#define TAG "AFK Менеджер"
new afk_protection, afk_protection_nr, afk_protection_auto,
afk_camptime, afk_movedist,
afk_glow, afk_glow_color, afk_glow_amount,
afk_transparent, afk_transparent_amount,
afk_icon, afk_blind
new isAfk[33]
new g_SayText, Sprite
new Float:fAngles[3]
new Float:pAngles[3]
new gPlayerPosition[32][3] // keeps track of last known origin
new gMoveTimer[32] // incremented if player didn't move far enough
public plugin_init() {
register_plugin("AFK Protection", VERSION, "rapara13")
register_cvar("afk_protection", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
RegisterHam( Ham_Item_PreFrame, "player", "v_PlayerFixMaxSpeed", 0 );
register_logevent("RoundStart",2,"1=Round_Start")
afk_protection = register_cvar("afk_protection","1")
afk_protection_nr = register_cvar("afk_protection_new_round","1")
afk_protection_auto = register_cvar("afk_protection_auto","1")
afk_camptime = register_cvar("afk_camptime", "20")
afk_movedist = register_cvar("afk_movedist", "1")
afk_glow = register_cvar("afk_glow","1")
afk_glow_color = register_cvar("afk_glow_color","255 0 0")
afk_glow_amount = register_cvar("afk_glow_amount","0")
afk_transparent = register_cvar("afk_transparent","1")
afk_transparent_amount = register_cvar("afk_transparent_amount","120")
afk_icon = register_cvar("afk_icon","1")
afk_blind = register_cvar("afk_blind","1")
g_SayText = get_user_msgid("SayText")
if(get_pcvar_num(afk_protection_auto))
set_task(0.5,"campcheck",0,"",0,"b" )
register_forward(FM_CmdStart, "fw_CmdStart")
}
public plugin_natives()
{
register_native("is_afk", "native_is_afk", 1)
}
public plugin_precache() {
Sprite = precache_model("sprites/sky/afk.spr")
}
public client_connect(id) {
isAfk[id] = false
}
public client_disconnected(id) {
isAfk[id] = false
}
public RoundStart() {
new players[32], num
get_players(players,num,"h")
for(new i=0;i<num;i++)
{
if(!get_pcvar_num(afk_protection) && !get_pcvar_num(afk_protection_nr))
return
if(isAfk[players[i]] && is_user_alive(players[i])) {
new color[17], red[5],green[7],blue[5]
new amount = get_pcvar_num(afk_glow_amount)
new tamount = get_pcvar_num(afk_transparent_amount)
get_pcvar_string(afk_glow_color,color,16)
parse(color,red,4,green,6,blue,4)
set_user_godmode(players[i], 1)
if(get_pcvar_num(afk_glow) == 1) {
set_user_rendering(players[i], kRenderFxGlowShell, str_to_num(red), str_to_num(green), str_to_num(blue), kRenderNormal, amount)
}
else if(get_pcvar_num(afk_glow) == 2) {
if(get_user_team(players[i]) == 1) {
set_user_rendering(players[i], kRenderFxGlowShell, 255, 0, 0, kRenderNormal, amount)
}
else if(get_user_team(players[i]) == 2) {
set_user_rendering(players[i], kRenderFxGlowShell, 0, 0, 255, kRenderNormal, amount)
}
}
if(get_pcvar_num(afk_transparent)) {
set_user_rendering(players[i], kRenderFxNone,255,255,255,kRenderTransAlpha,tamount)
}
if(get_pcvar_num(afk_blind)) {
message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, players[i])
write_short(~0)
write_short(~0)
write_short(0x0004) // stay faded
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(255)
message_end()
}
if(get_pcvar_num(afk_icon)) {
add_icon(players[i]);
}
}
if(is_user_alive(players[i])) {
get_user_origin(players[i], gPlayerPosition[players[i]])
}
}
}
public afk(id) {
if(!get_pcvar_num(afk_protection))
return
if(isAfk[id])
return
if(is_user_alive(id)) {
new color[17], red[5],green[7],blue[5]
get_pcvar_string(afk_glow_color,color,16)
parse(color,red,4,green,6,blue,4)
new amount = get_pcvar_num(afk_glow_amount)
new tamount = get_pcvar_num(afk_transparent_amount)
//strip_user_weapons(id)
set_user_godmode(id, 1)
if(get_pcvar_num(afk_glow) == 1) {
set_user_rendering(id, kRenderFxGlowShell, str_to_num(red), str_to_num(green), str_to_num(blue), kRenderNormal, amount)
}
else if(get_pcvar_num(afk_glow) == 2) {
if(get_user_team(id) == 1) {
set_user_rendering(id, kRenderFxGlowShell, 255, 0, 0, kRenderNormal, amount)
}
else if(get_user_team(id) == 2) {
set_user_rendering(id, kRenderFxGlowShell, 0, 0, 255, kRenderNormal, amount)
}
}
if(get_pcvar_num(afk_transparent)) {
set_user_rendering(id, kRenderFxNone,255,255,255,kRenderTransAlpha,tamount)
}
if(get_pcvar_num(afk_blind)) {
message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
write_short(~0)
write_short(~0)
write_short(0x0004) // stay faded
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(150)
message_end()
}
if(get_pcvar_num(afk_icon)) {
add_icon(id + 173);
}
set_dhudmessage(0, 206, 209, -1.0, 0.1, 0, 1.0, 7.0, 0.1, 0.2)
show_dhudmessage(id, "[%s]^nТы перешел в режим АФК.", TAG)
isAfk[id] = true
} else {
colormsg(id, "\g[%s] \tТы не можешь использовать режим АФК, когда мертв!", TAG)
}
}
public back(id) {
if(!get_pcvar_num(afk_protection))
return
if(!isAfk[id])
return
if(is_user_alive(id)) {
set_user_godmode(id, 0)
if(get_pcvar_num(afk_glow)) {
set_user_rendering(id, kRenderFxGlowShell, 0, 0, 0, kRenderNormal, 0)
}
if(get_pcvar_num(afk_transparent)) {
set_user_rendering(id,0,0,0,kRenderTransAlpha,0)
}
if(get_pcvar_num(afk_blind)) {
message_begin(MSG_ONE, get_user_msgid("ScreenFade"), {0,0,0}, id)
write_short(1<<10)
write_short(1<<10)
write_short(0x0000) // stay faded
write_byte(0)
write_byte(0)
write_byte(0)
write_byte(100)
message_end()
}
if(get_pcvar_num(afk_icon)) {
remove_icon(id);
}
remove_icon(id)
colormsg(id, "\g[%s] \tТы вышел из режима \gAFK.", TAG)
isAfk[id] = false
} else {
colormsg(id, "\g[%s] \tТы не можешь выключить режим АФК, когда мертв!", TAG)
}
}
public fw_CmdStart(id, UC_Handle, Seed)
{
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 angles(id)
{
pev(id, pev_v_angle, fAngles)
}
public angles2(id)
{
pev(id, pev_v_angle, pAngles)
}
public campcheck()
{
if(!get_pcvar_num(afk_protection_auto))
return
// Check all players to see if they've moved...
new origin[3]
new dx,dy,dz
for(new i = 1; i <= 32; i++) {
if (!is_user_alive(i)) continue
if (Entvars_Get_Int(i, EV_INT_flags)&FL_NOTARGET) continue
if (God_Mode(i) == 1 || !is_on_afk(i) || is_on_fire(i)) continue
get_user_origin(i,origin)
dx = gPlayerPosition[i][0] - origin[0]
dy = gPlayerPosition[i][1] - origin[1]
dz = gPlayerPosition[i][2] - origin[2]
new d = sqrt( dx*dx + dy*dy + dz*dz )
if (d <= get_pcvar_num(afk_movedist)) {
gMoveTimer[i]++
if(gMoveTimer[i] > get_pcvar_num(afk_camptime)) {
gMoveTimer[i]=0
afk(i)
}
} else {
gMoveTimer[i] = 0
back(i)
}
gPlayerPosition[i][0] = origin[0]
gPlayerPosition[i][1] = origin[1]
gPlayerPosition[i][2] = origin[2]
angles(i)
set_task(0.5, "angles2(i)", 123)
if(fAngles[0] != pAngles[0] || fAngles[1] != pAngles[1] || fAngles[2] != pAngles[2])
{
//gMoveTimer[i] = 0
back(i)
}
}
}
stock colormsg(const id, const string[], {Float, Sql, Resul,_}:...) {
new msg[191], players[32], count = 1;
vformat(msg, sizeof msg - 1, string, 3);
replace_all(msg,190,"\g","^4");
replace_all(msg,190,"\y","^1");
replace_all(msg,190,"\t","^3");
if(id)
players[0] = id;
else
get_players(players,count,"ch");
for (new i = 0 ; i < count ; i++)
{
if (is_user_connected(players[i]))
{
message_begin(MSG_ONE_UNRELIABLE, g_SayText,_, players[i]);
write_byte(players[i]);
write_string(msg);
message_end();
}
}
}
public v_PlayerFixMaxSpeed(id)
{
if (!is_user_connected(id))
return HAM_IGNORED;
if (get_user_maxspeed(id) != 400.0)
return HAM_IGNORED;
return HAM_SUPERCEDE;
}
public add_icon(index)
{
new id = index - 173;
if(!is_user_connected(id))
return;
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(Sprite);
write_byte(5);
write_byte(120);
message_end();
set_task(2.0, "add_icon", id + 173, _, _, "a", 1);
}
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 + 173);
}
public native_is_afk(id)
{
return isAfk[id]
}
stock sqrt(num)
{
if (num > 0) return sqroot(num)
return 0
}
Вложения
-
11.8 KB Просмотры: 1