Raised This Month: $51 Target: $400
 12% 

[Any] Stand Alone AFK Check


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Fearts
ferts of daeth
Join Date: Oct 2008
Old 12-29-2014 , 16:34   [Any] Stand Alone AFK Check
Reply With Quote #1

Should be pretty easy to make. Basically a admin with the b flag can type into chat !afkcheck. This opens a menu on all non-admins on the server. The menu looks like this:

Are you AFK?

1. No


Anyone who presses 1 for No isn't AFK. Anyone who hasn't pressed 1 after X seconds is kicked from the server with the message: You were kicked for being AFK.
__________________
Fearts is offline
Darkness_
Veteran Member
Join Date: Nov 2014
Old 12-29-2014 , 18:08   Re: [Any] Stand Alone AFK Check
Reply With Quote #2

Didn't test so I can't guarantee results.

PHP Code:
#include <sourcemod>
#include <cstrike>

new Handle:g_AFKTimer[MAXPLAYERS 1] = INVALID_HANDLE;
new 
Handle:g_hResponseTime INVALID_HANDLE;

public 
Plugin:myinfo =
{
    
name "AFK Check",
    
author "Darkness",
    
description "Lets Admins do an AFK Check on all non-admins.",
    
version "1.00",
    
url "https://forums.alliedmods.net/showthread.php?t=253862"
}

public 
OnPluginStart()
{
    
RegAdminCmd("sm_afkcheck"Command_AFKCheckADMFLAG_GENERIC);
    
g_hResponseTime CreateConVar("afk_responsetime""10.0""Amount of time players have to respond to the afk check.");
}

public 
Action:Command_AFKCheck(clientargs)
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsValidClient(i))
        {
            if (!
CheckCommandAccess(i"sm_afkcheck"ADMFLAG_GENERIC))
            {
                
ShowAFKMenu(i);
            }
        }
    }
    
ReplyToCommand(client"[SM] Sent out an AFK check to all non-admins.");
    return 
Plugin_Handled;
}

ShowAFKMenu(client)
{
    if (
IsValidClient(client))
    {
        new 
Handle:MenuHandle CreateMenu(AFKCheckMenu);
        
SetMenuTitle(MenuHandle"Are you AFK? \n");
        
AddMenuItem(MenuHandle"no""No");
        
DisplayMenu(MenuHandleclient0);
        if (
g_AFKTimer[client] != INVALID_HANDLE)
        {
            
KillTimer(g_AFKTimer[client]);
            
g_AFKTimer[client] = CreateTimer(GetConVarFloat(g_hResponseTime), KickPlayerclient);
        }
        if (
g_AFKTimer[client] == INVALID_HANDLE)
        {
            
g_AFKTimer[client] = CreateTimer(GetConVarFloat(g_hResponseTime), KickPlayerclient);
        }
    }
}

public 
AFKCheckMenu(Handle:menuMenuAction:actionclientoption)
{
    if (
action == MenuAction_Select)
    {
        new 
String:info[4];
        
GetMenuItem(menuoptioninfosizeof(info));
        if (
StrEqual(info"no"false))
        {
            if (
g_AFKTimer[client] != INVALID_HANDLE)
            {
                
KillTimer(g_AFKTimer[client]);
                
g_AFKTimer[client] = INVALID_HANDLE;
            }
            
PrintToChat(client"[SM] You have successfully responded to the AFK Check.");
        }
    }
    if (
action == MenuAction_End)
    {
        
CloseHandle(menu);
    }
}

public 
Action:KickPlayer(Handle:timerany:client)
{
    if (
IsValidClient(client))
    {
        
KickClient(client"Failed to respond to AFK Check");
    }
    
g_AFKTimer[client] = INVALID_HANDLE;
}

public 
OnMapEnd()
{
    for (new 
1<= MaxClientsi++)
    {
        if (
IsValidClient(i))
        {
            if (
g_AFKTimer[i] != INVALID_HANDLE)
            {
                
KillTimer(g_AFKTimer[i]);
                
g_AFKTimer[i] = INVALID_HANDLE;
            }
        }
    }
}

public 
OnClientDisconnect(client)
{
    if (
g_AFKTimer[client] != INVALID_HANDLE)
    {
        
KillTimer(g_AFKTimer[client]);
        
g_AFKTimer[client] = INVALID_HANDLE;
    }
}

