AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   [L4D2]AFK Manager Modification / Help Requests (https://forums.alliedmods.net/showthread.php?t=331813)

Darkwob 04-08-2021 15:40

[L4D2]AFK Manager Modification / Help Requests
 
Hey guys

This plugin says that players switch to the spectator team when they are inactive for a certain period of time, but the thing is that the player does not go to the spectator team. Also, when we write an !idle to the chat, we do not switch to the spectator team. Can anyone help edit this plugin?

PHP Code:

#pragma semicolon 1
#pragma newdecls required

#include <sourcemod>
#include <sdktools>

#define PLUGIN_VERSION "1.4"

public Plugin myinfo = {
    
name "[L4D(2)] AFK Manager",
    
author "Matthias Vance",
    
description "",
    
version PLUGIN_VERSION,
    
url "http://www.matthiasvance.com/"
};

float advertiseInterval 300.0;
Handle advertiseTimer null;

float specTime[MAXPLAYERS 1];
float afkTime[MAXPLAYERS 1];

float checkInterval 10.0;
float maxAfkSpecTime 40.0;
float maxAfkKickTime 480.0;
float joinTeamInterval 60.0;
float timeLeftInterval 5.0;

float lastMessage[MAXPLAYERS 1];

float clientPos[MAXPLAYERS 1][3];
float clientAngles[MAXPLAYERS 1][3];

int messageLevel 3;
int iTimeAfk;

public 
void OnPluginStart() 
{
    
CreateConVar("l4d_afkmanager_version"PLUGIN_VERSION"[L4D(2)] AFK Manager"FCVAR_SPONLY|FCVAR_NOTIFY|FCVAR_DONTRECORD);
    
SetConVarString(FindConVar("l4d_afkmanager_version"), PLUGIN_VERSION);

    
char temp[12];
    
    
FloatToString(advertiseIntervaltempsizeof(temp)); (CreateConVar("afk_adinterval"temp"Interval in which the plugin will advertise the 'idle' command.")).AddChangeHook(convar_AdvertiseTime);
    
FloatToString(maxAfkSpecTimetempsizeof(temp)); (CreateConVar("afk_spectime"temp"AFK time after which you will be moved to the Spectator team.")).AddChangeHook(convar_AfkSpecTime);
    
FloatToString(maxAfkKickTimetempsizeof(temp)); (CreateConVar("afk_kicktime"temp"AFK time after which you will be kicked.")).AddChangeHook(convar_AfkKickTime);
    (
CreateConVar("afk_messages""3""Control spec/kick messages. (0 = disable, 1 = spec, 2 = kick, 3 = spec + kick")).AddChangeHook(convar_Messages);
    
FloatToString(joinTeamIntervaltempsizeof(temp)); (CreateConVar("afk_joinmsg_time"temp)).AddChangeHook(convar_JoinMsgTime);
    
FloatToString(timeLeftIntervaltempsizeof(temp)); (CreateConVar("afk_warning_time"temp)).AddChangeHook(convar_WarningTime);

    
HookEvent("player_team"Event_PlayerTeam);
    
HookEvent("round_end"Event_RoundEndEventHookMode_PostNoCopy);
    
    
CreateTimer(1.0MapStart);
    
advertiseTimer CreateTimer(advertiseIntervaltimer_Advertise_TIMER_REPEAT);
    
CreateTimer(checkIntervaltimer_Check_TIMER_REPEAT);

    
//AutoExecConfig(true, "l4d_afkmanager");
}

public 
Action MapStart(Handle timer)
{
    
OnMapStart();
}

public 
void OnMapStart()
{
    
iTimeAfk GetTime();
}

public 
void convar_JoinMsgTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
    
joinTeamInterval StringToFloat(newValue);
}

public 
void convar_WarningTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
    
timeLeftInterval StringToFloat(newValue);
}

public 
void convar_Messages(ConVar convar, const char[] oldValue, const char[] newValue)
{
    if (
messageLevel <= 0)
    {
        
convar.SetInt(0);
        return;
    }
    if (
messageLevel >= 3)
    {
        
convar.SetInt(3);
        return;
    }
    
messageLevel convar.IntValue;
}

