LUA 337
V2+ Anti Camp 1.11 By xdedeone on 26th February 2019 04:11:58 PM
  1. -- Anti-Camping with AFK
  2. -- Idea inspired by Kennan
  3.  
  4. afk_time = 45  -- Time in seconds before a player is considered to be AFK (used for the function isafk).
  5. afk_warn_time = 240  -- Time in seconds before a player is warned that they will be kicked for being AFK (use nil to disable).
  6. afk_kick_time = 300  -- Time in seconds before a player should be kicked for being AFK (use nil to disable).
  7.  
  8. if afk_warn_time then
  9.         afk_warn_message = "**Warning**: You will be kicked in " .. afk_kick_time - afk_warn_time .. " seconds for being AFK!"
  10. end
  11.  
  12. if afk_kick_time then
  13.         afk_kick_message = " has been kicked for being AFK."  -- Player's name will be concatenated to the beginning of this string.
  14. end
  15.  
  16. afk = {}
  17.  
  18. xy_area_size = 4  -- XY size of sphere which a player must exit within area_timelimit seconds before they are considered to be camping.
  19. z_area_size = 2  -- Z size of sphere which a player must exit within area_timelimit seconds before they are considered to be camping.
  20. area_timelimit = 30  -- Amount of time in seconds a player is allowed to be within the same area before he/she is considered to be camping.
  21. camp_warning = 20  -- Amount of time in seconds before a player receives a warning that the server is about to consider them to be camping.
  22. camp_penalty = 0.1  -- Percentage of maximum health in damage done to player per second they are considered to be camping.  Use 1 to kill the player.
  23.  
  24. warning_message = "**Warning**: You will be considered to be camping in " .. area_timelimit - camp_warning .. " seconds!"
  25.  
  26. camping_message = "**Warning**: The server will now apply " .. camp_penalty * 100 .. "% damage per second while you are camping!"
  27.  
  28. function GetRequiredVersion()
  29.  
  30.         return 200
  31. end
  32.  
  33. function OnScriptLoad(processId, game, persistent)
  34.  
  35.  
  36. end
  37.  
  38. --[[
  39. function OnScriptUnload()
  40.  
  41.  
  42. end
  43. --]]
  44.  
  45. --[[
  46. function OnNewGame(map)
  47.  
  48.  
  49. end
  50. --]]
  51.  
  52. --[[
  53. function OnGameEnd(stage)
  54.  
  55.  
  56. end
  57. --]]
  58.  
  59. function OnServerChat(player, type, message)
  60.        
  61.         if player and type < 4 then
  62.                 afk[player].time = -1
  63.                 afk[player].boolean = false
  64.         end
  65. end
  66.  
  67. --[[
  68. function OnServerCommandAttempt(player, command, password)
  69.  
  70.         --return true
  71. end
  72. --]]
  73.  
  74. --[[
  75. function OnServerCommand(admin, command)
  76.  
  77.         --return true
  78. end
  79. --]]
  80.  
  81. --[[
  82. function OnNameRequest(hash, name)
  83.  
  84.         --return true, name
  85. end
  86. --]]
  87.  
  88. --[[
  89. function OnBanCheck(hash, ip)
  90.        
  91.         --return true
  92. end
  93. --]]
  94.  
  95. timers = {}
  96. location = {}
  97. camping = {}
  98.  
  99. function OnPlayerJoin(player)
  100.        
  101.         afk[player] = {}       
  102.         afk[player].orientation = {}
  103.         afk[player].response = true
  104.         afk[player].time = 0
  105.         afk[player].boolean = false
  106.         afk[player].timerid = registertimer(1000, "AFKTimer", player)
  107.  
  108.         location[player] = {}
  109.         camping[player] = false
  110.         timers[player] = registertimer(1000, "CampingTimer", player)
  111. end
  112.  
  113. function AFKTimer(id, count, player)
  114.  
  115.         local m_player = getplayer(player)
  116.         if m_player then
  117.                 local objId = readdword(m_player, 0x34)
  118.                 local m_object = getobject(objId)
  119.                 if m_object then
  120.                         local x_aim = readfloat(m_object, 0x230)
  121.                         local y_aim = readfloat(m_object, 0x234)
  122.                         local z_aim = readfloat(m_object, 0x238)
  123.                         local bool = true
  124.                        
  125.                         if x_aim == (afk[player].orientation.x or x_aim) and y_aim == (afk[player].orientation.y or y_aim) and z_aim == (afk[player].orientation.z or z_aim) then
  126.                                 local walking = readbyte(m_object, 0x4D2)
  127.                                 if walking == 0 then
  128.                                         bool = false
  129.                                 end
  130.                         end
  131.                        
  132.                         afk[player].orientation.x = x_aim
  133.                         afk[player].orientation.y = y_aim
  134.                         afk[player].orientation.z = z_aim
  135.                         afk[player].response = bool
  136.                        
  137.                         if afk[player].response == false then
  138.                                 afk[player].time = afk[player].time + 1
  139.                         else
  140.                                 afk[player].time = 0
  141.                         end
  142.                
  143.                         if afk[player].time == 0 then
  144.                                 afk[player].boolean = false
  145.                         elseif afk[player].time == afk_time then
  146.                                 afk[player].boolean = true
  147.                         elseif afk[player].time == afk_warn_time then
  148.                                 privatesay(player, afk_warn_message, false)
  149.                         elseif afk[player].time == afk_kick_time then
  150.                                 say(getname(player) .. afk_kick_message, false)
  151.                                 svcmd("sv_kick " .. resolveplayer(player))
  152.                         end
  153.                 else
  154.                         afk[player].orientation.x = nil
  155.                         afk[player].orientation.y = nil
  156.                         afk[player].orientation.z = nil
  157.                 end
  158.         end
  159.        
  160.         return true
  161. end
  162.  
  163. function CampingTimer(id, count, player)
  164.  
  165.         local m_player = getplayer(player)
  166.         if m_player then
  167.                 local objId = readdword(m_player, 0x34)
  168.                 local m_object = getobject(objId)
  169.                 if m_object then
  170.                         if not isafk(player) then
  171.                                 local x, y, z = getobjectcoords(objId)
  172.                                 location[player][count] = {x, y, z}
  173.                                 local seconds = 0
  174.                                 for i = count, count - area_timelimit, -1 do
  175.                                         if location[player][i] then
  176.                                                 local inside = inellipse(location[player][i], location[player][count])
  177.                                                 if inside then
  178.                                                         seconds = seconds + 1
  179.                                                 else
  180.                                                         for x = 1,i do
  181.                                                                 location[player][x] = nil
  182.                                                         end
  183.                                                        
  184.                                                         break
  185.                                                 end
  186.                                         else
  187.                                                 break
  188.                                         end
  189.                                 end
  190.                                
  191.                                 if seconds == camp_warning then
  192.                                         privatesay(player, warning_message, false)
  193.                                 elseif seconds == area_timelimit then
  194.                                         privatesay(player, camping_message, false)
  195.                                         camping[player] = true
  196.                                 end
  197.                                
  198.                                 if seconds >= area_timelimit then
  199.                                         -- 1 dmg = 4 / 300 health
  200.                                         local total_damage = 1 / (4 / 300)
  201.                                         local damage = camp_penalty * total_damage * 2
  202.                                         local shields = readfloat(m_object, 0xE4)
  203.                                         local health = readfloat(m_object, 0xE0)
  204.                                         if shields == 0 and health < camp_penalty then
  205.                                                 kill(player)
  206.                                         else
  207.                                                 applydmg(objId, damage)
  208.                                         end
  209.                                 else
  210.                                         camping[player] = false
  211.                                 end
  212.                         end
  213.                 end
  214.         end
  215.        
  216.         return true
  217. end
  218.  
  219. function inellipse(t1, t2)
  220.  
  221.         local x1, y1, z1 = table.unpack(t1)
  222.         local x2, y2, z2 = table.unpack(t2)
  223.        
  224.         local xdist = x2 - x1
  225.         local ydist = y2 - y1
  226.         local zdist = z2 - z1
  227.        
  228.         if zdist / 2 <= z_area_size then
  229.                 local xy_dist = math.sqrt(xdist ^ 2 + ydist ^ 2)
  230.                 if xy_dist <= xy_area_size then
  231.                         return true
  232.                 end
  233.         end
  234.        
  235.         return false
  236. end
  237.  
  238. function OnPlayerLeave(player)
  239.  
  240.         removetimer(timers[player])
  241.         location[player] = nil
  242.         camping[player] = nil
  243.        
  244.         removetimer(afk[player].timerid)
  245.         afk[player] = nil
  246. end
  247.  
  248. function OnPlayerKill(killer, victim, mode)
  249.  
  250.         if mode == 0 then
  251.                 if camping[victim] then
  252.                         say(getname(victim) .. " was killed for camping!", false)
  253.                         camping[victim] = false
  254.                         return false
  255.                 end
  256.         end
  257. end
  258.  
  259. --[[
  260. function OnKillMultiplier(player, multiplier)
  261.  
  262.         -- Multipliers:
  263.         -- 7: Double Kill
  264.         -- 9: Triple Kill
  265.         -- 10: Killtacular
  266.         -- 11: Killing Spree
  267.         -- 12: Running Riot
  268.         -- 16: Double Kill w/ Score
  269.         -- 17: Triple Kill w/ Score
  270.         -- 14: Killtacular w/ Score
  271.         -- 18: Killing Spree w/ Score
  272.         -- 17: Running Riot w/ Score
  273. end
  274. --]]
  275.  
  276. --[[
  277. function OnPlayerSpawn(player)
  278.        
  279.  
  280. end
  281. --]]
  282.  
  283. --[[
  284. function OnPlayerSpawnEnd(player)
  285.  
  286.  
  287. end
  288. --]]
  289.  
  290. --[[
  291. function OnWeaponAssignment(player, objId, slot, weapId)
  292.        
  293.         --return mapId
  294. end
  295. --]]
  296.  
  297. function OnWeaponReload(player, weapId)
  298.  
  299.         afk[player].time = -1
  300.         afk[player].boolean = false
  301. end
  302.  
  303. function OnObjectCreationAttempt(mapId, parentId, player)
  304.        
  305.         if player then
  306.                 local tagname, tagtype = gettaginfo(mapId)
  307.                 if tagtype == "proj" then
  308.                         if afk[player] then
  309.                                 afk[player].time = -1
  310.                                 afk[player].boolean = false
  311.                         end
  312.                 end
  313.         end
  314. end
  315.  
  316. --[[
  317. function OnObjectCreation(objId)
  318.  
  319.  
  320. end
  321. --]]
  322.  
  323. --[[
  324. function OnObjectInteraction(player, objId, mapId)
  325.  
  326.  
  327. end
  328. --]]
  329.  
  330. --[[
  331. function OnTeamDecision(team)
  332.        
  333.         --return team
  334. end
  335. --]]
  336.  
  337. --[[
  338. function OnTeamChange(player, old_team, new_team, voluntary)
  339.        
  340.         --return true
  341. end
  342. --]]
  343.  
  344. --[[
  345. function OnDamageLookup(receiver, causer, mapId)
  346.        
  347.         --return true
  348. end
  349. --]]
  350.  
  351. --[[
  352. function OnDamageApplication(receiver, causer, mapId, location, backtap)
  353.        
  354.         --return true
  355. end
  356. --]]
  357.  
  358. function OnVehicleEntry(player, vehiId, seat, mapId, voluntary)
  359.        
  360.         afk[player].time = -1
  361.         afk[player].boolean = false
  362. end
  363.  
  364. function OnVehicleEject(player, voluntary)
  365.  
  366.         afk[player].time = -1
  367.         afk[player].boolean = false
  368. end
  369.  
  370. function OnClientUpdate(player)
  371.  
  372.         local m_player = getplayer(player)
  373.         if m_player then
  374.                 local objId = readdword(m_player, 0x34)
  375.                 local m_object = getobject(objId)
  376.                 if m_object then
  377.                         local melee_key = readbit(m_object, 0x208, 0)
  378.                         local action_key = readbit(m_object, 0x208, 1)
  379.                         local flashlight_key = readbit(m_object, 0x208, 3)
  380.                         local jump_key = readbit(m_object, 0x208, 6)
  381.                         local crouch_key = readbit(m_object, 0x208, 7)
  382.                         local right_mouse = readbit(m_object, 0x209, 3)
  383.                         if melee_key or action_key or flashlight_key or jump_key or crouch_key or right_mouse then
  384.                                 afk[player].time = -1
  385.                                 afk[player].boolean = false
  386.                         end
  387.                 end
  388.         end
  389. end
  390.  
  391. function isafk(player)
  392.  
  393.         if player then
  394.                 if afk[player] then
  395.                         return afk[player].boolean
  396.                 end
  397.         end
  398. end

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.