stock bool:IsValidClient(client)
{
    if (
client || client MaxClients)
    {
        return 
false;
    }
    if (!
IsClientConnected(client))
    {
        return 
false;
    }
    if (!
IsClientInGame(client))
    {
        return 
false;
    }
    
    return 
true;


Last edited by Darkness_; 12-29-2014 at 18:17.
Darkness_ is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 12-29-2014 , 18:24   Re: [Any] Stand Alone AFK Check
Reply With Quote #3

Quote:
Originally Posted by Darkness_ View Post
Didn't test so I can't guarantee results.
Cleaned it up a bit.

Code:
#include <sourcemod> 

new Handle:g_AFKTimer[MAXPLAYERS + 1] = {INVALID_HANDLE, ...}; 
new Handle:g_hResponseTime; 

public Plugin:myinfo = 
{ 
	name = "AFK Check", 
	author = "Darkness, fixed by Keith Warren (Drixevel)", 
	description = "Lets Admins do an AFK Check on all non-admins.", 
	version = "1.00", 
	url = "https://forums.alliedmods.net/showthread.php?t=253862" 
} 

public OnPluginStart() 
{ 
	RegAdminCmd("sm_afkcheck", Command_AFKCheck, ADMFLAG_GENERIC); 
	g_hResponseTime = CreateConVar("afk_responsetime", "10.0", "Amount of time players have to respond to the afk check.", FCVAR_NOTIFY, true, 1.0); 
} 

public Action:Command_AFKCheck(client, args) 
{ 
	for (new i = 1; i <= MaxClients; i++) 
	{ 
		if (!IsClientInGame(i) || IsFakeClient(i) || CheckCommandAccess(i, "sm_afkcheck", ADMFLAG_GENERIC)) continue;
		ShowAFKMenu(i); 
	} 
	ReplyToCommand(client, "[SM] Sent out an AFK check to all non-admins."); 
	return Plugin_Handled; 
} 

ShowAFKMenu(client) 
{ 
	if (!IsClientInGame(client)) return;
	
	new Handle:MenuHandle = CreateMenu(AFKCheckMenu); 
	SetMenuTitle(MenuHandle, "Are you AFK? \n"); 
	AddMenuItem(MenuHandle, "no", "No"); 
	DisplayMenu(MenuHandle, client, 0); 
	if (g_AFKTimer[client] != INVALID_HANDLE) 
	{ 
		KillTimer(g_AFKTimer[client]); 
		g_AFKTimer[client] = CreateTimer(GetConVarFloat(g_hResponseTime), MoveToSpectate, client); 
	} 
	if (g_AFKTimer[client] == INVALID_HANDLE) 
	{ 
		g_AFKTimer[client] = CreateTimer(GetConVarFloat(g_hResponseTime), MoveToSpectate, client); 
	} 
} 

public AFKCheckMenu(Handle:menu, MenuAction:action, client, option) 
{
	switch (action)
	{
	case MenuAction_Select:
		{
			new String:info[4]; 
			GetMenuItem(menu, option, info, sizeof(info)); 
			if (StrEqual(info, "no", false)) 
			{ 
				if (g_AFKTimer[client] != INVALID_HANDLE) 
				{ 
					KillTimer(g_AFKTimer[client]); 
					g_AFKTimer[client] = INVALID_HANDLE; 
				} 
				PrintToChat(client, "[SM] You have successfully responded to the AFK Check."); 
			} 
		}
	case MenuAction_End: CloseHandle(menu);
	}
} 

public Action:MoveToSpectate(Handle:timer, any:client) 
{
	g_AFKTimer[client] = INVALID_HANDLE; 
	if (IsClientInGame(client)) 
	{ 
		KickClient(client, "Failed to respond to AFK Check"); 
	} 
} 

public OnMapEnd() 
{ 
	for (new i = 1; i <= MaxClients; i++) 
	{ 
		if (!IsClientInGame(i) || IsFakeClient(i)) continue;
		
		if (g_AFKTimer[i] != INVALID_HANDLE) 
		{ 
			KillTimer(g_AFKTimer[i]); 
			g_AFKTimer[i] = INVALID_HANDLE; 
		} 
	} 
} 

public OnClientDisconnect(client) 
{ 
	if (g_AFKTimer[client] != INVALID_HANDLE) 
	{ 
		KillTimer(g_AFKTimer[client]); 
		g_AFKTimer[client] = INVALID_HANDLE; 
	} 
}

Last edited by Drixevel; 12-30-2014 at 19:10.
Drixevel is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 12-29-2014 , 18:26   Re: [Any] Stand Alone AFK Check
Reply With Quote #4

You should add a yes option that kills them in some amusing manner.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 12-30-2014 , 17:55   Re: [Any] Stand Alone AFK Check
Reply With Quote #5

Quote:
Originally Posted by r3dw3r3w0lf View Post
... FVAR_NOTIFY ...
Change to:
FCVAR_NOTIFY

Last edited by Mitchell; 12-30-2014 at 17:56.
Mitchell is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 12-30-2014 , 19:10   Re: [Any] Stand Alone AFK Check
Reply With Quote #6

Quote:
Originally Posted by Mitchell View Post
Change to:
FCVAR_NOTIFY
Mistype.
Drixevel is offline
Fearts
ferts of daeth
Join Date: Oct 2008
Old 01-01-2015 , 00:54   Re: [Any] Stand Alone AFK Check
Reply With Quote #7

Thanks guys.
__________________
Fearts is offline
Phaiz
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-01-2015 , 20:10   Re: [Any] Stand Alone AFK Check
Reply With Quote #8

Could it be changed to something other than 1? 4 would be a good option so it doesn't interfere with people who are playing
__________________
Phaiz is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-01-2015 , 20:23   Re: [Any] Stand Alone AFK Check
Reply With Quote #9

Quote:
Originally Posted by Phaiz View Post
Could it be changed to something other than 1? 4 would be a good option so it doesn't interfere with people who are playing
Any menu is going to interfere.
You would have to use nativevotes to oush options to the f keys to fix that.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Phaiz
AlliedModders Donor
Join Date: Feb 2014
Location: USA
Old 01-01-2015 , 20:26   Re: [Any] Stand Alone AFK Check
Reply With Quote #10

Quote:
Originally Posted by friagram View Post
Any menu is going to interfere.
You would have to use nativevotes to oush options to the f keys to fix that.
I disagree. Most players use keys 1, 2 and 3 for primary, secondary and melee weapons respectively. What if they are unable to press 1 for "No" because they are fighting or some other reason? Having it set to something other than 1 2 or 3 causes next to zero interference.
__________________
Phaiz is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 05:25.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode