MAXAFKTIME = 6*60
LastKey = {} for i=1, _MaxPlayers() do LastKey[i] = 0 end

function AFKKick()
	for i=1, _MaxPlayers() do
		if IsPlayerOnline(i) then
			if LastKey[i]+MAXAFKTIME < _CurTime() then
				if not players[i].GoldMember and not IsJetAdmin(i) then
					_ServerCommand("kickid ".._PlayerInfo(i, "networkid").." Anti-AFK Kicked\n")
				end
			elseif LastKey[i]+(MAXAFKTIME-120) < _CurTime() then
				if not players[i].GoldMember and not IsJetAdmin(i) then
					AFKWarning(i)
				end
			end
		end
	end
end
AddTimer(30, 0, AFKKick)

function UpdateAFK(userid, key)
	LastKey[userid] = _CurTime()
end
HookEvent("eventKeyPressed", UpdateAFK)

function ResetAFK(name, userid, steamid)
	LastKey[userid] = _CurTime()
end
HookEvent("eventPlayerActive", ResetAFK)

function AFKWarning(userid)
	_GModText_Start( "ImpactMassive" )
	 _GModText_SetPos( -1, 0.45 )
	 _GModText_SetColor( 255, 0, 0, 255 )
	 _GModText_SetTime( 10, 0.5, 0.5 )
	 _GModText_SetText( "Warning!\n Auto-AFK Kicker" )
	_GModText_Send( userid, 5223 )
end
