Advertisement
Guest User

autoafk999spec.lua

a guest
Sep 13th, 2018
167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- autoafk999spec.lua - auto-puts 999 and afk players to spectator
  2. -- inactivity code from "Player Inactivity Modification" (inacmod.lua) by hadro
  3. -- g_inactivity needs to be enabled
  4. -- it is strongly recommended to set g_inactivity at least 11 seconds higher than max_player_inactivity
  5.  
  6. checkInterval = 15000 -- interval in milliseconds to check ping (15 sec)
  7. pings = {} -- pings[clientid][15 sec interval ping]; if 3 intervals (45 sec) are all 999, player is put to spec
  8. max_player_inactivity = 120000 -- time in milliseconds before a player gets moved to spectator for being inactive (2 min)
  9.  
  10. function et_InitGame(levelTime, randomSeed, restart)
  11.     et.RegisterModname("autoafk999spec.lua "..et.FindSelf())
  12.     for i=0,tonumber(et.trap_Cvar_Get("sv_maxclients"))-1 do
  13.         pings[i] = {[1]=0, [2]=0, [3]=0}
  14.     end
  15. end
  16.  
  17. function et_RunFrame(levelTime)
  18.     if math.mod(levelTime,checkInterval) ~= 0 then return end
  19.     local matches999 = 0
  20.     local matchesafk = 0
  21.     gamestate = tonumber(et.trap_Cvar_Get("gamestate"))
  22.     if gamestate == 0 then
  23.         for i=0,tonumber(et.trap_Cvar_Get("sv_maxclients"))-1 do
  24.             local team = tonumber(et.gentity_get(i,"sess.sessionTeam"))
  25.             if team == 1 or team == 2 then
  26.                 local ping = tonumber(et.gentity_get(i,"ps.ping"))
  27.                 local inact = tonumber(et.gentity_get(i, "client.inactivityTime"))
  28.                 local g_inactivity = tonumber(et.trap_Cvar_Get("g_inactivity")) * 1000
  29.                 -- afk check
  30.                 if levelTime >= inact - (g_inactivity - max_player_inactivity) then
  31.                     matchesafk = matchesafk + 1
  32.                     et.trap_SendConsoleCommand( et.EXEC_APPEND, "ref remove " .. i .. "\n" )
  33.                 end
  34.                 -- 999 check
  35.                 if pings[i][1] == 0 then
  36.                     pings[i][1] = ping
  37.                 elseif pings[i][1] ~= 0 then
  38.                     if pings[i][2] == 0 then
  39.                         pings[i][2] = ping
  40.                     elseif pings[i][2] ~= 0 then
  41.                         pings[i][3] = ping
  42.                         if pings[i][1] >= 999 and pings[i][2] >= 999 and pings[i][3] >= 999 then
  43.                             matches999 = matches999 + 1
  44.                             et.trap_SendConsoleCommand( et.EXEC_APPEND, "ref remove " .. i .. "\n" )
  45.                         else
  46.                             pings[i][1] = 0
  47.                             pings[i][2] = 0
  48.                             pings[i][3] = 0
  49.                         end
  50.                     end
  51.                 end
  52.             end
  53.         end
  54.         if matches999 ~= 0 then
  55.             et.trap_SendConsoleCommand( et.EXEC_APPEND, "qsay ^3auto-spec999: ^7Moving ^1" ..matches999.. " ^7999 ping player(s) to spectator\n" )
  56.             matches999 = 0
  57.         end
  58.         if matchesafk ~= 0 then
  59.             et.trap_SendConsoleCommand( et.EXEC_APPEND, "qsay ^3auto-afk: ^7Moving ^1" ..matchesafk.. " ^7AFK player(s) to spectator\n" )
  60.             matchesafk = 0
  61.         end
  62.     end
  63. end
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement