Raised This Month: $ Target: $400
 0% 

[TF2 REQ] AFK Player Tag On Scoreboard


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Tranced
Member
Join Date: Dec 2011
Location: United States
Old 01-03-2016 , 02:35   [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #1

Hello, I was just wondering if someone could make either a public or a private plugin that assigns an AFK Tag to a player who has not moved for X amount of time and then the tag gets removed when the players comes back from being AFK. I've seen quite a few CSS Plugins that do this, but none that seem to work for TF2. I looked through the sourcemod API and CS uses this format but I can't seem to find one for TF2.

PHP Code:
public Action:StatusAFK(Handle:timerany:client)
{
    
CS_SetClientClanTag(client"AFK"); 
Much help would be appreciated. Please send me a PM if you can do this or post in here. Cheers!
Tranced is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 01-03-2016 , 05:35   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #2

Actually, it's very simple. You can't do that because there is no 'tag' in TF2. I can do this script for you wait a few sec

EDIT:

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

#define PLUGIN_AUTHOR "Arkarr"
#define PLUGIN_VERSION "1.0"

float PlayerPosition[MAXPLAYERS+1][3];
float PlayerEyePosition[MAXPLAYERS+1][3];
bool AFKStat[MAXPLAYERS+1];

public 
Plugin myinfo 
{
    
name "[ANY] AFK Name",
    
author PLUGIN_AUTHOR,
    
description "Rename a player with the tag [AFK] after a certain periode of inactivity.",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
CreateTimer(5.0TMR_SavePositions_TIMER_REPEAT);
    
CreateTimer(2.0 5.0TMR_AFKCheck_TIMER_REPEAT);
}

public 
Action TMR_SavePositions(Handle tmr)
{
    for (new 
MaxClients0; --i)
    {        
        if (
IsValidClient(i))
        {
            
GetEntPropVector(iProp_Send"m_vecOrigin"PlayerPosition[i]);
            
GetClientEyePosition(iPlayerEyePosition[i]);
        }
    }
}

public 
void OnGameFrame()
{
    for (new 
MaxClients0; --i)
    {    
          if(
AFKStat[i] && !IsAfk(i))
          {
            
char clientName[45];
            
GetClientName(iclientNamesizeof(clientName));
            
ReplaceString(clientNamesizeof(clientName), "[AFK] """);
              
ServerCommand("sm_rename #%i \"%s\""GetClientUserId(i), clientName);
              
PrintToChat(i"[SM] Welcome back =D !");
              
AFKStat[i] = false;    
          }
      }
}

public 
Action TMR_AFKCheck(Handle tmr)
{
    for (new 
MaxClients0; --i)
    {        
        if (
IsValidClient(i))
        {
            if(
AFKStat[i] == false && IsAfk(i))
            {
                
char clientName[45];
                
GetClientName(iclientNamesizeof(clientName));
                  
ServerCommand("sm_rename #%i \"[AFK] %s\""GetClientUserId(i), clientName);
                  
PrintToChat(i"[SM] You are AFK and you have been tagged.");
                  
AFKStat[i] = true;
              }
        }
    }
}

stock bool IsAfk(int i)
{
    
float tmpPosition[3];
    
float tmpEyePosition[3];
    
    
GetEntPropVector(iProp_Send"m_vecOrigin"tmpPosition);
    
GetClientEyePosition(itmpEyePosition);
            
    return     (
tmpPosition[0] == PlayerPosition[i][0] && tmpPosition[1] == PlayerPosition[i][1] && tmpPosition[2] == PlayerPosition[i][2]) && (tmpEyePosition[0] == PlayerEyePosition[i][0] && tmpEyePosition[1] == PlayerEyePosition[i][1] && tmpEyePosition[2] == PlayerEyePosition[i][2])    
}

stock bool IsValidClient(iClientbool bReplay true)
{
    if (
iClient <= || iClient MaxClients)
    return 
false;
    if (!
IsClientInGame(iClient))
    return 
false;
    if (
bReplay && (IsClientSourceTV(iClient) || IsClientReplay(iClient)))
    return 
false;
    return 
true;

__________________
Want to check my plugins ?

Last edited by Arkarr; 01-03-2016 at 07:43.
Arkarr is offline
Tranced
Member
Join Date: Dec 2011
Location: United States
Old 01-03-2016 , 16:44   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #3

Will test it out now Arkarr. Thank you so much!

edit: Works like a charm! My only question is how do I adjust the time of the clients movements? Its rather quick right now for changing to the AFK tag. Is it the TMR_SavePositions, or TMR_AFKCheck? Also to perfect this plugin, could you make it so that a player has to type !afk in order for the tag to be removed?

Last edited by Tranced; 01-03-2016 at 22:53.
Tranced is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 01-04-2016 , 01:05   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #4

Quote:
Originally Posted by Tranced View Post
Will test it out now Arkarr. Thank you so much!

edit: Works like a charm! My only question is how do I adjust the time of the clients movements? Its rather quick right now for changing to the AFK tag. Is it the TMR_SavePositions, or TMR_AFKCheck? Also to perfect this plugin, could you make it so that a player has to type !afk in order for the tag to be removed?
Yeah.. I left the test value :/. Well, you can edit the two 5.0 and put it 10.0 or whatever you want OR you wait me to add Cvar and do your !afk request.
__________________
Want to check my plugins ?
Arkarr is offline
Tranced
Member
Join Date: Dec 2011
Location: United States
Old 01-04-2016 , 02:15   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #5

Ok sweet. Thank you for telling me that. I will gladly wait for that generous !afk request. There is no rush what so ever, Arkarr.

Last edited by Tranced; 01-04-2016 at 02:18.
Tranced is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 01-04-2016 , 03:46   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #6

Quote:
Originally Posted by Tranced View Post
Ok sweet. Thank you for telling me that. I will gladly wait for that generous !afk request. There is no rush what so ever, Arkarr.
Try this :
sm_afk - bring you back in game.
"sm_afkname_timer_check", "10.0", "The interval between each AFK checks."

Don't forget to donate if you would like to. (Click on the image, in my signature.)

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

#define PLUGIN_AUTHOR "Arkarr"
#define PLUGIN_VERSION "1.0"

float PlayerPosition[MAXPLAYERS+1][3];
float PlayerEyePosition[MAXPLAYERS+1][3];
bool AFKStat[MAXPLAYERS+1];

Handle CVAR_TimerAFKCheck;
Handle TIMER_SavePositions;
Handle TIMER_AFKCheck;

public 
Plugin myinfo 
{
    
name "[ANY] AFK Name",
    
author PLUGIN_AUTHOR,
    
description "Rename a player with the tag [AFK] after a certain periode of inactivity.",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
};

public 
void OnPluginStart()
{
    
RegConsoleCmd("sm_afk"CMD_AFK"Bring the player back.");
    
    
CVAR_TimerAFKCheck CreateConVar("sm_afkname_timer_check""10.0""The interval between each AFK checks.");
    
    
HookConVarChange(CVAR_TimerAFKCheckOnTimerAFKValueChange);
    
    
TIMER_SavePositions CreateTimer(GetConVarFloat(CVAR_TimerAFKCheck), TMR_SavePositions_TIMER_REPEAT);
    
TIMER_AFKCheck CreateTimer(2.0 GetConVarFloat(CVAR_TimerAFKCheck), TMR_AFKCheck_TIMER_REPEAT);
}

public 
void OnTimerAFKValueChange(ConVar convarchar[] oldValuechar[] newValue)
{
    
KillTimer(TIMER_SavePositions);
    
KillTimer(TIMER_AFKCheck);
    
    
TIMER_SavePositions CreateTimer(GetConVarFloat(CVAR_TimerAFKCheck), TMR_SavePositions_TIMER_REPEAT);
    
TIMER_AFKCheck CreateTimer(2.0 GetConVarFloat(CVAR_TimerAFKCheck), TMR_AFKCheck_TIMER_REPEAT);
}

public 
Action CMD_AFK(clientargs)
{
    if(
client == 0)
    {
        
ReplyToCommand(client"Command is game-only.");
        return 
Plugin_Handled;
    }
    
    if(
AFKStat[client] && !IsAfk(client))
      {
        
char clientName[45];
        
GetClientName(clientclientNamesizeof(clientName));
        
ReplaceString(clientNamesizeof(clientName), "[AFK] """);
          
ServerCommand("sm_rename #%i \"%s\""GetClientUserId(client), clientName);
          
PrintToChat(client"[SM] Welcome back =D !");
          
AFKStat[client] = false;    
      }
     
    return 
Plugin_Handled;
}

public 
Action TMR_SavePositions(Handle tmr)
{
    for (new 
MaxClients0; --i)
    {        
        if (
IsValidClient(i))
        {
            
GetEntPropVector(iProp_Send"m_vecOrigin"PlayerPosition[i]);
            
GetClientEyePosition(iPlayerEyePosition[i]);
        }
    }
}

public 
Action TMR_AFKCheck(Handle tmr)
{
    for (new 
MaxClients0; --i)
    {        
        if (
IsValidClient(i))
        {
            if(
AFKStat[i] == false && IsAfk(i))
            {
                
char clientName[45];
                
GetClientName(iclientNamesizeof(clientName));
                  
ServerCommand("sm_rename #%i \"[AFK] %s\""GetClientUserId(i), clientName);
                  
PrintToChat(i"[SM] You are AFK and you have been tagged.");
                  
AFKStat[i] = true;
              }
        }
    }
}

stock bool IsAfk(int i)
{
    
float tmpPosition[3];
    
float tmpEyePosition[3];
    
    
GetEntPropVector(iProp_Send"m_vecOrigin"tmpPosition);
    
GetClientEyePosition(itmpEyePosition);
            
    return     (
tmpPosition[0] == PlayerPosition[i][0] && tmpPosition[1] == PlayerPosition[i][1] && tmpPosition[2] == PlayerPosition[i][2]) && (tmpEyePosition[0] == PlayerEyePosition[i][0] && tmpEyePosition[1] == PlayerEyePosition[i][1] && tmpEyePosition[2] == PlayerEyePosition[i][2])    
}

stock bool IsValidClient(iClientbool bReplay true)
{
    if (
iClient <= || iClient MaxClients)
    return 
false;
    if (!
IsClientInGame(iClient))
    return 
false;
    if (
bReplay && (IsClientSourceTV(iClient) || IsClientReplay(iClient)))
    return 
false;
    return 
true;

__________________
Want to check my plugins ?

Last edited by Arkarr; 01-04-2016 at 03:51.
Arkarr is offline
Tranced
Member
Join Date: Dec 2011
Location: United States
Old 01-04-2016 , 04:49   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #7

The plugin works flawlessly. No errors what so ever. Donated
Tranced is offline
Arkarr
Veteran Member
Join Date: Sep 2012
Location: Just behind my PC screen
Old 01-04-2016 , 05:20   Re: [TF2 REQ] AFK Player Tag On Scoreboard
Reply With Quote #8

Quote:
Originally Posted by Tranced View Post
The plugin works flawlessly. No errors what so ever. Donated
Thanks mate !
__________________
Want to check my plugins ?
Arkarr 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 04:47.


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