public 
Action timer_Check(Handle timer
{
    
float currentPos[3];
    
float currentAngles[3];

    
int team;
    
bool isAFK;
    
int clientindex;

    for (
client 1client <= MaxClientsclient++) 
    {
        if (
IsClientInGame(client) && !IsFakeClient(client)) 
        {
            
team GetClientTeam(client);
            if (
team == 1
            {
                
specTime[client] += checkInterval;
                if (
specTime[client] >= maxAfkKickTime
                {
                    
                    if (
GetRealClientCount() > 25)
                    {
                        
                        if (!
IsVip(client))
                        {
                            
KickClient(client"You were AFK for too long.");
                            if (
messageLevel >= 2)
                                
PrintToChatAll("\x04[\x05AFK Manager\x04]\x01 Player \x04'%N'\x01 was kicked."client);
                        }
                    }
                    
                    if (
GetClientCount(false) >= 30 && !IsRoot(client))
                    {
                        
KickClient(client"You were AFK for too long.");
                        if (
messageLevel >= 2)
                            
PrintToChatAll("\x04[\x05AFK Manager\x04]\x01 Player \x04'%N'\x01 was kicked."client);
                    }
                    else
                        
specTime[client] = (specTime[client] - checkInterval 1);
                } 
                else 
                {
                    if (
GetClientTime(client) - lastMessage[client] >= timeLeftInterval
                    {
                        if (!
IsRoot(client))
                            
PrintToChat(client"\x04[\x05AFK Manager\x04]\x01 You can spectate for \x04%d\x01 more seconds before you will be kicked."RoundToFloor(maxAfkKickTime specTime[client]));
                        
lastMessage[client] = GetClientTime(client);
                    }
                    if (
GetClientTime(client) - lastMessage[client] >= joinTeamInterval
                    {
                        if (!
IsRoot(client))
                            
PrintToChat(client"\x04[\x05AFK Manager\x04]\x01 Say \x05!join\x01 to join game.");
                        
lastMessage[client] = GetClientTime(client);
                    }
                }
            } 
            else if (
IsPlayerAlive(client) && (team == || team == 3)) 
            {
                
GetClientAbsOrigin(clientcurrentPos);
                
GetClientAbsAngles(clientcurrentAngles);

                
isAFK true;
                for (
index 0index 3index++) 
                {
                    if(
currentPos[index] != clientPos[client][index]) 
                    {
                        
isAFK false;
                        break;
                    }
                }
                if (
isAFK
                {
                    for(
index 0index 3index++) 
                    {
                        if(
currentAngles[index] != clientAngles[client][index]) 
                        {
                            
isAFK false;
                            break;
                        }
                    }
                }
                if (
isAFK
                {
                    
afkTime[client] += checkInterval;
                    if (
afkTime[client] >= maxAfkSpecTime
                    {
                        if (
GetClientCount(false) >= 30)
                        {
                            
KickClient(client"Sorry, no open slots for spectators.");
                            if (
messageLevel >= 2)
                                
PrintToChatAll("\x04[\x05AFK Manager\x04]\x01 Player \x04'%N'\x01 was kicked. No open slots for spectators."client);
                        }
                        else
                            
ClientAFK(client);
                    }
                } 
                else 
                    
afkTime[client] = 0.0;

                for (
index 0index 3index++) 
                {
                    
clientPos[client][index] = currentPos[index];
                    
clientAngles[client][index] = currentAngles[index];
                }
            }
        }
    }
    return 
Plugin_Continue;
}

void ClientAFK(int client)
{
    if (!
IsClientInGame(client))
        return;
    if (
IsFakeClient(client))
        return;
    if (
GetClientTeam(client) == 1)
        return;
    
    
float fAFK GetRandomFloat(0.15.1);
    
CreateTimer(fAFKTimer_Afkclient);
}

public 
Action Timer_Afk(Handle timerany client)
{
    if (
IsClientInGame(client))
    {
        if (!
IsFakeClient(client))
        {
            if (
GetClientTeam(client) != 1)
            {
                
int afktime = (GetTime() - iTimeAfk);
                if (
afktime 50)
                    
afkTime[client] = (afkTime[client] - (checkInterval 1.0));
                else
                {
                    if (
GetClientCount(false) >= 30)
                    {
                        
KickClient(client"Sorry, no open slots for spectators.");
                        if (
messageLevel >= 2)
                            
PrintToChatAll("\x04[\x05AFK Manager\x04]\x01 Player \x04'%N'\x01 was kicked. No open slots for spectators."client);
                        return 
Plugin_Stop;
                    }
                    
                    if (
messageLevel == || messageLevel == 3)
                        
PrintToChatAll("\x04[\x05AFK Manager\x04]\x01 Player \x04'%N'\x01 was moved to Spectator team."client);
                    
PrintToServer("[AFK Manager] Player '%N' was moved to Spectator team."client);
                    
ServerCommand("sm_switchplayer2 #%d 1"GetClientUserId(client));
                    
iTimeAfk GetTime();
                }
            }
        }
    }
    return 
Plugin_Stop;
}

int GetRealClientCount()
{
    
int clients 0;
    for (
int i 1<= MaxClientsi++)
    {
        if (
IsClientInGame(i))
        {
            if (!
IsFakeClient(i))
                
clients++;
        }
    }
    return 
clients;
}

public 
void convar_AfkSpecTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
    
maxAfkSpecTime StringToFloat(newValue);
    if (
maxAfkSpecTime == 0.0 || maxAfkSpecTime <= 30.0)
    {
        
convar.SetFloat(30.0);
        return;
    }
}

public 
void convar_AfkKickTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
    
maxAfkKickTime StringToFloat(newValue);
    if (
maxAfkKickTime == 0.0 || maxAfkKickTime <= 60.0)
    {
        
convar.SetFloat(60.0);
        return;
    }
}

public 
Action Event_PlayerTeam(Event event, const char[] namebool dontBroadcast)
{
    
int client GetClientOfUserId(event.GetInt("userid"));
    
int team GetEventInt(event"team");
    switch(
team)
    {
        case 
1specTime[client] = 0.0;
        case 
23afkTime[client] = 0.0;
    }
    if (
event.GetBool("disconnected"))
    {
        
clientPos[client] = view_as<float>({0.00.00.0});
        
clientAngles[client] = view_as<float>({0.00.00.0});
    }
}

public 
void convar_AdvertiseTime(ConVar convar, const char[] oldValue, const char[] newValue)
{
    if (
advertiseTimer != null)
    {
        
KillTimer(advertiseTimer);
        
advertiseTimer null;
    }
    
advertiseInterval StringToFloat(newValue);
    if (
advertiseInterval <= 10.0)
    {
        
convar.SetFloat(10.0);
        return;
    }
    if (
advertiseInterval 0.0)
        
advertiseTimer CreateTimer(advertiseIntervaltimer_Advertise_TIMER_REPEAT);
}

public 
Action timer_Advertise(Handle timer
{
    
PrintToChatAll("\x04[\x05AFK Manager\x04]\x01 Use \x05!idle \x01if you plan to go AFK for a while.");
    return 
Plugin_Continue;
}

bool IsRoot(int client)
{
    
AdminId admin GetUserAdmin(client);

    if (
admin == INVALID_ADMIN_ID)
        return 
false;
    if (
GetAdminFlag(adminAdmin_Root) || GetAdminFlag(adminAdmin_Password))
        return 
true;
    
    return 
true;
}

bool IsVip(int client)
{
    
AdminId admin GetUserAdmin(client);

    if (
admin == INVALID_ADMIN_ID)
        return 
false;
    if (
GetAdminFlag(adminAdmin_Reservation))
        return 
true;
    return 
true;
}

public 
Action Event_RoundEnd(Event event, const char[] namebool dontBroadcast)
{
    
int i 1;
    while (
<= MaxClients)
    {
        if (
IsClientInGame(i))
        {
            
afkTime[i] = 0.0;
        }
        
+= 1;
    }



Darkwob 04-10-2021 11:27

Re: [L4D2]AFK Manager Modification / Help Requests
 
isn't there an author who can fix these problems ?

Psyk0tik 04-10-2021 11:57

Re: [L4D2]AFK Manager Modification / Help Requests
 
Bro, it’s only been two days. You can’t expect live support from other users. Remember that you are the one asking others to grant your request so you need to have more patience.

Darkwob 04-10-2021 13:35

Re: [L4D2]AFK Manager Modification / Help Requests
 
Quote:

Originally Posted by Crasher_3637 (Post 2743676)
Bro, it’s only been two days. You can’t expect live support from other users. Remember that you are the one asking others to grant your request so you need to have more patience.

bro, there is no afk system that I can use on the server, which causes many players to wait on the server afk. and you know that with slots. and other players cannot join the server. I'm sorry I didn't know. but I wish I could know what caused the problem.

HarryPotter 04-13-2021 07:40

Re: [L4D2]AFK Manager Modification / Help Requests
 
1. this plugin doesn't force a player to change team to spectator
(ServerCommand sm_switchplayer2 does not exist)

2. this plugins doesn't even provide a command like !idle to switch team

3. since your purpose is to make players switch to the spectator team when they are inactive for a certain period of time, how about you try this one I made
https://forums.alliedmods.net/showpo...6&postcount=98

Darkwob 04-16-2021 03:38

Re: [L4D2]AFK Manager Modification / Help Requests
 
Quote:

Originally Posted by HarryPotter (Post 2743977)
1. this plugin doesn't force a player to change team to spectator
(ServerCommand sm_switchplayer2 does not exist)

2. this plugins doesn't even provide a command like !idle to switch team

3. since your purpose is to make players switch to the spectator team when they are inactive for a certain period of time, how about you try this one I made
https://forums.alliedmods.net/showpo...6&postcount=98

Thank God I finally got an answer. I gave up hope on this topic. Thank you bro for your reply, your plugin is fine, but this plugin I hope to be fixed works more logically on my server. If you can fix bugs in this plugin, I would appreciate it. Cuz it does not exhibit a stable run.

Darkwob 05-08-2021 13:27

Re: [L4D2]AFK Manager Modification / Help Requests
 
Isn't there someone who can find a solution to the problem I got in the afk manager plugin, whose source codes I have given above?

paulo_crash 05-08-2021 15:19

Re: [L4D2]AFK Manager Modification / Help Requests
 
I believe that this meets all your needs: https://forums.alliedmods.net/showthread.php?t=79904

notyouraverage 05-09-2021 16:21

Re: [L4D2]AFK Manager Modification / Help Requests
 
1 Attachment(s)
try if it works. also !idle command added.

Darkwob 05-11-2021 20:41

Re: [L4D2]AFK Manager Modification / Help Requests
 
Quote:

Originally Posted by notyouraverage (Post 2746387)
try if it works. also !idle command added.

Thank you for your help. but there is a problem like this. When a player writes !idle it does not give an print. normally the player was supposed to send a message to the spectator team that he had passed. But otherwise, when the player remains stationary, he can switch to the spectator team. Thank you for this correction, he also gives a printout on the chat screen that he has passed to the spectator team.

notyouraverage 05-12-2021 09:08

Re: [L4D2]AFK Manager Modification / Help Requests
 
1 Attachment(s)
Quote:

Originally Posted by Darkwob (Post 2746577)
Thank you for your help. but there is a problem like this. When a player writes !idle it does not give an print. normally the player was supposed to send a message to the spectator team that he had passed. But otherwise, when the player remains stationary, he can switch to the spectator team. Thank you for this correction, he also gives a printout on the chat screen that he has passed to the spectator team.

done. have fun :up:

Darkwob 05-14-2021 16:35

Re: [L4D2]AFK Manager Modification / Help Requests
 
Quote:

Originally Posted by notyouraverage (Post 2746615)
done. have fun :up:

Thank you very much, I will get back to you after testing it.

Darkwob 05-17-2021 06:24

Re: [L4D2]AFK Manager Modification / Help Requests
 
Quote:

Originally Posted by notyouraverage (Post 2746615)
done. have fun :up:

Hi bro, the plugin is working successfully. but I realized there was a problem like this. Once a player was afk he would normally give a countdown message, no longer show him. can you solve this problem too?


PHP Code:

                        if (!IsRoot(client))
                            
PrintToChat(client"\x04[\x05AFK Manager\x04]\x01 You can spectate for \x04%d\x01 more seconds before you will be kicked."RoundToFloor(maxAfkKickTime specTime[client]));
                        
lastMessage[client] = GetClientTime(client);
                    }
                    if (
GetClientTime(client) - lastMessage[client] >= joinTeamInterval
                    {
                        if (!
IsRoot(client))
                            
PrintToChat(client"\x04[\x05AFK Manager\x04]\x01 Say \x05!join\x01 to join game.");
                        
lastMessage[client] = GetClientTime(client);
                    }
                } 

Also, can you prevent Survivor Da dead players from passing the spectator team by typing !Idle? Finally, I noticed one thing that a lot of players go to the spectator team using the command !idle in order not to die. Can you add a countdown to prevent this? After 15 seconds, he can make it to the audience team. Can you print it as a printhinttext?

like this
PHP Code:

PrinHinttext("After x seconds you will be afk"



All times are GMT -4. The time now is 17:12.

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