Author Topic: AAFK V_3.1 : Anti-AFK system for Garry's Mod  (Read 67427 times)

0 Members and 1 Guest are viewing this topic.

Offline syn.

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 6
  • Lua Padawan
    • SynGaming
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #30 on: January 24, 2014, 06:10:15 PM »
Oh yeah! This is totally legit! I love syn! 
Code: [Select]
x = syn
if x == syn then
print (x .. " is so sexy!")
syn is so sexy!
that is totally kind (and legit) of you to say! xD
Lua Student

"The more you understand, the crazier you get."

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 723
  • Karma: 114
  • :)
    • My Homepage
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #31 on: January 24, 2014, 06:12:51 PM »
that is totally kind (and legit) of you to say! xD
HOW DARE YOU CONTORT MY WORDS?
THOU SHALT BE SMITTEN BY MY AMAZING POWERS OF ZAP CRACKLE SNAP!
*pulls out a battery and two ominous looking wires and smiles evily*
bw81@ulysses-forums ~ % whoami
Homepage

Offline DRKO

  • Newbie
  • *
  • Posts: 1
  • Karma: -1
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #32 on: January 28, 2014, 01:35:37 PM »
Could someone tell me of this works for those players in spectate mode? I have the problem of people logging on in spectator mode to rack up points in the pointshop, and I don't really want that. People also sometimes go into spectator mode when the server is full, taking up spots, and it would be nice if we could auto kick them based on how long they were there.

Offline syn.

  • Jr. Member
  • **
  • Posts: 56
  • Karma: 6
  • Lua Padawan
    • SynGaming
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #33 on: January 28, 2014, 02:51:57 PM »

Could someone tell me of this works for those players in spectate mode? I have the problem of people logging on in spectator mode to rack up points in the pointshop, and I don't really want that. People also sometimes go into spectator mode when the server is full, taking up spots, and it would be nice if we could auto kick them based on how long they were there.
yep works for spectators and normal players, as long as they don't move it will kick them within the time specified.
Lua Student

"The more you understand, the crazier you get."

Offline chris8778

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #34 on: February 15, 2014, 02:58:21 PM »
can someone tell me how to[ edit this script to move them to spectate instead of kicking them; when time is up?

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #35 on: February 21, 2014, 01:00:53 AM »
How are your admins defined in ULX? This only ignores players who register on IsAdmin(). So this would be: superadmin, admin, and any other group that inherits admin.

I have custom group names (on purpose so map exploits wont give people admin), how do i fix it so that my admins dont get kicked?

EDIT: I tried changing the code to "if pl:IsAdmin(customgroup)"  and i added the custom group names to "settings\users.txt" and im still getting kicked.

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 7968
  • Karma: 373
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #36 on: February 21, 2014, 02:23:21 PM »
Pal, you can't add a group check to the "IsAdmin" function - it searches for a player being part of Gmod's default "admin" group, nothing else.
You might be able to switch/addpl:IsUserGroup("customgroup") instead, which DOES take a group name.

You're thinking on preventing admin by using non-custom group names MIGHT help with ULX/other admin mods, but, once Gmod sees a player as admin or superadmin, no matter the exploit, they're going to get access to basic server admin functions inherent in Gmod itself.
The price one pays for pursuing any profession or calling is an intimate knowledge of its ugly side. - James Baldwin

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #37 on: February 22, 2014, 12:42:42 AM »
Pal, you can't add a group check to the "IsAdmin" function - it searches for a player being part of Gmod's default "admin" group, nothing else.
You might be able to switch/addpl:IsUserGroup("customgroup") instead, which DOES take a group name.


Awesome, that fixed it!  Thanks

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #38 on: March 22, 2014, 06:05:39 PM »
This doesnt work with Murder gamemode, anyone else having this problem?

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2671
  • Karma: 417
    • |G4P| Gman4President
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #39 on: March 22, 2014, 08:20:36 PM »
The three main things it detects for AFK are:

1. Player's exact location. (X,Y,Z) coordinates.
2. Player's Look angles.
3. If they've said anything in chat.

Are any of these things changed in Murder. For example, does the gamemode reset a player's position more frequently than the timer to see if they are AFK?

Offline Bytewave

  • Respected Community Member
  • Hero Member
  • *****
  • Posts: 723
  • Karma: 114
  • :)
    • My Homepage
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #40 on: March 23, 2014, 08:27:03 AM »
This doesnt work with Murder gamemode, anyone else having this problem?
Murder has its own AFK system, doesn't it?
bw81@ulysses-forums ~ % whoami
Homepage

