LUA 252
V2+ Ultimate Ping Kicker v3 By xdedeone on 25th February 2019 09:43:00 PM
  1. --[[ ### Ping Kick Script v3 ###]]--
  2. --[[ ###     by Wizard     ###]]--
  3. --[[ ###    for Phasor v2    ###]]--
  4. --[[ ###  other thanks below ###]]--
  5.  
  6. --This script measures time in seconds, and 'ping updates'
  7. --Ping updates are when the player gets a new ping (or has his ping 'updated') on the F1 menu, which usually happens every 3 seconds.
  8.  
  9. max_ping = 365 -- Max Ping: edit as needed
  10. max_players_before_kick = 12 -- start pingkicking when the server has this many players.
  11. omg_ping = 700 -- unless their ping is at this many ms.
  12. pingkick_timeout = 45 -- After this many seconds any player warned of high ping will be forgotten. - edit as needed
  13. pingupdate_fix_time = 4 -- A player must have a ping lower than the max_ping/omg_ping for this many ping updates to be forgiven.
  14. pingupdate_warn_time = 4 -- A player must have a ping higher than the max_ping/omg_ping for this many ping updates to trigger a warning.
  15.  
  16.  
  17. --don't edit:
  18. pingwarned = {} -- Table of players who have been warned for high ping
  19. playerRemoved = {}
  20. currentplayers = 0
  21. in_grace = {}
  22. warncount = {}
  23. gracecount = {}
  24.  
  25. function GetRequiredVersion()
  26.         return 200
  27. end
  28.  
  29. function OnScriptLoad(process, game, persistent)
  30.  
  31. end
  32.  
  33. function OnNewGame(map)
  34.  
  35.         pingwarned = {}
  36.         pingtimer = registertimer(3000, "pingkickTimer") -- check all players pings every second
  37. end
  38.  
  39. function pingkickTimer(id, count)
  40.         for i = 0,15 do
  41.                 if not playerRemoved[i] then
  42.                         local m_player = getplayer(i)
  43.                         if m_player then
  44.                                 local player_ping = readword(m_player + 0xDC)
  45.                                 local pingcheck = highPingCheck(player_ping)
  46.                                 --Check if player has been warned.
  47.                                 if not pingwarned[i] then
  48.                                         --Check if we should start the warn counter
  49.                                         if pingcheck then
  50.                                                 if not warncount[i] then warncount[i] = 0 end
  51.                                                 warncount[i] = warncount[i] + 1
  52.                                                 if warncount[i] == pingupdate_warn_time then
  53.                                                         pingwarned[i] = true
  54.                                                         privatesay(i, string.format("WARNING: Your Ping: %s ms. You will be kicked if your ping is over %s ms.", player_ping, pingcheck))
  55.                                                         local time, units = timeUnit(pingkick_timeout)
  56.                                                         privatesay(i, string.format("You have %s %s to solve it before being kicked.", time, units))
  57.                                                 end
  58.                                         else
  59.                                                 warncount[i] = 0
  60.                                         end
  61.                                 else
  62.                                         --need some way to determine if player failed to meet grace time.
  63.                                         if in_grace[i] == "nope" then
  64.                                                 if pingcheck then
  65.                                                         say(getname(i) .. " was kicked for having a ping over " .. pingcheck .. "ms.")
  66.                                                 else
  67.                                                         say(getname(i) .. " was kicked for having a ping over " .. max_ping .. "ms.")
  68.                                                 end
  69.                                                 svcmd("sv_kick " .. resolveplayer(i))
  70.                                                 playerRemoved[i] = true
  71.                                                 in_grace[i] = nil
  72.                                         --if not nil then person has pingkick_timeout to lower their ping.
  73.                                         elseif in_grace[i] then
  74.                                                 if not pingcheck then
  75.                                                         if not gracecount[i] then gracecount[i] = 0 end
  76.                                                         gracecount[i] = gracecount[i] + 1
  77.                                                         if gracecount[i] >= pingupdate_fix_time then
  78.                                                                 removetimer(in_grace[i])
  79.                                                                 in_grace[i] = nil
  80.                                                                 pingwarned[i] = nil
  81.                                                         end
  82.                                                 else
  83.                                                         gracecount[i] = 0
  84.                                                 end
  85.                                         elseif not in_grace[i] then
  86.                                                 in_grace[i] = registertimer(pingkick_timeout * 1000, "pingTimeout", i)
  87.                                         end
  88.                                 end
  89.                         end
  90.                 end
  91.         end
  92.         return true
  93. end
  94.  
  95. function timeUnit(seconds)
  96.         local minutes = seconds / 60
  97.         if minutes == math.floor(minutes) then
  98.                 --really hate programs that never change to singular...
  99.                 if minutes == 1 then
  100.                         return minutes, "minute"
  101.                 end
  102.                 return minutes, "minutes"
  103.         end
  104.         --really hate programs that never change to singular...
  105.         if minutes == 1 then
  106.                 return seconds, "second"
  107.         end
  108.         return minutes, "seconds"
  109. end
  110.  
  111. --without this function if statements would be too long
  112. function highPingCheck(ping)
  113.         if ping > max_ping and currentplayers >= max_players_before_kick then
  114.                 return max_ping
  115.         elseif ping >= omg_ping then
  116.                 return omg_ping
  117.         end
  118.         return false
  119. end
  120.  
  121. function pingTimeout(id, count, player)  --re-evaluate warn or kick
  122.         pingwarned[player] = nil
  123.         in_grace[player] = "nope"
  124.         return false
  125. end
  126.  
  127. function OnPlayerJoin(player)
  128.         currentplayers = currentplayers + 1
  129. end
  130.  
  131. function OnPlayerLeave(player)
  132.         pingwarned[player] = nil
  133.         playerRemoved[player] = nil
  134.         currentplayers = currentplayers - 1
  135. end
  136.  
  137. -- Thanks to H® Shaft for the original script.
  138. -- Also thanks to H® BugZ, Oxide, Elite Prime, Nugget & many others for their contributions to Phasor and the Halo Community
  139. -- 365 is high limit for UK connecting to US server, 333 is too low and will kick even though UK player is not warping nor having packet loss (lag)
  140. -- for regional ping limits (client to host) that is stable such as Chicago to New York a good high is 250 which means UK players would get warned/kicked quickly

HaloNet.Net is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.