Русское сообщество по скриптингу

[Help] Afk Manager

Scripting help for english speaking users. While not very active, you still have a chance to get help here.
Правила форума
We cannot maintain english version version of our forum rules, but shortly (it's simple) - Don't be a dick. If you really want to know our rules you should check appropriate thread.

[Help] Afk Manager

Сообщение VenomIvanof » 01 июн 2016, 10:47

How can i add a text when the player say /afk and he get black screen. I want to add text on the black screen, and when the player say /back the text will be removed
P.S. I tryed to make it but i think it should make with a task .. but i dont understand ...
here is the code

Код: Выделить всё
#include <amxmodx>
#include <fun>
#include <fakemeta>
#include <colorchat>
#include <Vexd_Utilities>

#define VERSION "2.0"

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, afk_announce

new isAfk[33]
new g_SayText
new sync

new gPlayerPosition[33][3]  // keeps track of last known origin
new gMoveTimer[33]          // incremented if player didn't move far enough

enum _:playerTasks ( += 33 )
{
   TASK_PLAYER_REMOVE_TEXT
}

public plugin_init() {
   register_plugin("AFK Protection", VERSION, "rapara13")
   register_cvar("afk_protection", VERSION, FCVAR_SERVER|FCVAR_SPONLY)
   
   register_clcmd("say /afk","afk")
   register_clcmd("say_team /afk","afk")
   register_clcmd("say /back","back")
   register_clcmd("say_team /back","back")
   sync = CreateHudSyncObj()
   
   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", "280")
   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","0")
   afk_transparent_amount = register_cvar("afk_transparent_amount","120")
   
   afk_icon = register_cvar("afk_icon","0")
   afk_blind = register_cvar("afk_blind","1")
   afk_announce = register_cvar("afk_annouce","20")
   
   g_SayText = get_user_msgid("SayText")
   
   if(get_pcvar_num(afk_protection_auto))
      set_task(1.0,"campcheck",0,"",0,"b" )
}



public client_putinserver(id) {
   set_task(get_pcvar_float(afk_announce), "announce", id)
}

public announce(id)
{
   ColorChat(id, GREY, "^4[^3Maina City^4] ^3Write ^4/afk ^3to be in ^4AFK Mode")
}

public client_connect(id) {
   isAfk[id] = false
}

public client_disconnect(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_pev(players[i],pev_flags,pev(players[i],pev_flags) | FL_FROZEN)
         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], 999999);
         }
      }
      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)
         
      set_pev(id,pev_flags,pev(id,pev_flags) | FL_FROZEN)
      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(255)
         message_end()
      }
         
      if(get_pcvar_num(afk_icon)) {
         add_icon(id, 999999);
      }
         
      ColorChat(id, GREY, "^4[^3Maina City^4] ^3You are in ^4AFK Mode^3! To remove ^4AFK Mode ^3write ^4/back")
      set_hudmessage(255, 0, 0, 0.40, 0.50, 0, 6.0, 7.0)
      ShowSyncHudMsg(id, sync, "You are AFK now. Write /back to Play again! ^n When you write /back the message will dissapear after 5 sec ^n Have a nice play in our server!")
      isAfk[id] = true
   } else {
      ColorChat(id, GREY, "^4[^3Maina City^4] ^3You can't use it when you dead")
   }
}

public back(id) {
   if(!get_pcvar_num(afk_protection))
      return
      
   if(!isAfk[id])
      return
      
   if(is_user_alive(id)) {
      set_pev(id,pev_flags,pev(id,pev_flags) & ~FL_FROZEN)
      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);
      }
      
      ColorChat(id, GREY, "^4[^3Maina City^4] ^3You remove AFK Mode")
      isAfk[id] = false
   } else {
      ColorChat(id, GREY, "^4[^3Maina City^4] ^3You cant use it when you are ^4dead!")
   }
}

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

      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
      }
      gPlayerPosition[i][0] = origin[0]
      gPlayerPosition[i][1] = origin[1]
      gPlayerPosition[i][2] = origin[2]
   }
}

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

stock add_icon(index, HoldTime)
{
   if(!is_user_connected(index))
      return;
   
   message_begin(MSG_ALL, SVC_TEMPENTITY);
   write_byte(TE_PLAYERATTACHMENT);
   write_byte(index);
   write_coord(60);
   write_short(HoldTime);
   message_end();
}

stock remove_icon(index)
{
   if(!is_user_connected(index))
      return;
   
   message_begin(MSG_ALL, SVC_TEMPENTITY)
   write_byte(TE_KILLPLAYERATTACHMENTS);
   write_byte(index);
   message_end();
}

stock sqrt(num)
{
   if (num > 0)   return sqroot(num)
   return 0
}
Аватара пользователя
VenomIvanof
 
Сообщения: 62
Зарегистрирован: 02 апр 2016, 13:26
Благодарил (а): 17 раз.
Поблагодарили: 1 раз.
Языки программирования: Counter-Strike 1.6

Re: [Help] Afk Manager

Сообщение Pafos » 01 июн 2016, 13:28

VenomIvanof,
Код: Выделить всё

new g_iMsgScreenFade
;

public plugin_init()
{
    g_iMsgScreenFade = get_user_msgid("ScreenFade");
}

ScreenFade(nClientIndex, bool:bStatus = false)
{
    message_begin(MSG_ONE, g_iMsgScreenFade, _, nClientIndex);
    write_short(1<<0); // Duration
    write_short(1<<0); // Hold time
    write_short(bStatus ? 1<<: 1<<0); // Fade type
    write_byte(0); // Red
    write_byte(0); // Green
    write_byte(0); // Blue
    write_byte(bStatus ? 255 : 0); // Alpha
    message_end();
}


used so
Код: Выделить всё

public back
(id) {
//....
ScreenFade(id, false)
//.....

Код: Выделить всё

public afk
(id) {
//....
ScreenFade(id, true)
//.....
У меня есть код , который почти всегда работает, но не ясно , что он делает :crazy:

Аватара пользователя
Pafos
 
Сообщения: 495
Зарегистрирован: 07 апр 2014, 18:03
Откуда: pfnClientConnect
Предупреждения: 1
Благодарил (а): 114 раз.
Поблагодарили: 87 раз.
Опыт программирования: Около года
Языки программирования: Pawn

Re: [Help] Afk Manager

Сообщение VenomIvanof » 01 июн 2016, 13:44

Pafos писал(а):VenomIvanof,
Код: Выделить всё

new g_iMsgScreenFade
;

public plugin_init()
{
    g_iMsgScreenFade = get_user_msgid("ScreenFade");
}

ScreenFade(nClientIndex, bool:bStatus = false)
{
    message_begin(MSG_ONE, g_iMsgScreenFade, _, nClientIndex);
    write_short(1<<0); // Duration
    write_short(1<<0); // Hold time
    write_short(bStatus ? 1<<: 1<<0); // Fade type
    write_byte(0); // Red
    write_byte(0); // Green
    write_byte(0); // Blue
    write_byte(bStatus ? 255 : 0); // Alpha
    message_end();
}


used so
Код: Выделить всё

public back
(id) {
//....
ScreenFade(id, false)
//.....

Код: Выделить всё

public afk
(id) {
//....
ScreenFade(id, true)
//.....


so it will be like this?

public afk(id) {
set_hudmessage(25, 255, 255, 0.3, 0.3, 0, 6.0, 12.0)
show_hudmessage(id, "text")
ScreenFade(id, true)

and

public back(id) {
set_hudmessage(25, 255, 255, 0.3, 0.3, 0, 6.0, 12.0)
show_hudmessage(id, "text")
ScreenFade(id, false)
Аватара пользователя
VenomIvanof
 
Сообщения: 62
Зарегистрирован: 02 апр 2016, 13:26
Благодарил (а): 17 раз.
Поблагодарили: 1 раз.
Языки программирования: Counter-Strike 1.6


Вернуться в Scripting

Кто сейчас на конференции

Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 1