Offline PAL-18

  • Full Member
  • ***
  • Posts: 142
  • Karma: 1
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #41 on: March 24, 2014, 11:45:44 AM »
Murder has its own AFK system, doesn't it?

It just moves them to spectator, it doesnt kick them from server.

I searched through the code for the line that controls if a player is afk (in murder) and i found this:

Quote
if !ply.HasMoved && !ply.Frozen && self.AFKMoveToSpec:GetBool() then

I'm not exactly sure how to implement it into the afk kicker though :S
« Last Edit: March 24, 2014, 11:47:16 AM by PAL-18 »

Offline chris8778

  • Newbie
  • *
  • Posts: 7
  • Karma: 0
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #42 on: April 15, 2014, 04:07:48 AM »
Hey mr president. I run a popular melonbomb server and people die to fast for this to work.  How do i disable the checking if they moved and it just checks to see if they have moved the mouse and kick them that way?  Please remember I am a complete noob.  thanks :)  If you  fix this problem I would love to donate to you if you have a link  :)

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2671
  • Karma: 417
    • |G4P| Gman4President
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #43 on: April 15, 2014, 06:03:46 AM »
Try this:

Just copy and replace the entire contents of your aafk.lua file with this.

Code: Lua
  1. CreateConVar("ulx_afk_flagminutes", 8, FCVAR_ARCHIVE, "How many minutes an player can be AFK before being flagged as AFK.")
  2. CreateConVar("ulx_afk_kickminutes", 10, FCVAR_ARCHIVE, "How many minutes an player can be AFK before being kicked.")
  3. CreateConVar("ulx_afk_ignoreadmins", 0, FCVAR_ARCHIVE, "Should we ignore AFK admins? (1=yes, 0=no).")
  4. CreateConVar("ulx_afk_kickonafk", 1, FCVAR_ARCHIVE, "Should AFK players be kicked from the server at all? (1=yes, 0=no).")
  5. CreateConVar("ulx_afk_kickonlywhenfull", 0, FCVAR_ARCHIVE, "Should the script only kick afk players when the server is full? (1=yes, 0=no).")
  6.  
  7. if SERVER then
  8.         function ulx.CheckAFK( pl )
  9.  
  10.                 if pl:IsAdmin() and GetConVarNumber( "ulx_afk_ignoreadmins" ) == 1 then
  11.                         return
  12.                 end
  13.  
  14.                 local afk_kth = GetConVarNumber( "ulx_afk_kickminutes" )
  15.  
  16.                 if not IsValid( pl ) then return end
  17.                 if not pl:IsConnected() then return end
  18.                
  19.                 if pl.lang == nil then
  20.                         pl.lang = pl:GetAngles()
  21.                         pl.afk = false
  22.                         return
  23.                 end
  24.                
  25.                 if pl.afkc == nil then
  26.                         pl.afkc = 0
  27.                 end
  28.                
  29.                 if  pl:GetAngles() == pl.lang  then
  30.                         pl.afkc = pl.afkc + 1
  31.                 else
  32.                         pl.afkc = 0
  33.                         pl.afk = false
  34.                         pl.lang = pl:GetAngles()
  35.                         return
  36.                 end
  37.                
  38.                 if pl.afkc >= GetConVarNumber( "ulx_afk_flagminutes" ) then
  39.                         if pl.afk == false then
  40.                                 pl.afk = true
  41.                                 ulx.fancyLogAdmin( pl, "#A went AFK!" )
  42.                                 ULib.tsayColor(_, Color(0,0,0,255), "[AAFK] ", team.GetColor(pl:Team()), pl:Nick(), Color(255,255,255), " went ", Color(255,0,0,255), "AFK.")
  43.                         end
  44.                 end
  45.  
  46.                 if ( pl.afkc >= afk_kth ) and ( GetConVarNumber( "ulx_afk_kickonafk" ) ) then
  47.                         if ( #player.GetAll() < game.MaxPlayers() ) and ( GetConVarNumber( "ulx_afk_kickonlywhenfull" ) == 1 ) then
  48.                                 return
  49.                         end
  50.                         ULib.kick( pl, "AFK: Exceeding the allowed AFK time!" )
  51.                 end
  52.  
  53.         end
  54.  
  55.         function ulx.AFKTimer( pl )
  56.  
  57.                 local PID = pl:SteamID64()
  58.                 pl.afkc = 0
  59.                 pl.afk = false
  60.                 pl:SetNWBool("afk", false)
  61.                 pl.lang = pl:GetAngles()
  62.                 timer.Create("ulx_afk_" .. PID, 60, 0, function() ulx.CheckAFK( pl ) end )
  63.  
  64.         end
  65.         hook.Add( "ULibLocalPlayerReady", "AFKTimer", ulx.AFKTimer )
  66.  
  67.         function ulx.ResetAFKStatus( pl )
  68.  
  69.                 if pl.lang == nil then
  70.                         pl.lang = pl:GetAngles()
  71.                         pl.afk = false
  72.                         return
  73.                 end
  74.                
  75.                 pl.afkc = 0
  76.                 pl.afk = false
  77.                 pl:SetNWBool("afk", false)
  78.                 pl.lang = pl:GetAngles()
  79.                
  80.                 ulx.fancyLogAdmin( pl, "#A returned from being AFK!" )
  81.                 ULib.tsayColor(_, Color(0,0,0,255), "[AAFK] ", team.GetColor(pl:Team()), pl:Nick(), Color(255,255,255), " returned from being ", Color(255,0,0,255), "AFK.")
  82.                
  83.         end
  84.  
  85.  
  86.         function ulx.AFKExit_Chat( pl )
  87.                 if pl.afk == false then return end
  88.                
  89.                 if not IsValid( pl ) then return end
  90.                 if not pl:IsConnected() then return end
  91.                 ulx.ResetAFKStatus( pl )
  92.                 print("1")
  93.                
  94.         end
  95.         hook.Add("PlayerSay", "AFKExit_Chat", ulx.AFKExit_Chat)
  96.        
  97.         function ulx.AFKExit_KeyPress( pl )
  98.                 if pl.afk == false then return end
  99.                
  100.                 if not IsValid( pl ) then return end
  101.                 if not pl:IsConnected() then return end
  102.                 ulx.ResetAFKStatus( pl )
  103.                 print("2")
  104.         end
  105.         hook.Add("KeyPress", "AFKExit_KeyPress", ulx.AFKExit_KeyPress)
  106.        
  107.         function ulx.AFKExit_Move( pl )
  108.                 if pl.afk == false then return end
  109.                
  110.                 if not IsValid( pl ) then return end
  111.                 if not pl:IsConnected() then return end
  112.                 ulx.ResetAFKStatus( pl )
  113.                 print("2")
  114.         end
  115.         hook.Add("PlayerFootstep", "AFKExit_Move", ulx.AFKExit_Move)
  116. end
  117.  
  118. if CLIENT then
  119.         surface.CreateFont( "SGS_HUD3", {
  120.                 font    =       "tahoma",
  121.                 size    =       14,
  122.                 weight  =       600
  123.                 }
  124.         )
  125.         local enablenames = true
  126.         local enabletitles = true
  127.         local textalign = 1
  128.         local distancemulti = 0.6
  129.        
  130.         function DrawAFKStatus()
  131.  
  132.                 local vStart = LocalPlayer():GetPos()
  133.                 local vEnd
  134.  
  135.                 for k, v in pairs(player.GetAll()) do
  136.                
  137.                         if v:GetNWBool("afk", false) == false then continue end
  138.  
  139.                         local vStart = LocalPlayer():GetPos()
  140.                         local vEnd = v:GetPos() + Vector(0,0,25)
  141.                         local trace = {}
  142.                        
  143.                         trace.start = vStart
  144.                         trace.endpos = vEnd
  145.                         local trace = util.TraceLine( trace )
  146.                        
  147.                         if trace.HitWorld then
  148.                                 local mepos = LocalPlayer():GetPos()
  149.                                 local tpos = v:GetPos()
  150.                                 local tdist = mepos:Distance(tpos)
  151.                                 if tdist <= 2000 then
  152.                                
  153.                                         local zadj = 0.03334 * tdist
  154.                                         local pos = v:GetPos() + Vector(0,0,v:OBBMaxs().z + 5 + zadj)
  155.                                         pos = pos:ToScreen()
  156.                                         draw.RoundedBoxEx( 2, pos.x - 4, pos.y - 4, 8, 8, Color(255,0,0,255), true, true, true, true )
  157.  
  158.                                 end
  159.                         else
  160.                                 local mepos = LocalPlayer():GetPos()
  161.                                 local tpos = v:GetPos()
  162.                                 local tdist = mepos:Distance(tpos)
  163.                                
  164.                                 if tdist <= 600 then
  165.                                         local zadj = 0.03334 * tdist
  166.                                         local pos = v:GetPos() + Vector(0,0,v:OBBMaxs().z + 5 + zadj)
  167.                                         pos = pos:ToScreen()
  168.                                        
  169.                                         if v != LocalPlayer() then
  170.                                                 draw.SimpleTextOutlined( "[AFK]", "SGS_HUD3", pos.x, pos.y - 8 , Color(255,0,0,255), textalign, 1,1,Color(0,0,0,255))
  171.                                                 draw.SimpleTextOutlined( v:Name(), "SGS_HUD3", pos.x, pos.y - 23 , Color(255,0,0,255), textalign, 1,1,Color(0,0,0,255))
  172.                                         end
  173.                                 elseif tdist > 600 and tdist <= 2000 then
  174.                                
  175.                                         local zadj = 0.03334 * tdist
  176.                                         local pos = v:GetPos() + Vector(0,0,v:OBBMaxs().z + 5 + zadj)
  177.                                         pos = pos:ToScreen()
  178.                                         draw.RoundedBoxEx( 2, pos.x - 4, pos.y - 4, 8, 8, Color(255,0,0,255), true, true, true, true )
  179.  
  180.                                 end
  181.                         end
  182.                 end
  183.         end
  184.         hook.Add("HUDPaint", "DrawAFKStatus", DrawAFKStatus)
  185. end
  186.  

Offline Bryantdl7

  • Jr. Member
  • **
  • Posts: 86
  • Karma: -2
Re: AAFK V_3.1 : Anti-AFK system for Garry's Mod
« Reply #44 on: April 21, 2014, 11:09:50 AM »
Anti-AFK Version 3.1

Description:
This script monitors a players movements and actions on a server to attempt to determine if they are AFK. If they are found to be AFK it will tag them as such (client-side graphical).
Optionally (enabled by default) you can have the script kick players who have been afk for a certain number of minutes.

Installation Instructions:
Unzip the ULX_AFK folder into your addons folder.
Check the ConVars below and change them from a server console to your liking.

Console Variables:
ulx_afk_flagminutes - ( Default: 8 ) - How long in minutes a player needs to have not performed an action on the server to be flagged as afk
ulx_afk_kickminutes - ( Default: 10 ) - How long in minutes a player needs to be afk before they are kicked if kicking is enabled (see below)
ulx_afk_ignoreadmins - ( Default: 0 ) - Should the script ignore admins? 1-Yes, 0-No
ulx_afk_kickonafk - ( Default: 1 ) - Should the script kick at all? 1-Yes, 0-No : If this is set to 0 then AFKs will only be shown and players will not be kicked.
ulx_afk_kickonlywhenfull - ( Default: 0 ) - If this is enabled, players will only be kicked from the server for being AFK if the server is full. 1-Yes, 0-No

ChangeLog:

V3.1
+Fixed the verbage of the log messages to make more sense.

V3.0
+Recoded from scratch
+garrysmod13 release


As always... Questions/Comments are welcome!

Could you Integrate the commands into ULX? Also, could you fix the double printing or tell me what I would need to do for my own server?
« Last Edit: April 21, 2014, 12:32:17 PM by Bryantdl7 »