Advertisement
Guest User

Untitled

a guest
May 12th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* AMX Mod X
  2. *   Full Server Idler Kicker (+last AFK to Spec)
  3. *
  4. * (c) Copyright 2006 by VEN
  5. *
  6. * This file is provided as is (no warranties)
  7. *
  8. *     DESCRIPTION
  9. *       The concept of this plugin is "don't clean the full server from idlers unless
  10. *       new connection try". By idlers i mean HLTV/unassigned/spectator/AFK users.
  11. *       I created this plugin because i don't like the goal of all other plugins that
  12. *       deal with idelrs using the conditions which is strictly based on the idle time.
  13. *       This plugin isn't using the idle time as primary condition. So how it work?
  14. *       Let's say the new user is trying to connect to the full server. Normally he
  15. *       would be kicked unless he have a slot reservation access, but this plugin
  16. *       able to clean the slot for this user if it will find the idler on the server.
  17. *       Firstly it will try to find and kick HLTV (this can be disabled). Secondly -
  18. *       the most idle unassigned/spectator user. Though the plugin will never kick
  19. *       a client with immunity access (this can be configured) or the user who is just
  20. *       connected and still unassigned - it will "immune" him for a few seconds
  21. *       (this can be configured). And lastly the plugin will try to find and kick
  22. *       the most idle alive AFK player (min. idle time that required to mark a player
  23. *       as AFK can be configured). Also as a bonus feature the plugin able to detect
  24. *       when all alive players in the same team are AFK. Usually it would be just
  25. *       a single AFK player who is the only one alive player in a team. In this case
  26. *       to avoid waiting/seaching AFK player(s) by other player(s) the plugin will move
  27. *       him/them to the spectators. Later such AFK users can be kicked from Spectators
  28. *       following the steeps that listed above. Requirement for full server kicker are
  29. *       at least one free reserverved slot (controlled by amx_reservation AMXX's CVAR).
  30. */
  31.  
  32. #include <amxmodx>
  33.  
  34. #define PLUGIN_NAME "Full Server Idler Kicker MOD 4norbert"
  35. #define PLUGIN_VERSION "0.1/hujow.sto"
  36. #define PLUGIN_AUTHOR "VEN->karce"
  37.  
  38. // OPTIONS BELOW
  39.  
  40. // comment to disable access check on kick
  41. #define IMMUNE_SPEC_ACCESS ADMIN_RESERVATION
  42.  
  43. // time after spec can be KICKED...
  44. #define IMMUNE_SPEC_TIME 120
  45.  
  46. // connected user's unassigned kick immunity time
  47. #define IMMUNE_TIME_AFTER_CONNECT 5
  48.  
  49. // AFK check interval (seconds)
  50. #define AFK_CHECK_INTERVAL 5
  51.  
  52. // max. allowed AFK time (seconds)
  53. #define MAX_ALLOWED_AFK_TIME 110
  54.  
  55. // comment to disable HLTV kick
  56. //#define HLTV_KICK
  57.  
  58. #if defined HLTV_KICK
  59.     new const g_hltv_kick_reason[] = "Sorry, HLTV isn't allowed on the full server"
  60. #endif
  61.  
  62. // kick reasons
  63. new const g_spec_kick_reason[] = "Niestety, siedzenie na SPEC jest niedozwolone na pelnym serwerze."
  64. //new const g_afk_kick_reason[]  = "Zostales wyrzucony za brak aktywnosci na pelnym serwerze"
  65.  
  66. // AFK to Spectators transfer reason
  67. new const g_afktospec_reason[] = "\yZostales przeniesiony na SPEC\nz powodu braku aktywnosci"
  68.  
  69. // chat reasons
  70. //new const g_spec_kick_chat[] = "[AMXX] %s zostal wyrzucony za brak aktywnosci na pelnym serwerze."
  71. //new const g_afk_kick_chat[]  = "[AMXX] %s zostal wyrzucony za brak aktywnosci na pelnym serwerze."
  72. new const g_afktospec_chat[] = "[AMXX] %s zostal przeniesiony na SPEC za brak aktywnosci."
  73.  
  74. // OPTIONS ABOVE
  75.  
  76. new const g_teamname[2][] = {"TERRORIST", "CT"}
  77.  
  78. #define MAX_PLAYERS 32
  79. new bool:g_connected[MAX_PLAYERS + 1]
  80. new g_origin[MAX_PLAYERS + 1][3]
  81. new g_afktime[MAX_PLAYERS + 1]
  82. new g_specgametime[MAX_PLAYERS + 1]
  83.  
  84. new g_maxplayers
  85. new g_pcvar_reservation
  86.  
  87. public plugin_init() {
  88.     register_plugin(PLUGIN_NAME, PLUGIN_VERSION, PLUGIN_AUTHOR)
  89.  
  90.     register_event("TeamInfo", "event_spectate", "a", "2=UNASSIGNED", "2=SPECTATOR")
  91.     register_event("TeamInfo", "event_playteam", "a", "2=TERRORIST", "2=CT")
  92.  
  93.     g_maxplayers = get_maxplayers()
  94.     g_pcvar_reservation = get_cvar_pointer("amx_reservation")
  95.  
  96.     set_task(float(AFK_CHECK_INTERVAL), "task_afk_check", _, _, _, "b")
  97. }
  98.  
  99. public client_connect(id) {
  100.     g_connected[id] = true
  101.  
  102.     if (get_playersnum(1) <= g_maxplayers - get_pcvar_num(g_pcvar_reservation))
  103.         return
  104.  
  105. #if defined HLTV_KICK
  106.     if (is_user_hltv(id)) {
  107.         client_kick(id, g_hltv_kick_reason)
  108.         return
  109.     }
  110. #endif
  111.  
  112.     static players[32], num, i, tchar[2]
  113.     new candidate, candidatetime
  114.     get_players(players, num, "b")
  115.     for (new x; x < num; ++x) {
  116.         i = players[x]
  117.  
  118. #if defined IMMUNE_SPEC_ACCESS
  119.         if (get_user_flags(i) & IMMUNE_SPEC_ACCESS)
  120.             continue
  121. #endif
  122.  
  123.         if (is_user_hltv(i)) {
  124. #if defined HLTV_KICK
  125.             client_kick(i, g_hltv_kick_reason)
  126.             return
  127. #else
  128.             continue
  129. #endif
  130.         }
  131.  
  132.         get_user_team(i, tchar, 1)
  133.         if (((tchar[0] == 'U' && get_user_time(i, 1) > IMMUNE_TIME_AFTER_CONNECT) || tchar[0] == 'S') && (!candidatetime || g_specgametime[i] < candidatetime)) {
  134.             candidatetime = g_specgametime[i]
  135.             candidate = i
  136.         }
  137.     }
  138.  
  139.     if (candidate && (floatround(get_gametime()) - g_specgametime[id]) > IMMUNE_SPEC_TIME ) {
  140.         //chat_msg(candidate, g_spec_kick_chat)
  141.         client_kick(candidate, g_spec_kick_reason)
  142.         return
  143.     }
  144.  
  145.     // static origin[3], afktime
  146.     // get_players(players, num, "a")
  147.     // for (new x; x < num; ++x) {
  148.         // i = players[x]
  149.         // get_user_origin(i, origin)
  150.         // if (!is_user_afk(i, origin)) {
  151.             // g_afktime[i] = 0
  152.             // g_origin[i] = origin
  153.             // continue
  154.         // }
  155.  
  156.         // afktime = g_afktime[i]
  157.         // if (afktime >= MAX_ALLOWED_AFK_TIME && afktime > candidatetime) {
  158.             // candidatetime = afktime
  159.             // candidate = i
  160.         // }
  161.     // }
  162.  
  163.     // if (candidate) {
  164.         // chat_msg(candidate, g_afk_kick_chat)
  165.         // client_kick(candidate, g_afk_kick_reason)
  166.     // }
  167.  
  168. }
  169.  
  170. public task_afk_check() {
  171.     static players[32], num, i, bool:allafk, origin[3]
  172.     for (new a; a < 2; ++a) {
  173.         get_players(players, num, "ae", g_teamname[a])
  174.         allafk = true
  175.         for (new x; x < num; ++x) {
  176.             i = players[x]
  177.             get_user_origin(i, origin)
  178.             if (is_user_afk(i, origin)) {
  179.                 g_afktime[i] += AFK_CHECK_INTERVAL
  180.                 if (g_afktime[i] < MAX_ALLOWED_AFK_TIME)
  181.                     allafk = false
  182.             }
  183.             else {
  184.                 g_afktime[i] = 0
  185.                 g_origin[i] = origin
  186.                 allafk = false
  187.             }
  188.         }
  189.  
  190.         if (!allafk)
  191.             continue
  192.  
  193.         for (new x; x < num; ++x) {
  194.             i = players[x]
  195.             chat_msg(i, g_afktospec_chat)
  196.             user_to_spec(i, g_afktospec_reason)
  197.         }
  198.     }
  199. }
  200.  
  201. public event_spectate() {
  202.     new id = read_data(1)
  203.     if (g_connected[id] && !g_specgametime[id])
  204.         g_specgametime[id] = floatround(get_gametime())
  205. }
  206.  
  207. public event_playteam() {
  208.     new id = read_data(1)
  209.     if (g_connected[id])
  210.         clear_vars(id)
  211. }
  212.  
  213. public client_disconnect(id) {
  214.     g_connected[id] = false
  215.     clear_vars(id)
  216. }
  217.  
  218. clear_vars(id) {
  219.     g_origin[id][0] = 0
  220.     g_origin[id][1] = 0
  221.     g_origin[id][2] = 0
  222.     g_afktime[id] = 0
  223.     g_specgametime[id] = 0
  224. }
  225.  
  226. bool:is_user_afk(id, const origin[3]) {
  227.     return (origin[0] == g_origin[id][0] && origin[1] == g_origin[id][1])
  228. }
  229.  
  230. chat_msg(id, const text[]) {
  231.     static name[32]
  232.     get_user_name(id, name, 31)
  233.     client_print(0, print_chat, text, name)
  234. }
  235.  
  236. stock client_kick(id, const reason[] = "") {
  237.     server_cmd("kick #%d ^"%s^"", get_user_userid(id), reason)
  238.     server_exec()
  239. }
  240.  
  241. stock user_to_spec(id, const reason[] = "") {
  242.     user_kill(id, 1)
  243.     engclient_cmd(id, "jointeam", "6")
  244.     show_menu(id, 1023, reason)
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement