Advertisement
rockbandcheeseman

AFK

Sep 7th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.82 KB | None | 0 0
  1. -- AFK 1.01
  2.  
  3. afk_time = 45  -- Time in seconds before a player is considered to be AFK (used for the function isafk).
  4. afk_warn_time = 240  -- Time in seconds before a player is warned that they will be kicked for being AFK (use nil to disable).
  5. afk_kick_time = 300  -- Time in seconds before a player should be kicked for being AFK (use nil to disable).
  6.  
  7. if afk_warn_time then
  8.     afk_warn_message = "**Warning**: You will be kicked in " .. afk_kick_time - afk_warn_time .. " seconds for being AFK!"
  9. end
  10.  
  11. if afk_kick_time then
  12.     afk_kick_message = " has been kicked for being AFK."  -- Player's name will be concatenated to the beginning of this string.
  13. end
  14.  
  15. afk = {}
  16.  
  17. function GetRequiredVersion()
  18.  
  19.     return 200
  20. end
  21.  
  22. function OnScriptLoad(processId, game, persistent)
  23.  
  24.    
  25. end
  26.  
  27. --[[
  28. function OnScriptUnload()
  29.  
  30.  
  31. end
  32. --]]
  33.  
  34. --[[
  35. function OnNewGame(map)
  36.  
  37.  
  38. end
  39. --]]
  40.  
  41. --[[
  42. function OnGameEnd(stage)
  43.  
  44.  
  45. end
  46. --]]
  47.  
  48. function OnServerChat(player, type, message)
  49.    
  50.     if player and type < 4 then
  51.         afk[player].time = -1
  52.         afk[player].boolean = false
  53.     end
  54. end
  55.  
  56. --[[
  57. function OnServerCommandAttempt(player, command, password)
  58.  
  59.     --return true
  60. end
  61. --]]
  62.  
  63. --[[
  64. function OnServerCommand(admin, command)
  65.  
  66.     --return true
  67. end
  68. --]]
  69.  
  70. --[[
  71. function OnNameRequest(hash, name)
  72.  
  73.     --return true, name
  74. end
  75. --]]
  76.  
  77. --[[
  78. function OnBanCheck(hash, ip)
  79.    
  80.     --return true
  81. end
  82. --]]
  83.  
  84. function OnPlayerJoin(player)
  85.  
  86.     afk[player] = {}   
  87.     afk[player].orientation = {}
  88.     afk[player].response = true
  89.     afk[player].time = 0
  90.     afk[player].boolean = false
  91.     afk[player].timerid = registertimer(1000, "AFKTimer", player)
  92. end
  93.  
  94. function AFKTimer(id, count, player)
  95.  
  96.     local m_player = getplayer(player)
  97.     if m_player then
  98.         local objId = readdword(m_player, 0x34)
  99.         local m_object = getobject(objId)
  100.         if m_object then
  101.             local x_aim = readfloat(m_object, 0x230)
  102.             local y_aim = readfloat(m_object, 0x234)
  103.             local z_aim = readfloat(m_object, 0x238)
  104.             local bool = true
  105.            
  106.             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
  107.                 local walking = readbyte(m_object, 0x4D2)
  108.                 if walking == 0 then
  109.                     bool = false
  110.                 end
  111.             end
  112.            
  113.             afk[player].orientation.x = x_aim
  114.             afk[player].orientation.y = y_aim
  115.             afk[player].orientation.z = z_aim
  116.             afk[player].response = bool
  117.            
  118.             if afk[player].response == false then
  119.                 afk[player].time = afk[player].time + 1
  120.             else
  121.                 afk[player].time = 0
  122.             end
  123.        
  124.             if afk[player].time == 0 then
  125.                 afk[player].boolean = false
  126.             elseif afk[player].time == afk_time then
  127.                 afk[player].boolean = true
  128.             elseif afk[player].time == afk_warn_time then
  129.                 privatesay(player, afk_warn_message, false)
  130.             elseif afk[player].time == afk_kick_time then
  131.                 say(getname(player) .. afk_kick_message, false)
  132.                 svcmd("sv_kick " .. resolveplayer(player))
  133.             end
  134.         else
  135.             afk[player].orientation.x = nil
  136.             afk[player].orientation.y = nil
  137.             afk[player].orientation.z = nil
  138.         end
  139.     end
  140.    
  141.     return true
  142. end
  143.  
  144. function OnPlayerLeave(player)
  145.  
  146.     removetimer(afk[player].timerid)
  147.     afk[player] = nil
  148. end
  149.  
  150. --[[
  151. function OnPlayerKill(killer, victim, mode)
  152.  
  153.     -- mode 0: Killed by server
  154.     -- mode 1: Killed by fall damage
  155.     -- mode 2: Killed by guardians
  156.     -- mode 3: Killed by vehicle
  157.     -- mode 4: Killed by killer
  158.     -- mode 5: Betrayed by killer
  159.     -- mode 6: Suicide
  160. end
  161. --]]
  162.  
  163. --[[
  164. function OnKillMultiplier(player, multiplier)
  165.  
  166.     -- Multipliers:
  167.     -- 7: Double Kill
  168.     -- 9: Triple Kill
  169.     -- 10: Killtacular
  170.     -- 11: Killing Spree
  171.     -- 12: Running Riot
  172.     -- 16: Double Kill w/ Score
  173.     -- 17: Triple Kill w/ Score
  174.     -- 14: Killtacular w/ Score
  175.     -- 18: Killing Spree w/ Score
  176.     -- 17: Running Riot w/ Score
  177. end
  178. --]]
  179.  
  180. --[[
  181. function OnPlayerSpawn(player)
  182.    
  183.  
  184. end
  185. --]]
  186.  
  187. --[[
  188. function OnPlayerSpawnEnd(player)
  189.  
  190.    
  191. end
  192. --]]
  193.  
  194. --[[
  195. function OnWeaponAssignment(player, objId, slot, weapId)
  196.    
  197.     --return mapId
  198. end
  199. --]]
  200.  
  201. function OnWeaponReload(player, weapId)
  202.  
  203.     afk[player].time = -1
  204.     afk[player].boolean = false
  205. end
  206.  
  207. function OnObjectCreationAttempt(mapId, parentId, player)
  208.    
  209.     if player then
  210.         local tagname, tagtype = gettaginfo(mapId)
  211.         if tagtype == "proj" then
  212.             if afk[player] then
  213.                 afk[player].time = -1
  214.                 afk[player].boolean = false
  215.             end
  216.         end
  217.     end
  218. end
  219.  
  220. --[[
  221. function OnObjectCreation(objId)
  222.  
  223.  
  224. end
  225. --]]
  226.  
  227. --[[
  228. function OnObjectInteraction(player, objId, mapId)
  229.  
  230.  
  231. end
  232. --]]
  233.  
  234. --[[
  235. function OnTeamDecision(team)
  236.    
  237.     --return team
  238. end
  239. --]]
  240.  
  241. --[[
  242. function OnTeamChange(player, old_team, new_team, voluntary)
  243.    
  244.     --return true
  245. end
  246. --]]
  247.  
  248. --[[
  249. function OnDamageLookup(receiver, causer, mapId)
  250.    
  251.     --return true
  252. end
  253. --]]
  254.  
  255. --[[
  256. function OnDamageApplication(receiver, causer, mapId, location, backtap)
  257.    
  258.     --return true
  259. end
  260. --]]
  261.  
  262. function OnVehicleEntry(player, vehiId, seat, mapId, voluntary)
  263.    
  264.     afk[player].time = -1
  265.     afk[player].boolean = false
  266. end
  267.  
  268. function OnVehicleEject(player, voluntary)
  269.  
  270.     afk[player].time = -1
  271.     afk[player].boolean = false
  272. end
  273.  
  274. function OnClientUpdate(player)
  275.  
  276.     local m_player = getplayer(player)
  277.     if m_player then
  278.         local objId = readdword(m_player, 0x34)
  279.         local m_object = getobject(objId)
  280.         if m_object then
  281.             local melee_key = readbit(m_object, 0x208, 0)
  282.             local action_key = readbit(m_object, 0x208, 1)
  283.             local flashlight_key = readbit(m_object, 0x208, 3)
  284.             local jump_key = readbit(m_object, 0x208, 6)
  285.             local crouch_key = readbit(m_object, 0x208, 7)
  286.             local right_mouse = readbit(m_object, 0x209, 3)
  287.             if melee_key or action_key or flashlight_key or jump_key or crouch_key or right_mouse then
  288.                 afk[player].time = -1
  289.                 afk[player].boolean = false
  290.             end
  291.         end
  292.     end
  293. end
  294.  
  295. function isafk(player)
  296.  
  297.     if player then
  298.         if afk[player] then
  299.             return afk[player].boolean
  300.         end
  301.     end
  302. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement