added support for average hours count on server

This commit is contained in:
jenz 2023-04-09 13:57:09 +02:00
parent d21303488b
commit 1c4f1d532c
3 changed files with 173 additions and 109 deletions

View File

@ -148,6 +148,8 @@ native bool AreRestrictionsActive();
native int SimulateMapEnd(); native int SimulateMapEnd();
native int GetAveragePlayerTimeOnServerMapRestriction(const char[] map);
public SharedPlugin __pl_mapchooser_extended = public SharedPlugin __pl_mapchooser_extended =
{ {
name = "mapchooser", name = "mapchooser",

View File

@ -46,6 +46,7 @@
#include <sourcemod> #include <sourcemod>
#include <mapchooser> #include <mapchooser>
#include <mapchooser_extended> #include <mapchooser_extended>
#include <unloze_playtime>
#include <nextmap> #include <nextmap>
#include <sdktools> #include <sdktools>
#include <multicolors> #include <multicolors>
@ -304,6 +305,8 @@ public void OnPluginStart()
RegConsoleCmd("sm_extends", Command_ExtendsLeft, "sm_extends - Shows how many extends are left on the current map."); RegConsoleCmd("sm_extends", Command_ExtendsLeft, "sm_extends - Shows how many extends are left on the current map.");
RegConsoleCmd("sm_extendsleft", Command_ExtendsLeft, "sm_extendsleft - Shows how many extends are left on the current map."); RegConsoleCmd("sm_extendsleft", Command_ExtendsLeft, "sm_extendsleft - Shows how many extends are left on the current map.");
RegConsoleCmd("sm_houravg", Command_hours_average, "Prints in the chat what the current hour average of each player accumulated is.");
RegConsoleCmd("sm_avghour", Command_hours_average, "Prints in the chat what the current hour average of each player accumulated is.");
g_Cvar_Winlimit = FindConVar("mp_winlimit"); g_Cvar_Winlimit = FindConVar("mp_winlimit");
g_Cvar_Maxrounds = FindConVar("mp_maxrounds"); g_Cvar_Maxrounds = FindConVar("mp_maxrounds");
@ -402,47 +405,48 @@ public void OnPluginStart()
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max) public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{ {
if(LibraryExists("mapchooser")) if(LibraryExists("mapchooser"))
{ {
strcopy(error, err_max, "MapChooser already loaded, aborting."); strcopy(error, err_max, "MapChooser already loaded, aborting.");
return APLRes_Failure; return APLRes_Failure;
} }
RegPluginLibrary("mapchooser"); RegPluginLibrary("mapchooser");
MarkNativeAsOptional("GetEngineVersion"); MarkNativeAsOptional("GetEngineVersion");
CreateNative("NominateMap", Native_NominateMap); CreateNative("NominateMap", Native_NominateMap);
CreateNative("RemoveNominationByMap", Native_RemoveNominationByMap); CreateNative("RemoveNominationByMap", Native_RemoveNominationByMap);
CreateNative("RemoveNominationByOwner", Native_RemoveNominationByOwner); CreateNative("RemoveNominationByOwner", Native_RemoveNominationByOwner);
CreateNative("InitiateMapChooserVote", Native_InitiateVote); CreateNative("InitiateMapChooserVote", Native_InitiateVote);
CreateNative("CanMapChooserStartVote", Native_CanVoteStart); CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone); CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
CreateNative("GetExcludeMapList", Native_GetExcludeMapList); CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
CreateNative("GetNominatedMapList", Native_GetNominatedMapList); CreateNative("GetNominatedMapList", Native_GetNominatedMapList);
CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled); CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled);
// MapChooser Extended natives // MapChooser Extended natives
CreateNative("IsMapOfficial", Native_IsMapOfficial); CreateNative("IsMapOfficial", Native_IsMapOfficial);
CreateNative("CanNominate", Native_CanNominate); CreateNative("CanNominate", Native_CanNominate);
CreateNative("ExcludeMap", Native_ExcludeMap); CreateNative("ExcludeMap", Native_ExcludeMap);
CreateNative("ExcludeMapTime", Native_ExcludeMapTime); CreateNative("ExcludeMapTime", Native_ExcludeMapTime);
CreateNative("GetMapCooldown", Native_GetMapCooldown); CreateNative("GetMapCooldown", Native_GetMapCooldown);
CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime); CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime);
CreateNative("GetMapMinTime", Native_GetMapMinTime); CreateNative("GetMapMinTime", Native_GetMapMinTime);
CreateNative("GetMapMaxTime", Native_GetMapMaxTime); CreateNative("GetMapMaxTime", Native_GetMapMaxTime);
CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers); CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers);
CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers); CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers);
CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction); CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction);
CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction); CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction);
CreateNative("GetMapGroups", Native_GetMapGroups); CreateNative("GetMapGroups", Native_GetMapGroups);
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction); CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction); CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction);
CreateNative("GetExtendsLeft", Native_GetExtendsLeft); CreateNative("GetExtendsLeft", Native_GetExtendsLeft);
CreateNative("AreRestrictionsActive", Native_AreRestrictionsActive); CreateNative("AreRestrictionsActive", Native_AreRestrictionsActive);
CreateNative("SimulateMapEnd", Native_SimulateMapEnd); CreateNative("SimulateMapEnd", Native_SimulateMapEnd);
CreateNative("GetAveragePlayerTimeOnServerMapRestriction", Native_GetAveragePlayerTimeOnServerMapRestriction);
return APLRes_Success; return APLRes_Success;
} }
public void OnMapStart() public void OnMapStart()
@ -665,6 +669,12 @@ public Action Command_ReloadMaps(int client, int args)
InitializeOfficialMapList(); InitializeOfficialMapList();
} }
public Action Command_hours_average(int client, int args)
{
PrintToChat(client, "Average hour count is: %i", GetAveragePlayerTimeOnServer());
return Plugin_Handled;
}
public Action Command_ExtendsLeft(int client, int args) public Action Command_ExtendsLeft(int client, int args)
{ {
CReplyToCommand(client, "[MCE] Available Extends: %d", GetConVarInt(g_Cvar_Extend) - g_Extends); CReplyToCommand(client, "[MCE] Available Extends: %d", GetConVarInt(g_Cvar_Extend) - g_Extends);
@ -2367,6 +2377,33 @@ public int Native_GetMapTimeRestriction(Handle plugin, int numParams)
return InternalGetMapTimeRestriction(map); return InternalGetMapTimeRestriction(map);
} }
//GetAveragePlayerTimeOnServerMapRestriction
public int Native_GetAveragePlayerTimeOnServerMapRestriction(Handle plugin, int numParams)
{
int len;
GetNativeStringLength(1, len);
if(len <= 0)
return false;
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
int players_average_hours = GetAveragePlayerTimeOnServer();
int MinAverageHours = 0;
if(g_Config && g_Config.JumpToKey(map))
{
MinAverageHours = g_Config.GetNum("MinHoursAvg", MinAverageHours);
g_Config.Rewind();
}
//0 means map can be nominated, anything above 0 means more hours are required
if (players_average_hours >= MinAverageHours)
{
return 0;
}
return MinAverageHours - players_average_hours;
}
//GetMapPlayerRestriction
public int Native_GetMapPlayerRestriction(Handle plugin, int numParams) public int Native_GetMapPlayerRestriction(Handle plugin, int numParams)
{ {
int len; int len;

View File

@ -360,100 +360,107 @@ public void OnNominationRemoved(const char[] map)
public Action Command_Addmap(int client, int args) public Action Command_Addmap(int client, int args)
{ {
if(args == 0) if(args == 0)
{ {
AttemptAdminNominate(client); AttemptAdminNominate(client);
return Plugin_Handled; return Plugin_Handled;
} }
if(args != 1) if(args != 1)
{ {
CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>"); CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>");
return Plugin_Handled; return Plugin_Handled;
} }
static char mapname[PLATFORM_MAX_PATH]; static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname)); GetCmdArg(1, mapname, sizeof(mapname));
if(!IsMapValid(mapname)) if(!IsMapValid(mapname))
{ {
CReplyToCommand(client, "%t", "Map was not found", mapname); CReplyToCommand(client, "%t", "Map was not found", mapname);
AttemptAdminNominate(client, mapname); AttemptAdminNominate(client, mapname);
return Plugin_Handled; return Plugin_Handled;
} }
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true)) if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
{ {
bool RestrictionsActive = AreRestrictionsActive(); bool RestrictionsActive = AreRestrictionsActive();
int status; int status;
if(GetTrieValue(g_mapTrie, mapname, status)) if(GetTrieValue(g_mapTrie, mapname, status))
{ {
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED) if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{ {
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map"); CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{ {
int Cooldown = GetMapCooldown(mapname); int Cooldown = GetMapCooldown(mapname);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
} }
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED) if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated"); CPrintToChat(client, "[NE] %t", "Map Already Nominated");
return Plugin_Handled; return Plugin_Handled;
} }
} }
int Cooldown = GetMapCooldownTime(mapname); int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime()) if(RestrictionsActive && Cooldown > GetTime())
{ {
int Seconds = Cooldown - GetTime(); int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60); CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
return Plugin_Handled; return Plugin_Handled;
} }
int TimeRestriction = GetMapTimeRestriction(mapname); int TimeRestriction = GetMapTimeRestriction(mapname);
if(RestrictionsActive && TimeRestriction) if(RestrictionsActive && TimeRestriction)
{ {
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60); CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
return Plugin_Handled; return Plugin_Handled;
} }
int PlayerRestriction = GetMapPlayerRestriction(mapname); int AverageHourRestricted = GetAveragePlayerTimeOnServerMapRestriction(mapname);
if(RestrictionsActive && PlayerRestriction) if (AverageHourRestricted > 0)
{ {
if(PlayerRestriction < 0) PrintToChat(client, "%s requires +%i hours average. Use sm_houravg to check average.", mapname, AverageHourRestricted);
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1); return Plugin_Handled;
else }
CPrintToChat(client, "[NE] %t", "Map Nominate MaxPlayers Error", PlayerRestriction);
return Plugin_Handled; int PlayerRestriction = GetMapPlayerRestriction(mapname);
} if(RestrictionsActive && PlayerRestriction)
} {
if(PlayerRestriction < 0)
CPrintToChat(client, "[NE] %t", "Map Nominate MinPlayers Error", PlayerRestriction * -1);
else
CPrintToChat(client, "[NE] %t", "Map Nominate MaxPlayers Error", PlayerRestriction);
NominateResult result = NominateMap(mapname, true, 0); return Plugin_Handled;
}
}
if(result > Nominate_Replaced) NominateResult result = NominateMap(mapname, true, 0);
{
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */
CReplyToCommand(client, "%t", "Map Already In Vote", mapname);
return Plugin_Handled; if(result > Nominate_Replaced)
} {
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */
CReplyToCommand(client, "%t", "Map Already In Vote", mapname);
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED); return Plugin_Handled;
}
CReplyToCommand(client, "%t", "Map Inserted", mapname); SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
PrintToChatAll("[NE] %N has inserted %s into nominations", client, mapname); CReplyToCommand(client, "%t", "Map Inserted", mapname);
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
return Plugin_Handled; PrintToChatAll("[NE] %N has inserted %s into nominations", client, mapname);
return Plugin_Handled;
} }
public Action Command_Removemap(int client, int args) public Action Command_Removemap(int client, int args)
@ -695,6 +702,13 @@ public Action Command_Nominate(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
int AverageHourRestricted = GetAveragePlayerTimeOnServerMapRestriction(mapname);
if (AverageHourRestricted > 0)
{
PrintToChat(client, "%s requires +%i hours average. Use sm_houravg to check average.", mapname, AverageHourRestricted);
return Plugin_Handled;
}
int PlayerRestriction = GetMapPlayerRestriction(mapname); int PlayerRestriction = GetMapPlayerRestriction(mapname);
if(RestrictionsActive && PlayerRestriction) if(RestrictionsActive && PlayerRestriction)
{ {
@ -1003,6 +1017,7 @@ Menu BuildMapMenu(const char[] filter, int client)
GetMapCooldownTime(map) > GetTime() || GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) || GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) || GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, client))) GetMapVIPRestriction(map, client)))
{ {
continue; continue;
@ -1098,6 +1113,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetMapCooldownTime(map) > GetTime() || GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) || GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) || GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1))) GetMapVIPRestriction(map, param1)))
{ {
PrintToChat(param1, "[NE] You cant nominate this map right now."); PrintToChat(param1, "[NE] You cant nominate this map right now.");
@ -1167,6 +1183,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetMapCooldownTime(map) > GetTime() || GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) || GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) || GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1))) GetMapVIPRestriction(map, param1)))
{ {
return ITEMDRAW_DISABLED; return ITEMDRAW_DISABLED;
@ -1258,6 +1275,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return RedrawMenuItem(display); return RedrawMenuItem(display);
} }
int AverageHourRestricted = GetAveragePlayerTimeOnServerMapRestriction(map);
if (AverageHourRestricted > 0)
{
Format(display, sizeof(display), "%s requires +%i hours average.", map, AverageHourRestricted);
return RedrawMenuItem(display);
}
int PlayerRestriction = GetMapPlayerRestriction(map); int PlayerRestriction = GetMapPlayerRestriction(map);
if(RestrictionsActive && PlayerRestriction) if(RestrictionsActive && PlayerRestriction)
{ {
@ -1352,6 +1376,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
GetMapCooldownTime(map) > GetTime() || GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) || GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) || GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1))) GetMapVIPRestriction(map, param1)))
{ {
PrintToChat(param1, "[NE] You cant nominate this map right now."); PrintToChat(param1, "[NE] You cant nominate this map right now.");