AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [Any] Stand Alone AFK Check (https://forums.alliedmods.net/showthread.php?t=253862)

Fearts 12-29-2014 16:34

[Any] Stand Alone AFK Check
 
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.

Darkness_ 12-29-2014 18:08

Re: [Any] Stand Alone AFK Check
 
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;



Drixevel 12-29-2014 18:24

Re: [Any] Stand Alone AFK Check
 
Quote:

Originally Posted by Darkness_ (Post 2241655)
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;
        }
}


friagram 12-29-2014 18:26

Re: [Any] Stand Alone AFK Check
 
You should add a yes option that kills them in some amusing manner.

Mitchell 12-30-2014 17:55

Re: [Any] Stand Alone AFK Check
 
Quote:

Originally Posted by r3dw3r3w0lf (Post 2241660)
... FVAR_NOTIFY ...

Change to:
FCVAR_NOTIFY

Drixevel 12-30-2014 19:10

Re: [Any] Stand Alone AFK Check
 
Quote:

Originally Posted by Mitchell (Post 2242403)
Change to:
FCVAR_NOTIFY

Mistype.

Fearts 01-01-2015 00:54

Re: [Any] Stand Alone AFK Check
 
Thanks guys.

Phaiz 01-01-2015 20:10

Re: [Any] Stand Alone AFK Check
 
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

friagram 01-01-2015 20:23

Re: [Any] Stand Alone AFK Check
 
Quote:

Originally Posted by Phaiz (Post 2243375)
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.

Phaiz 01-01-2015 20:26

Re: [Any] Stand Alone AFK Check
 
Quote:

Originally Posted by friagram (Post 2243376)
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.


All times are GMT -4. The time now is 02:13.

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