forked from UNLOZE/sm-plugins
adding minute support from unloze playtime into discord message, entwatch, knifeban and spraymanager
This commit is contained in:
@@ -25,8 +25,13 @@ Handle g_hFwd_OnClientUnrestricted;
|
||||
|
||||
/* COOKIES */
|
||||
Handle g_hCookie_RestrictIssued;
|
||||
Handle g_hCookie_RestrictIssued_minutes;
|
||||
|
||||
Handle g_hCookie_RestrictExpire;
|
||||
Handle g_hCookie_RestrictExpire_minutes;
|
||||
|
||||
Handle g_hCookie_RestrictLength;
|
||||
Handle g_hCookie_RestrictLength_minutes;
|
||||
|
||||
/* BOOLEANS */
|
||||
bool g_bRestrictedTemp[MAXPLAYERS+1];
|
||||
@@ -34,9 +39,16 @@ bool g_bDontSpamMsg[MAXPLAYERS+1]
|
||||
|
||||
/* INTERGERS */
|
||||
int g_iRestrictIssued[MAXPLAYERS+1];
|
||||
int g_iRestrictIssued_minutes[MAXPLAYERS+1];
|
||||
|
||||
int g_iRestrictLength[MAXPLAYERS+1];
|
||||
int g_iRestrictLength_minutes[MAXPLAYERS+1];
|
||||
|
||||
int g_iRestrictExpire[MAXPLAYERS+1];
|
||||
int g_iRestrictExpire_minutes[MAXPLAYERS+1];
|
||||
|
||||
int g_iClientHours[MAXPLAYERS + 1];
|
||||
int g_iClientMinutes[MAXPLAYERS + 1];
|
||||
|
||||
/* STRINGMAPS */
|
||||
StringMap g_hTrie_Storage;
|
||||
@@ -76,12 +88,17 @@ public void OnPluginStart()
|
||||
LoadTranslations("common.phrases");
|
||||
LoadTranslations("entWatch.restrictions.phrases");
|
||||
|
||||
g_hFwd_OnClientRestricted = CreateGlobalForward("EW_OnClientRestricted", ET_Ignore, Param_Cell, Param_Cell, Param_Cell);
|
||||
g_hFwd_OnClientRestricted = CreateGlobalForward("EW_OnClientRestricted", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_Cell);
|
||||
g_hFwd_OnClientUnrestricted = CreateGlobalForward("EW_OnClientUnrestricted", ET_Ignore, Param_Cell, Param_Cell);
|
||||
|
||||
g_hCookie_RestrictIssued = RegClientCookie("EW_RestrictIssued", "", CookieAccess_Private);
|
||||
g_hCookie_RestrictIssued_minutes = RegClientCookie("EW_RestrictIssued_minutes", "", CookieAccess_Private);
|
||||
|
||||
g_hCookie_RestrictExpire = RegClientCookie("EW_RestrictExpire", "", CookieAccess_Private);
|
||||
g_hCookie_RestrictExpire_minutes = RegClientCookie("EW_RestrictExpire_minutes", "", CookieAccess_Private);
|
||||
|
||||
g_hCookie_RestrictLength = RegClientCookie("EW_RestrictLength", "", CookieAccess_Private);
|
||||
g_hCookie_RestrictLength_minutes = RegClientCookie("EW_RestrictLength_minutes", "", CookieAccess_Private);
|
||||
|
||||
g_hTrie_Storage = new StringMap();
|
||||
|
||||
@@ -134,8 +151,13 @@ public void OnClientPutInServer(int client)
|
||||
public void OnClientCookiesCached(int client)
|
||||
{
|
||||
g_iRestrictIssued[client] = GetClientCookieInt(client, g_hCookie_RestrictIssued);
|
||||
g_iRestrictIssued_minutes[client] = GetClientCookieInt(client, g_hCookie_RestrictIssued_minutes);
|
||||
|
||||
g_iRestrictExpire[client] = GetClientCookieInt(client, g_hCookie_RestrictExpire);
|
||||
g_iRestrictExpire_minutes[client] = GetClientCookieInt(client, g_hCookie_RestrictExpire_minutes);
|
||||
|
||||
g_iRestrictLength[client] = GetClientCookieInt(client, g_hCookie_RestrictLength);
|
||||
g_iRestrictLength_minutes[client] = GetClientCookieInt(client, g_hCookie_RestrictLength_minutes);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -153,10 +175,18 @@ public void OnClientDisconnect(int client)
|
||||
|
||||
g_bDontSpamMsg[client] = false;
|
||||
g_bRestrictedTemp[client] = false;
|
||||
|
||||
g_iRestrictIssued[client] = 0;
|
||||
g_iRestrictIssued_minutes[client] = 0;
|
||||
|
||||
g_iRestrictExpire[client] = 0;
|
||||
g_iRestrictExpire_minutes[client] = 0;
|
||||
|
||||
g_iRestrictLength[client] = 0;
|
||||
g_iRestrictLength_minutes[client] = 0;
|
||||
|
||||
g_iClientHours[client] = 0;
|
||||
g_iClientMinutes[client] = 0;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@@ -184,13 +214,20 @@ public Action Command_ClientRestrict(int client, int args)
|
||||
|
||||
if (ClientRestrict(client, target, length))
|
||||
{
|
||||
if (length && length >= 60)
|
||||
if (length == -1)
|
||||
{
|
||||
length /= 60;
|
||||
CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \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 restricted %L for %d hours playtime.", client, target, length);
|
||||
CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s temporarily.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
||||
LogAction(client, target, "%L restricted %L temporarily.", client, target);
|
||||
}
|
||||
else if (!length)
|
||||
else if (length > 0)
|
||||
{
|
||||
int hours = length / 60;
|
||||
int minutes = length % 60;
|
||||
|
||||
CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \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", hours, "F16767", "EDEDED", minutes, "F16767");
|
||||
LogAction(client, target, "%L restricted %L for %d hours and %d minutes playtime.", client, target, hours, minutes);
|
||||
}
|
||||
else
|
||||
{
|
||||
CPrintToChatAll("\x07%s[entWatch] \x07%s%N\x07%s restricted \x07%s%N\x07%s permanently.", "E01B5D", "EDEDED", client, "F16767", "EDEDED", target, "F16767");
|
||||
LogAction(client, target, "%L restricted %L permanently.", client, target);
|
||||
@@ -252,7 +289,7 @@ public Action Command_DisplayRestrictions(int client, int args)
|
||||
{
|
||||
if (ClientRestricted(i))
|
||||
{
|
||||
if (g_iClientHours[i] <= g_cvarHourRequirement.IntValue)
|
||||
if (g_iClientHours[i] < g_cvarHourRequirement.IntValue)
|
||||
{
|
||||
GetClientName(i, aBuf2_time_requirement, sizeof(aBuf2_time_requirement));
|
||||
StrCat(aBuf_time_requirement, sizeof(aBuf_time_requirement), aBuf2_time_requirement);
|
||||
@@ -318,9 +355,24 @@ public Action Command_DisplayStatus(int client, int args)
|
||||
}
|
||||
else if (g_iRestrictIssued[target] && g_iRestrictExpire[target] >= g_iClientHours[target])
|
||||
{
|
||||
//example: 1335 hours and 40 minutes restriction expires. player at 1335 hours and 50 minutes is no longer restricted.
|
||||
if (g_iRestrictExpire[target] == g_iClientHours[target] && g_iRestrictExpire_minutes[target] < g_iClientMinutes[target])
|
||||
{
|
||||
CReplyToCommand(client, "\x07%s[entWatch] \x07%s%N\x07%s is currently not restricted.", "E01B5D", "EDEDED", target, "F16767");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//its just hours and minutes now
|
||||
char sTimeRemaining[64];
|
||||
int iTimeRemaining = g_iRestrictExpire[target] - g_iClientHours[target]; //its just hours now
|
||||
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours Playtime", iTimeRemaining);
|
||||
int iTimeRemaining_hours = g_iRestrictExpire[target] - g_iClientHours[target];
|
||||
int iTimeRemaining_minutes = g_iRestrictExpire_minutes[target] - g_iClientMinutes[target];
|
||||
if (iTimeRemaining_minutes < 0)
|
||||
{
|
||||
iTimeRemaining_minutes += 60;
|
||||
iTimeRemaining_hours--;
|
||||
}
|
||||
|
||||
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours and %d minutes Playtime", iTimeRemaining_hours, iTimeRemaining_minutes);
|
||||
|
||||
CReplyToCommand(client, "\x07%s[entWatch] \x07%s%N\x07%s is currently restricted for another \x07%s%s\x07%s.", "E01B5D", "EDEDED", target, "F16767", "EDEDED", sTimeRemaining, "F16767");
|
||||
return Plugin_Handled;
|
||||
@@ -350,9 +402,24 @@ public Action Command_DisplayStatus(int client, int args)
|
||||
}
|
||||
else if (g_iRestrictIssued[client] && g_iRestrictExpire[client] >= g_iClientHours[client])
|
||||
{
|
||||
//example: 1335 hours and 40 minutes restriction expires. player at 1335 hours and 50 minutes is no longer restricted.
|
||||
if (g_iRestrictExpire[client] == g_iClientHours[client] && g_iRestrictExpire_minutes[client] < g_iClientMinutes[client])
|
||||
{
|
||||
CReplyToCommand(client, "\x07%s[entWatch] \x07%sYou are currently not restricted.", "E01B5D", "F16767");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
//its just hours and minutes now
|
||||
char sTimeRemaining[64];
|
||||
int iTimeRemaining = g_iRestrictExpire[client] - g_iClientHours[client]; //its just hours now
|
||||
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours Playtime", iTimeRemaining);
|
||||
int iTimeRemaining_hours = g_iRestrictExpire[client] - g_iClientHours[client];
|
||||
int iTimeRemaining_minutes = g_iRestrictExpire_minutes[client] - g_iClientMinutes[client];
|
||||
if (iTimeRemaining_minutes < 0)
|
||||
{
|
||||
iTimeRemaining_minutes += 60;
|
||||
iTimeRemaining_hours--;
|
||||
}
|
||||
|
||||
Format(sTimeRemaining, sizeof(sTimeRemaining), "%d Hours and %d minutes Playtime", iTimeRemaining_hours, iTimeRemaining_minutes);
|
||||
|
||||
CReplyToCommand(client, "\x07%s[entWatch] \x07%sYou are currently restricted for another \x07%s%s\x07%s.", "E01B5D", "F16767", "EDEDED", sTimeRemaining, "F16767");
|
||||
return Plugin_Handled;
|
||||
@@ -401,6 +468,7 @@ stock bool ClientRestrict(int client, int target, int length)
|
||||
}
|
||||
else if (length == 0)
|
||||
{
|
||||
//permanently
|
||||
g_bRestrictedTemp[target] = false;
|
||||
g_iRestrictIssued[target] = g_iClientHours[target];
|
||||
g_iRestrictExpire[target] = 0;
|
||||
@@ -412,27 +480,52 @@ stock bool ClientRestrict(int client, int target, int length)
|
||||
}
|
||||
else
|
||||
{
|
||||
if (length < 60)
|
||||
{
|
||||
CPrintToChat(client, "\x07%s[entWatch] \x07%sEban length is now rounded in hours so minimum value has to be 60.", "E01B5D", "EDEDED");
|
||||
return false;
|
||||
}
|
||||
//2026 edit. we now use ingame play time of the client instead of real time.
|
||||
length /= 60;
|
||||
int hours_length = length / 60;
|
||||
int minutes_length = length % 60;
|
||||
|
||||
g_bRestrictedTemp[target] = false;
|
||||
|
||||
g_iRestrictIssued[target] = g_iClientHours[target];
|
||||
g_iRestrictExpire[target] = g_iClientHours[target] + length;
|
||||
g_iRestrictLength[target] = length;
|
||||
g_iRestrictIssued_minutes[target] = g_iClientMinutes[target];
|
||||
|
||||
g_iRestrictExpire[target] = g_iClientHours[target] + hours_length;
|
||||
int rounded_minutes = g_iClientMinutes[target] + minutes_length;
|
||||
if (rounded_minutes > 60)
|
||||
{
|
||||
rounded_minutes -= 60;
|
||||
g_iRestrictExpire[target]++;
|
||||
}
|
||||
g_iRestrictExpire_minutes[target] = rounded_minutes;
|
||||
|
||||
g_iRestrictLength[target] = hours_length;
|
||||
g_iRestrictLength_minutes[target] = minutes_length;
|
||||
|
||||
SetClientCookieInt(target, g_hCookie_RestrictIssued, g_iRestrictIssued[target]);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictIssued_minutes, g_iRestrictIssued_minutes[target]);
|
||||
|
||||
SetClientCookieInt(target, g_hCookie_RestrictExpire, g_iRestrictExpire[target]);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictLength, length);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictExpire_minutes, g_iRestrictExpire_minutes[target]);
|
||||
|
||||
SetClientCookieInt(target, g_hCookie_RestrictLength, g_iRestrictLength[target]);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictLength_minutes, g_iRestrictLength_minutes[target]);
|
||||
}
|
||||
|
||||
Call_StartForward(g_hFwd_OnClientRestricted);
|
||||
Call_PushCell(client);
|
||||
Call_PushCell(target);
|
||||
Call_PushCell(length);
|
||||
if (length == -1 || length == 0)
|
||||
{
|
||||
//its temporarily or permanently
|
||||
Call_PushCell(length);
|
||||
Call_PushCell(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
//its certain amount of hours and minutes
|
||||
Call_PushCell(g_iRestrictLength[target]);
|
||||
Call_PushCell(g_iRestrictLength_minutes[target]);
|
||||
}
|
||||
Call_Finish();
|
||||
|
||||
return true;
|
||||
@@ -447,13 +540,24 @@ stock bool ClientUnrestrict(int client, int target)
|
||||
return false;
|
||||
|
||||
g_bRestrictedTemp[target] = false;
|
||||
|
||||
g_iRestrictIssued[target] = 0;
|
||||
g_iRestrictIssued_minutes[target] = 0;
|
||||
|
||||
g_iRestrictExpire[target] = 0;
|
||||
g_iRestrictExpire_minutes[target] = 0;
|
||||
|
||||
g_iRestrictLength[target] = 0;
|
||||
g_iRestrictLength_minutes[target] = 0;
|
||||
|
||||
SetClientCookieInt(target, g_hCookie_RestrictIssued, 0);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictIssued_minutes, 0);
|
||||
|
||||
SetClientCookieInt(target, g_hCookie_RestrictExpire, 0);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictExpire_minutes, 0);
|
||||
|
||||
SetClientCookieInt(target, g_hCookie_RestrictLength, 0);
|
||||
SetClientCookieInt(target, g_hCookie_RestrictLength_minutes, 0);
|
||||
|
||||
Call_StartForward(g_hFwd_OnClientUnrestricted);
|
||||
Call_PushCell(client);
|
||||
@@ -485,14 +589,25 @@ stock bool ClientRestricted(int client)
|
||||
|
||||
//Normal restriction.
|
||||
if (g_iRestrictIssued[client] && g_iRestrictExpire[client] >= g_iClientHours[client])
|
||||
return true;
|
||||
|
||||
{
|
||||
//example: client restricted until 1335 hours and currently has 1320
|
||||
if (g_iRestrictExpire[client] > g_iClientHours[client])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
//example client restricted until 1335 hours and 45 minutes. currently has 1335 hours and 20 minutes.
|
||||
if (g_iRestrictExpire_minutes[client] > g_iClientMinutes[client])
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//hour requirement for picking up items
|
||||
if (g_iClientHours[client] <= g_cvarHourRequirement.IntValue)
|
||||
if (g_iClientHours[client] < g_cvarHourRequirement.IntValue)
|
||||
{
|
||||
if (!g_bDontSpamMsg[client])
|
||||
{
|
||||
CPrintToChat(client, "\x07%s[entWatch] \x07%s You have \x07%s%i\x07%s hours playtime and need more than %i hours for picking up items.", "E01B5D", "EDEDED", "EDEDED", g_iClientHours[client], "EDEDED", g_cvarHourRequirement.IntValue);
|
||||
CPrintToChat(client, "\x07%s[entWatch] \x07%s You have \x07%s%i\x07%s hours and \x07%s%i\x07%s minutes playtime and need %i hours for picking up items.", "E01B5D", "EDEDED", "EDEDED", g_iClientHours[client], "EDEDED", "EDEDED", g_iClientMinutes[client], "EDEDED", g_cvarHourRequirement.IntValue);
|
||||
g_bDontSpamMsg[client] = true;
|
||||
CreateTimer(1.0, allow_message_again, GetClientSerial(client));
|
||||
}
|
||||
@@ -551,9 +666,10 @@ stock int GetClientCookieInt(int client, Handle hCookie)
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// 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;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user