adding minute support from unloze playtime into discord message, entwatch, knifeban and spraymanager

This commit is contained in:
jenz
2026-01-27 18:55:28 +01:00
parent 7d940c6509
commit 41b775f611
5 changed files with 284 additions and 77 deletions
+99 -44
View File
@@ -21,6 +21,7 @@ KeyValues Banlist;
int g_hActiveWeapon;
int g_iClientHours[MAXPLAYERS + 1];
int g_iClientMinutes[MAXPLAYERS + 1];
public Plugin myinfo =
{
@@ -99,6 +100,8 @@ public void OnClientPostAdminCheck(int client)
}
g_iClientHours[client] = 0;
g_iClientMinutes[client] = 0;
char sAuth[32];
GetClientAuthId(client, AuthId_Steam2, sAuth, sizeof(sAuth));
@@ -107,12 +110,14 @@ public void OnClientPostAdminCheck(int client)
if(Banlist.JumpToKey(sAuth))
{
int length = Banlist.GetNum("duration");
int length_minutes = Banlist.GetNum("duration_minutes");
int time = Banlist.GetNum("time");
int time_minutes = Banlist.GetNum("time_minutes", 0);
if(length == -1)
g_bKnifeBanned[client] = true;
else if(length > 0)
CheckIfClientIsStillKnifeBanned(sAuth, client, time, length);
CheckIfClientIsStillKnifeBanned(sAuth, client, time, time_minutes, length, length_minutes);
}
int accountid = GetSteamAccountID(client);
@@ -127,6 +132,7 @@ public void OnClientPostAdminCheck(int client)
public void OnClientDisconnect(int client)
{
g_iClientHours[client] = 0;
g_iClientMinutes[client] = 0;
g_bKnifeBanned[client] = false;
}
@@ -150,28 +156,45 @@ public Action CheckKnifeBans(Handle timer)
Banlist.Rewind();
int length;
int length_minutes;
int time;
int time_minutes;
if(Banlist.JumpToKey(sAuth))
{
length = Banlist.GetNum("duration");
length_minutes = Banlist.GetNum("duration_minutes");
time = Banlist.GetNum("time");
time_minutes = Banlist.GetNum("time_minutes", 0);
}
if(length > 0)
CheckIfClientIsStillKnifeBanned(sAuth, i, time, length);
CheckIfClientIsStillKnifeBanned(sAuth, i, time, time_minutes, length, length_minutes);
}
}
return Plugin_Continue;
}
public void CheckIfClientIsStillKnifeBanned(char sAuth[32], int client, int time, int length)
public void CheckIfClientIsStillKnifeBanned(char sAuth[32], int client, int time, int time_minutes, int length, int length_minutes)
{
int timesinceknifeban = g_iClientHours[client] - time;
int timesinceknifeban_minutes = g_iClientMinutes[client] - time_minutes;
if(timesinceknifeban < length)
if (timesinceknifeban_minutes < 0)
{
timesinceknifeban_minutes += 60;
timesinceknifeban--;
}
if (timesinceknifeban < length)
{
g_bKnifeBanned[client] = true;
else
}
else if (timesinceknifeban == length && timesinceknifeban_minutes < length_minutes)
{
g_bKnifeBanned[client] = true;
}
else
{
g_bKnifeBanned[client] = false;
Banlist.Rewind();
@@ -179,7 +202,9 @@ public void CheckIfClientIsStillKnifeBanned(char sAuth[32], int client, int time
if(Banlist.JumpToKey(sAuth))
{
Banlist.SetNum("time", 0);
Banlist.SetNum("time_minutes", 0);
Banlist.SetNum("duration", 0);
Banlist.SetNum("duration_minutes", 0);
Banlist.SetString("admin", "");
Banlist.Rewind();
Banlist.ExportToFile(g_sBanListFilePath);
@@ -242,6 +267,9 @@ public Action Command_Knifeban(int client, int args)
return Plugin_Handled;
int length;
int length_hours;
int length_minutes;
if(GetCmdArgs() >= 2)
{
length = StringToInt(sArguments[1]);
@@ -252,18 +280,10 @@ public Action Command_Knifeban(int client, int args)
return Plugin_Handled;
}
if(length < 60 && length != 0)
{
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sKnifebans are now done in hours of gametime. Minimum value is 60.", "E01B5D", "F16767");
return Plugin_Handled;
}
if (length != 0)
{
length /= 60;
}
length_hours = length / 60;
length_minutes = length % 60;
}
if(g_bKnifeBanned[target])
{
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sThe given client is already knifebanned.", "E01B5D", "F16767");
@@ -272,6 +292,7 @@ public Action Command_Knifeban(int client, int args)
g_bKnifeBanned[target] = true;
int time = g_iClientHours[target];
int time_minutes = g_iClientMinutes[target];
char sAdmin[32];
GetClientName(client, sAdmin, sizeof(sAdmin));
@@ -285,16 +306,18 @@ public Action Command_Knifeban(int client, int args)
if(GetCmdArgs() >= 2)
{
if(length)
if(length_hours || length_minutes)
{
CPrintToChatAll("\x07%s[KnifeBan] \x07%s%N\x07%s knifebanned \x07%s%N\x07%s for \x07%s%d\x07%s hours Playtime.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767", "EDEDED", length, "F16767");
LogAction(client, target, "%L knifebanned %L for %d hours.", client, target, length);
CPrintToChatAll("\x07%s[KnifeBan] \x07%s%N\x07%s knifebanned \x07%s%N\x07%s for \x07%s%d\x07%s hours and \x07%s%d\x07%s minutes Playtime.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767", "EDEDED", length_hours, "F16767", "EDEDED", length_minutes, "F16767");
LogAction(client, target, "%L knifebanned %L for %d hours and %d minutes.", client, target, length_hours, length_minutes);
if(Banlist.JumpToKey(sAuth, true))
{
int history = Banlist.GetNum("history");
Banlist.SetNum("history", history + 1);
Banlist.SetNum("time", time);
Banlist.SetNum("duration", length);
Banlist.SetNum("time_minutes", time_minutes);
Banlist.SetNum("duration", length_hours);
Banlist.SetNum("duration_minutes", length_minutes);
Banlist.SetString("admin", sAdmin);
Banlist.Rewind();
Banlist.ExportToFile(g_sBanListFilePath);
@@ -309,7 +332,9 @@ public Action Command_Knifeban(int client, int args)
int history = Banlist.GetNum("history");
Banlist.SetNum("history", history + 1);
Banlist.SetNum("time", time);
Banlist.SetNum("time_minutes", time_minutes);
Banlist.SetNum("duration", -1);
Banlist.SetNum("duration_minutes", -1);
Banlist.SetString("admin", sAdmin);
Banlist.Rewind();
Banlist.ExportToFile(g_sBanListFilePath);
@@ -325,6 +350,7 @@ public Action Command_Knifeban(int client, int args)
int history = Banlist.GetNum("history");
Banlist.SetNum("history", history + 1);
Banlist.SetNum("time", time);
Banlist.SetNum("time_minutes", time_minutes);
Banlist.SetString("admin", sAdmin);
Banlist.Rewind();
Banlist.ExportToFile(g_sBanListFilePath);
@@ -368,7 +394,9 @@ public Action Command_Knifeunban(int client, int args)
int history = Banlist.GetNum("history");
Banlist.SetNum("history", history - 1);
Banlist.SetNum("time", 0);
Banlist.SetNum("time_minutes", 0);
Banlist.SetNum("duration", 0);
Banlist.SetNum("duration_minutes", 0);
Banlist.SetString("admin", "");
Banlist.Rewind();
Banlist.ExportToFile(g_sBanListFilePath);
@@ -405,13 +433,21 @@ public Action Command_Knifestatus(int client, int args)
int index = g_TempBanned.FindValue(accountid);
Banlist.Rewind();
int length;
int length_hours;
int length_minutes;
int time;
int time_minutes;
int history;
if(Banlist.JumpToKey(sAuth))
{
length = Banlist.GetNum("duration");
length_hours = Banlist.GetNum("duration");
length_minutes = Banlist.GetNum("duration_minutes");
time = Banlist.GetNum("time");
time_minutes = Banlist.GetNum("time_minutes");
history = Banlist.GetNum("history");
}
@@ -422,18 +458,27 @@ public Action Command_Knifestatus(int client, int args)
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently temporarily knifebanned.", "E01B5D", "EDEDED", target, "F16767");
return Plugin_Handled;
}
else if(g_bKnifeBanned[target] && length == -1)
else if(g_bKnifeBanned[target] && length_hours == -1)
{
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently permanently knifebanned.", "E01B5D", "EDEDED", target, "F16767");
return Plugin_Handled;
}
else if(g_bKnifeBanned[target] && length > 0)
else if(g_bKnifeBanned[target] && (length_hours > 0 || length_minutes > 0))
{
char sTimeRemaining[64];
int timesinceknifeban = g_iClientHours[target] - time;
int iTimeRemaining = length - timesinceknifeban;
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours playtime", iTimeRemaining);
int timesinceknifeban_minutes = g_iClientMinutes[target] - time_minutes;
if (timesinceknifeban_minutes < 0)
{
timesinceknifeban_minutes += 60;
timesinceknifeban--;
}
int iTimeRemaining = length_hours - timesinceknifeban;
int iTimeRemaining_minutes = length_minutes - timesinceknifeban_minutes;
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours and %d minutes playtime", iTimeRemaining, iTimeRemaining_minutes);
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%s%N\x07%s is currently knifebanned for another \x07%s%s\x07%s.", "E01B5D", "EDEDED", target, "F16767", "EDEDED", sTimeRemaining, "F16767");
return Plugin_Handled;
}
@@ -451,12 +496,18 @@ public Action Command_Knifestatus(int client, int args)
int index = g_TempBanned.FindValue(accountid);
Banlist.Rewind();
int length;
int length_hours;
int length_minutes;
int time;
int time_minutes;
if(Banlist.JumpToKey(sAuth))
{
length = Banlist.GetNum("duration");
length_hours = Banlist.GetNum("duration");
length_minutes = Banlist.GetNum("duration_minutes");
time = Banlist.GetNum("time");
time_minutes = Banlist.GetNum("time_minutes");
}
if(g_bKnifeBanned[client] && index != -1)
@@ -464,19 +515,27 @@ public Action Command_Knifestatus(int client, int args)
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently temporarily knifebanned.", "E01B5D", "F16767");
return Plugin_Handled;
}
else if(g_bKnifeBanned[client] && length == -1)
else if(g_bKnifeBanned[client] && length_hours == -1)
{
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently permanently knifebanned.", "E01B5D", "F16767");
return Plugin_Handled;
}
else if (g_bKnifeBanned[client] && length > 0)
else if(g_bKnifeBanned[client] && (length_hours > 0 || length_minutes > 0))
{
char sTimeRemaining[64];
int timesinceknifeban = g_iClientHours[client] - time;
int iTimeRemaining = length - timesinceknifeban;
int timesinceknifeban_minutes = g_iClientMinutes[client] - time_minutes;
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours playtime", iTimeRemaining);
if (timesinceknifeban_minutes < 0)
{
timesinceknifeban_minutes += 60;
timesinceknifeban--;
}
int iTimeRemaining = length_hours - timesinceknifeban;
int iTimeRemaining_minutes = length_minutes - timesinceknifeban_minutes;
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours and %d minutes playtime", iTimeRemaining, iTimeRemaining_minutes);
CReplyToCommand(client, "\x07%s[KnifeBan] \x07%sYou are currently knifebanned for another \x07%s%s\x07%s.", "E01B5D", "F16767", "EDEDED", sTimeRemaining, "F16767");
return Plugin_Handled;
}
@@ -600,13 +659,15 @@ public void OpenKnifebanlistOfTheClient(int client, char sBuffer[32])
Banlist.Rewind();
int length;
int time;
int length_minutes;
int history;
char sAdmin[32];
if(Banlist.JumpToKey(sAuth))
{
length = Banlist.GetNum("duration");
time = Banlist.GetNum("time");
length_minutes = Banlist.GetNum("duration_minutes");
history = Banlist.GetNum("history");
Banlist.GetString("admin", sAdmin, sizeof(sAdmin));
}
@@ -619,25 +680,18 @@ public void OpenKnifebanlistOfTheClient(int client, char sBuffer[32])
menuclient.AddItem("0", sInfo);
if(length > 0)
Format(sInfo, sizeof(sInfo), "Duration: %d Hours playtime", length);
Format(sInfo, sizeof(sInfo), "Duration: %d Hours and %d minutes playtime", length, length_minutes);
else if(length == -1)
Format(sInfo, sizeof(sInfo), "Duration: Permanently");
else
Format(sInfo, sizeof(sInfo), "Duration: Temporarly");
menuclient.AddItem("1", sInfo);
char sTime[32];
FormatTime(sTime, sizeof(sTime), "%c", time);
Format(sInfo, sizeof(sInfo), "Date: %s", sTime);
Format(sInfo, sizeof(sInfo), "Ban History: %d times", history);
menuclient.AddItem("2", sInfo);
Format(sInfo, sizeof(sInfo), "Ban History: %d times", history);
menuclient.AddItem("3", sInfo);
menuclient.AddItem("4", "Back to List");
menuclient.AddItem("3", "Back to List");
menuclient.Display(client, MENU_TIME_FOREVER);
}
@@ -663,7 +717,8 @@ public void MenuHandler_ClientMenu(Menu menuclient, MenuAction action, int clien
//----------------------------------------------------------------------------------------------------
// Purpose: 2026 getting the ingame play time of the players. called with OnClientPostAdminCheck() forward and timer every 10 minutes
//----------------------------------------------------------------------------------------------------
public void GetPlayerHoursServer(int client, int hours)
public void GetPlayerHoursServer(int client, int hours, int minutes)
{
g_iClientHours[client] = hours;
g_iClientMinutes[client] = minutes;
}