This script (for GMod10) was completely reworked from the ground up, but it was based on the original idea by Megiddo.(for GMod9)
The idea behind this script is that after a certain time of not moving, you will be flagged as afk. If you continue to be afk, you will be kicked from the server.
This is an addon. Extract it to your Garrysmod/addons folder.
This REQUIRES ULib to be installed to use. ULIB can be downloaded from http://ulyssesmod.net. If you use ULX admin mod, you already have ULib.~Features~
Ability to change time with console command aafk_time <integer>
Ability to disable the script with aafk_enabled <1/0>
Ability to allow admins immunity to kick with aafk_adminimmune <1/0>
Ability to allow the kicking function to not happen with aafk_kickenabled<1/0>
Ability to shift between allowing afk players to stay on the server and kicking them depending on how full the server is with aafk_kicknumber<integer>
ChangeLog:
v1.0
-Release
v1.10
-Hooks and Timers are client side now, the client checks its own angles instead of the server checking every players angle
-Added in name change support. Whan a player goes afk, their name changes to <AFK>Name and back when they return.
-Added functions to have the client and server side of the script communicate properly with each other.
v1.20
-went partially back to serverside. It was possible to use lua_run_cl to mess up the checks and circumvent the system. Now it is not =)
-Fixed other various bugs.
v1.30
-Simply fixed a bug in 1.2 that was causing the settings not to load correctly.
v2.00
-Major Release
-Added a new variable, aafk_kicknumber will set the server to only kick AFk clients if there are more clients connected to the server than you have the number set to. If there are fewer, it will not kick them.
-Added Names over afk players heads.
-Typing !afk will now flag yourself as afk. Not advised if kick is enabled for you =)
-Chatting as well as view angle will prevent being flagged as afk. Chatting will now bring you out of afk as well.
-Changed: In the notification, if kick is disabled, it will no longer tell the player he/she will be kicked.
v2.1
-Changed some things to make it work with the new Gmod.
v2.2
-Added Access String in the adminimmunity checks. This allows you to give additional groups/users immunity on the fly. See the topic below for how to use.
Immunity Access String Usage.
If you are running ULX (this addon REQUIRES ULib) you can do the following to give an user immunity to the kick if aafk_adminimmunity is on.
ulx userallow <username> "aafk_immune"
This will add the access string "aafk_immune" to their user file and will keep them from being kicked
Also you can edit your data/ULib/groups.txt file and add "aafk_immune" to any groups allow list to give everyone in the group immunity from being kicked.
Please keep in mind that all of this requires aafk_adminimmunity console variable to be set to 1 (on)
~~~~~~~
The way this script works is:
It takes the time you have set in the config (top lines of the .lua file) or if you used aafk_time to set your own in game... and every amount of seconds as defined it checks the players entity angle.. (this is basically where the mouse is pointed) and stores it into a variable for your specific client.
If it finds that you have not changed angles since the last time it checked, and you are not flagged as afk, it will flag you as afk.
If it finds that you have not moved since it last checked and you are already flagged as afk, it will kick you from the server (assuming you have kick enabled)
The default time is 150 seconds.. this allows for around 5-7 minutes of complete afk before being kicked.. depending on how soon after a check you stop moving.
Suggestions for a future version are welcome.. I will try to implement anything that seems worth implementing.
Console Commands:
aafk_enabled <1/0> - Turns aafk on or off (Default On)
aafk_time <integer> - sets the time (in seconds) on the afk check. How often the script checks angles. (Default 150 seconds.. which is 2.5 minutes)
aafk_adminimmune <1/0> - This sets whether or not admins are immune to being kicked for being afk. (Default Off)
aafk_kickenabled <1/0> - Currently no real point in this.. I plan on implimenting more features later that will make use of the player not being kicked but still being flagged as afk.. such as name changing to <afk> Name.. or putting text above their head. (Default On)
aafk_kicknumber <integer> - Setting this number will cause the script to only kick afk users if the current total of players is greater or equal to the number that you set. Good for letting afk players stay connected if the server has less than 5 players connected at the time but keeping afk players from filling slots on a full server.
All of these defaults can be changed in the top of the aafk.lua file
--Old Versions--