LUA 178
V1+ Anti-Aimbot 1.0 By xdedeone on 26th February 2019 07:08:39 PM
  1. -- Maximum number of "snaps" before a player is given a warning.
  2. snaps_needed = 3
  3.  
  4. -- Max ping to check for aimbotters with.
  5. max_ping = 300
  6.  
  7. -- Maximum number of warnings before an action is taken on a player.
  8. warnings_needed = 3
  9.  
  10. -- Action can be kick, ban, or nil.
  11. -- After a players warnings go above the limit, the player can be kicked or banned
  12. -- which is determined here. If action is nil, then only players are notified and
  13. -- no action is taken.
  14. default_action = "ban"
  15.  
  16. -- Should the server log when a person snaps and their total warnings?
  17. -- If this is true, it will log to AimbotWarnings.log
  18. logwarnings = true
  19.  
  20. -- How long a person should be banned for if a players warnings go above the limit
  21. -- and the default action is ban.
  22. -- 0 is infinite.
  23. default_ban_time = 0
  24.  
  25. -- Should the player be notified that they have been suspected of aimbotting.
  26. notify_player = true
  27.  
  28. -- Should admins be notified that a player has been suspected of aimbotting.
  29. notify_admins = true
  30.  
  31. -- Should the server be notified that a player has been suspected of aimbotting.
  32. notify_server = true
  33.  
  34. -- The maximum angle allowed for the player to be considered snapping.
  35. -- This is to weed out the player moving the mouse quickly and sporadically.
  36. -- Lowering this angle weeds out more accidents, but will not catch the snaps
  37. -- of bots from angles larger than this. 25 degrees seems to be the default
  38. -- maximum that a bot will snap.
  39. snap_max_angle = 25
  40.  
  41. -- The minimum angle allowed for the player to be considered snapping.
  42. -- This is to weed out normal movement of the mouse.
  43. -- Increasing this angle weeds out more accidents, but will not catch the snaps
  44. -- of bots that were in close proximity to the player. 20 degrees seems to weed
  45. -- out almost all non-botters.
  46. snap_min_angle = 20
  47.  
  48. -- The maximum angle allowed for the sudden stop of the snap.
  49. -- This is to weed out normal movement of the mouse.
  50. -- Decreasing this angle weeds out more accidents of the player suddenly stopping
  51. -- movement of the mouse, but will catch fewer snaps if the botter, or the target
  52. -- being botted is moving. 0.1 degrees seems to weed out most non-botters except
  53. -- for the occasional lag that happens.
  54. snap_stop_angle = 0.1
  55.  
  56. camera_table = {}
  57. watch_table = {}
  58. snap_table = {}
  59. warning_table = {}
  60.  
  61. -------------------------------------------------
  62. -- Called when a player has been suspected of aimbotting.
  63. -- This is called before the player has been tallied for snapping.
  64. -- The return value determines if the player should be tallied.
  65. -- Returning true tallies the player, returning false doesn't.
  66. function OnAimbotDetection(player)
  67.         return true
  68. end
  69.  
  70. function GetRequiredVersion()
  71.         return 10057
  72. end
  73.  
  74. function OnScriptLoad(process)
  75.         profile_path = getprofilepath()
  76.         log_file = profile_path .. "\\logs\\AimbotWarnings.log"
  77. end
  78.  
  79. function OnScriptUnload()
  80. end
  81.  
  82. function OnNewGame(map)
  83. end
  84.  
  85. function OnGameEnd(mode)
  86. end
  87.  
  88. function OnServerChat(player, mode, msg)
  89.         return 1
  90. end
  91.  
  92. function OnServerCommand(player, cmdline)
  93.         return 1
  94. end
  95.  
  96. function OnTeamDecision(team)
  97.         return team
  98. end
  99.  
  100. function OnPlayerJoin(player, team)
  101.         snap_table[player] = 0
  102.         warning_table[player] = 0
  103. end
  104.  
  105. function OnPlayerLeave(player, team)
  106.         camera_table[player] = nil
  107.         watch_table[player] = nil
  108.         snap_table[player] = nil
  109.         warning_table[player] = nil
  110. end
  111.  
  112. function OnPlayerKill(killer, victim, mode)
  113.         camera_table[victim] = nil
  114.         watch_table[victim] = nil
  115. end
  116.  
  117. function OnKillMultiplier(player, multiplier)
  118. end
  119.  
  120. function OnPlayerSpawn(player, object)
  121. end
  122.  
  123. function OnPlayerSpawnEnd(player, object)
  124. end
  125.  
  126. function OnTeamChange(relevant, player, team, change)
  127.         return 1
  128. end
  129.  
  130. function OnClientUpdate(player, object)
  131.         local m_player = getplayer(player)
  132.  
  133.         if m_player == nil then
  134.                 return
  135.         end
  136.  
  137.         local object = readdword(m_player, 0x34)
  138.         local m_object = getobject(object)
  139.  
  140.         if m_object == nil then
  141.                 return
  142.         end
  143.  
  144.         local camera_x = readfloat(m_object, 0x230)
  145.         local camera_y = readfloat(m_object, 0x234)
  146.         local camera_z = readfloat(m_object, 0x238)
  147.  
  148.         if camera_table[player] == nil then
  149.                 camera_table[player] = {camera_x, camera_y, camera_z}
  150.  
  151.                 return
  152.         end
  153.  
  154.         local last_camera_x = camera_table[player][1]
  155.         local last_camera_y = camera_table[player][2]
  156.         local last_camera_z = camera_table[player][3]
  157.  
  158.         camera_table[player] = {camera_x, camera_y, camera_z}
  159.  
  160.         if last_camera_x == 0 and
  161.                 last_camera_y == 0 and
  162.                 last_camera_z == 0 then
  163.  
  164.                 return
  165.         end
  166.  
  167.         local movement = math.sqrt(
  168.                 (camera_x - last_camera_x) ^ 2 +
  169.                 (camera_y - last_camera_y) ^ 2 +
  170.                 (camera_z - last_camera_z) ^ 2)
  171.  
  172.         local angle = math.acos((2 - movement ^ 2) / 2)
  173.         angle = angle * 180 / math.pi
  174.  
  175.         if watch_table[player] ~= nil then
  176.                 watch_table[player] = nil
  177.  
  178.                 if angle < snap_stop_angle then
  179.                         for i = 0, 15 do
  180.                                 if IsLookingAt(player, i) then
  181.                                         if OnAimbotDetection(player) then
  182.                                                 TallyPlayer(player)
  183.  
  184.                                                 break
  185.                                         end
  186.  
  187.                                         return
  188.                                 end
  189.                         end
  190.                 end
  191.  
  192.                 return
  193.         end
  194.  
  195.         if angle > snap_min_angle and angle < snap_max_angle then
  196.                 watch_table[player] = true
  197.         end
  198. end
  199.  
  200. function OnObjectInteraction(player, object, tag_type, tag_name)
  201.         return 1
  202. end
  203.  
  204. function OnWeaponReload(player, weapon)
  205.         return 1
  206. end
  207.  
  208. function OnVehicleEntry(relevant, player, vehicle, tag_name, seat)
  209.         return 1
  210. end
  211.  
  212. function OnVehicleEject(player, forced)
  213.         return 1
  214. end
  215.  
  216. function OnDamageLookup(receiver, causer, tag_data, tag_name)
  217. end
  218.  
  219. function OnWeaponAssignment(player, object, count, tag_name)
  220.         return 0
  221. end
  222.  
  223. function OnObjectCreation(object, owner, tag_name)
  224. end
  225.  
  226. function TallyPlayer(player)
  227.         local player_ping = getping(player)
  228.         if player_ping <= max_ping then
  229.                 if getplayer(player) == nil then
  230.                         return
  231.                 end
  232.  
  233.                 if snap_table[player] == nil then
  234.                         snap_table[player] = 0
  235.                 end
  236.  
  237.                 snap_table[player] = snap_table[player] + 1
  238.  
  239.                 if snap_table[player] >= snaps_needed then
  240.                         snap_table[player] = 0
  241.  
  242.                         if warning_table[player] == nil then
  243.                                 warning_table[player] = 0
  244.                         end
  245.  
  246.                         warning_table[player] = warning_table[player] + 1
  247.  
  248.                         if warning_table[player] >= warnings_needed then
  249.                                 if default_action == "kick" then
  250.                                         svcmd("sv_kick " .. resolveplayer(player))
  251.  
  252.                                         if notify_player then
  253.                                                 privatesay(player, "You have been kicked for aimbotting.")
  254.                                         end
  255.  
  256.                                         if notify_admins then
  257.                                                 for i = 0, 15 do
  258.                                                         if i ~= player then
  259.                                                                 privatesay(i, getname(player) .. " has been kicked for aimbotting.")
  260.                                                         end
  261.                                                 end
  262.                                         end
  263.  
  264.                                         if notify_server then
  265.                                                 for i = 0, 15 do
  266.                                                         if i ~= player then
  267.                                                                 if not notify_admins and not isadmin(player) then
  268.                                                                         privatesay(i, getname(player) .. " has been kicked for aimbotting.")
  269.                                                                 end
  270.                                                         end
  271.                                                 end
  272.                                         end
  273.  
  274.                                         return
  275.                                 elseif default_action == "ban" then
  276.                                         svcmd("sv_ban " .. resolveplayer(player) .. " " .. default_ban_time)
  277.  
  278.                                         if notify_player then
  279.                                                 privatesay(player, "You have been banned for aimbotting.")
  280.                                         end
  281.  
  282.                                         if notify_admins then
  283.                                                 for i = 0, 15 do
  284.                                                         if i ~= player then
  285.                                                                 privatesay(i, getname(player) .. " has been banned for aimbotting.")
  286.                                                         end
  287.                                                 end
  288.                                         end
  289.  
  290.                                         if notify_server then
  291.                                                 for i = 0, 15 do
  292.                                                         if i ~= player then
  293.                                                                 if not notify_admins and not isadmin(player) then
  294.                                                                         privatesay(i, getname(player) .. " has been banned for aimbotting.")
  295.                                                                 end
  296.                                                         end
  297.                                                 end
  298.                                         end
  299.  
  300.                                         return
  301.                                 end
  302.                         end
  303.  
  304.                         if notify_player then
  305.                                 privatesay(player, "You have been suspected of aimbotting. This is warning number " .. warning_table[player] .. ".")
  306.  
  307.                                 if default_action == "kick" then
  308.                                         privatesay(player, "You have " .. (warnings_needed - warning_table[player]) .. " more warnings before you are kicked.")
  309.                                 elseif default_action == "ban" then
  310.                                         privatesay(player, "You have " .. (warnings_needed - warning_table[player]) .. " more warnings before you are banned.")
  311.                                 end
  312.                         end
  313.  
  314.                         if notify_admins then
  315.                                 for i = 0, 15 do
  316.                                         if i ~= player then
  317.                                                 privatesay(i, getname(player) .. " has been suspected of aimbotting. This is warning number " .. warning_table[player] .. ".")
  318.                                         end
  319.                                 end
  320.                         end
  321.  
  322.                         if notify_server then
  323.                                 for i = 0, 15 do
  324.                                         if i ~= player then
  325.                                                 if not notify_admins and not isadmin(player) then
  326.                                                         privatesay(i, getname(player) .. " has been suspected of aimbotting. This is warning number " .. warning_table[player] .. ".")
  327.                                                 end
  328.                                         end
  329.                                 end
  330.                         end
  331.                         if logwarnings then
  332.                                 local hash = gethash(player)
  333.                                 local ping = getping(player)
  334.                                 local name = getname(player)
  335.                                 local line = "%s (%s) has snapped. (ping: %s)"
  336.                                 line = string.format(line, name, hash, ping)
  337.                                 WriteLog(log_file, line)
  338.                         end
  339.                 end
  340.         end
  341. end
  342.  
  343. function WriteLog(filename, value)
  344.         local file = io.open(filename, "a")
  345.  
  346.         if file then
  347.                 local timestamp = os.date("!%m/%d/%Y %H:%M:%S")
  348.                 local line = string.format("%s\t%s\n", timestamp, tostring(value))
  349.  
  350.                 file:write(line)
  351.                 file:close()
  352.         end
  353. end
  354.  
  355. function getping(player)
  356.         local m_player = getplayer(player)
  357.  
  358.         if not m_player then
  359.                 return nil
  360.         end
  361.  
  362.         local ping = readword(m_player, 0xDC)
  363.  
  364.         return ping
  365. end
  366.  
  367. function IsLookingAt(player1, player2)
  368.         local m_player1 = getplayer(player1)
  369.         local m_player2 = getplayer(player2)
  370.  
  371.         if m_player1 == nil or m_player2 == nil then
  372.                 return
  373.         end
  374.  
  375.         local object1 = readdword(m_player1, 0x34)
  376.         local object2 = readdword(m_player2, 0x34)
  377.         local m_object1 = getobject(object1)
  378.         local m_object2 = getobject(object2)
  379.  
  380.         if m_object1 == nil or m_object2 == nil then
  381.                 return
  382.         end
  383.  
  384.         local camera_x = readfloat(m_object1, 0x230)
  385.         local camera_y = readfloat(m_object1, 0x234)
  386.         local camera_z = readfloat(m_object1, 0x238)
  387.  
  388.         local location1_x = readfloat(m_object1, 0x5C)
  389.         local location1_y = readfloat(m_object1, 0x60)
  390.         local location1_z = readfloat(m_object1, 0x64)
  391.  
  392.         local location2_x = readfloat(m_object2, 0x5C)
  393.         local location2_y = readfloat(m_object2, 0x60)
  394.         local location2_z = readfloat(m_object2, 0x64)
  395.  
  396.         local state1 = readbyte(m_object1, 0x2A7)
  397.         local state2 = readbyte(m_object2, 0x2A7)
  398.  
  399.         if state1 == 2 then
  400.                 location1_z = location1_z + 0.6
  401.         elseif state1 == 3 then
  402.                 location1_z = location1_z + 0.3
  403.         else
  404.                 return
  405.         end
  406.  
  407.         if state2 == 2 then
  408.                 location2_z = location2_z + 0.6
  409.         elseif state2 == 3 then
  410.                 location2_z = location2_z + 0.3
  411.         else
  412.                 return
  413.         end
  414.  
  415.         local radius = math.sqrt(
  416.                 (location2_x - location1_x) ^ 2 +
  417.                 (location2_y - location1_y) ^ 2 +
  418.                 (location2_z - location1_z) ^ 2)
  419.  
  420.         local local_x = location2_x - location1_x
  421.         local local_y = location2_y - location1_y
  422.         local local_z = location2_z - location1_z
  423.  
  424.         local point_x = 1 / radius * local_x
  425.         local point_y = 1 / radius * local_y
  426.         local point_z = 1 / radius * local_z
  427.  
  428.         if math.round(camera_x, 1) == math.round(point_x, 1) and
  429.                 math.round(camera_y, 1) == math.round(point_y, 1) and
  430.                 math.round(camera_z, 1) == math.round(point_z, 1) then
  431.  
  432.                 return true
  433.         end
  434.  
  435.         return false
  436. end
  437.  
  438. function math.round(number, place)
  439.         local mult = 10 ^ (place or 0)
  440.  
  441.         return math.floor(number * mult + 0.5) / mult
  442. 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.