Skip to content

Commit

Permalink
v0.0.7
Browse files Browse the repository at this point in the history
- Added SpecKickMinPlayers option in the config (minimum number of players to kick).
- Fixed SpecWarnPlayerEveryXSeconds when the value is less than the Timer interval.
  • Loading branch information
NiGHT757 committed Nov 12, 2023
1 parent 38cbe90 commit 5408592
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
21 changes: 14 additions & 7 deletions AFKManager/AFKManager.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
using CounterStrikeSharp.API;
using CounterStrikeSharp.API.Core;
using CounterStrikeSharp.API.Core.Attributes;
using CounterStrikeSharp.API.Core.Attributes.Registration;
using CounterStrikeSharp.API.Modules.Memory;
using CounterStrikeSharp.API.Modules.Utils;
using System.Net.Sockets;

namespace AFKManager;

[MinimumApiVersion(43)]
public class AFKManager : BasePlugin
{
#region definitions
public override string ModuleAuthor => "NiGHT & K4ryuu";
public override string ModuleName => "AFK Manager";
public override string ModuleVersion => "0.0.6";
public override string ModuleVersion => "0.0.7";
public static string Directory = string.Empty;
private CCSGameRules? g_GameRulesProxy = null;

// create a class that store player AbsOrigin
private class PlayerAbsOrigin
{
Expand All @@ -38,7 +41,7 @@ public override void Load(bool hotReload)
{
g_GameRulesProxy = null;
});

#region OnClientConnected
RegisterListener<Listeners.OnClientConnected>(playerSlot =>
{
Expand Down Expand Up @@ -118,7 +121,9 @@ private void AfkTimer_Callback()
return;

string sFormat = null;

// check how many players are connected on server
var players = Utilities.GetPlayers().Count;

for (int i = 1; i <= Server.MaxPlayers; i++)
{
CCSPlayerController player = Utilities.GetPlayerFromIndex(i);
Expand Down Expand Up @@ -231,7 +236,7 @@ private void AfkTimer_Callback()
}
#endregion
#region SPEC Time
if (CFG.config.SpecKickPlayerAfterXWarnings != 0 && !g_PlayerAbsOrigin[i].Whitelisted.SkipSPEC && player.TeamNum == 1)
if (CFG.config.SpecKickPlayerAfterXWarnings != 0 && players >= CFG.config.SpecKickMinPlayers && !g_PlayerAbsOrigin[i].Whitelisted.SkipSPEC && player.TeamNum == 1)
{
g_PlayerAbsOrigin[i].fAfkTime += CFG.config.Timer;

Expand Down Expand Up @@ -263,4 +268,6 @@ private void AfkTimer_Callback()
#endregion
}
}
}
}


13 changes: 10 additions & 3 deletions AFKManager/CFG.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ public void CheckConfig(string moduleDirectory)
config.Timer = 5.0f;
Console.WriteLine("AFK Manager: Timer value is invalid, setting to default value (5.0).");
}

if(config.SpecWarnPlayerEveryXSeconds < config.Timer)
{
config.SpecWarnPlayerEveryXSeconds = config.Timer;
Console.WriteLine($"AFK Manager: The value of SpecWarnPlayerEveryXSeconds is less than the value of Timer, SpecWarnPlayerEveryXSeconds will be forced to {config.Timer}");
}
}
}

Expand Down Expand Up @@ -85,10 +91,11 @@ private static void CreateAndWriteFile(string path)
ChatWarningKickMessage = "{chatprefix} You\'re{LightRed} Idle/ AFK{Default}. Move or you\'ll be kicked in {Darkred}{time}{Default} seconds.",
ChatWarningMoveMessage = "{chatprefix} You\'re{LightRed} Idle/ AFK{Default}. Move or you\'ll be moved to SPEC in {Darkred}{time}{Default} seconds.",
ChatWarningKillMessage = "{chatprefix} You\'re{LightRed} Idle/ AFK{Default}. Move or you\'ll killed in {Darkred}{time}{Default} seconds.",
SpecWarnPlayerEveryXSeconds = 20,
SpecWarnPlayerEveryXSeconds = 20.0f,
SpecKickPlayerAfterXWarnings = 5,
Warnings = 3,
Punishment = 1,
SpecKickMinPlayers = 5,
Timer = 5.0f,
Offset = 89
};
Expand Down Expand Up @@ -135,12 +142,12 @@ internal class Config

public int Warnings { get; set; }
public int Punishment { get; set; }
public int SpecWarnPlayerEveryXSeconds { get; set; }
public float SpecWarnPlayerEveryXSeconds { get; set; }
public int SpecKickPlayerAfterXWarnings { get; set; }
public int SpecKickMinPlayers { get; set; }
public float Timer { get; set; }
public int Offset { get; set; }
}

public class Whitelist
{
public bool SkipAFK { get; set; }
Expand Down

0 comments on commit 5408592

Please sign in to comment.