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 GetAveragePlayerTimeOnServerMapRestriction(const char[] map);
public SharedPlugin __pl_mapchooser_extended =
{
name = "mapchooser",

View File

@ -46,6 +46,7 @@
#include <sourcemod>
#include <mapchooser>
#include <mapchooser_extended>
#include <unloze_playtime>
#include <nextmap>
#include <sdktools>
#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_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_Maxrounds = FindConVar("mp_maxrounds");
@ -402,47 +405,48 @@ public void OnPluginStart()
public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
{
if(LibraryExists("mapchooser"))
{
strcopy(error, err_max, "MapChooser already loaded, aborting.");
return APLRes_Failure;
}
if(LibraryExists("mapchooser"))
{
strcopy(error, err_max, "MapChooser already loaded, aborting.");
return APLRes_Failure;
}
RegPluginLibrary("mapchooser");
RegPluginLibrary("mapchooser");
MarkNativeAsOptional("GetEngineVersion");
MarkNativeAsOptional("GetEngineVersion");
CreateNative("NominateMap", Native_NominateMap);
CreateNative("RemoveNominationByMap", Native_RemoveNominationByMap);
CreateNative("RemoveNominationByOwner", Native_RemoveNominationByOwner);
CreateNative("InitiateMapChooserVote", Native_InitiateVote);
CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
CreateNative("GetNominatedMapList", Native_GetNominatedMapList);
CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled);
CreateNative("NominateMap", Native_NominateMap);
CreateNative("RemoveNominationByMap", Native_RemoveNominationByMap);
CreateNative("RemoveNominationByOwner", Native_RemoveNominationByOwner);
CreateNative("InitiateMapChooserVote", Native_InitiateVote);
CreateNative("CanMapChooserStartVote", Native_CanVoteStart);
CreateNative("HasEndOfMapVoteFinished", Native_CheckVoteDone);
CreateNative("GetExcludeMapList", Native_GetExcludeMapList);
CreateNative("GetNominatedMapList", Native_GetNominatedMapList);
CreateNative("EndOfMapVoteEnabled", Native_EndOfMapVoteEnabled);
// MapChooser Extended natives
CreateNative("IsMapOfficial", Native_IsMapOfficial);
CreateNative("CanNominate", Native_CanNominate);
CreateNative("ExcludeMap", Native_ExcludeMap);
CreateNative("ExcludeMapTime", Native_ExcludeMapTime);
CreateNative("GetMapCooldown", Native_GetMapCooldown);
CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime);
CreateNative("GetMapMinTime", Native_GetMapMinTime);
CreateNative("GetMapMaxTime", Native_GetMapMaxTime);
CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers);
CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers);
CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction);
CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction);
CreateNative("GetMapGroups", Native_GetMapGroups);
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction);
CreateNative("GetExtendsLeft", Native_GetExtendsLeft);
CreateNative("AreRestrictionsActive", Native_AreRestrictionsActive);
CreateNative("SimulateMapEnd", Native_SimulateMapEnd);
// MapChooser Extended natives
CreateNative("IsMapOfficial", Native_IsMapOfficial);
CreateNative("CanNominate", Native_CanNominate);
CreateNative("ExcludeMap", Native_ExcludeMap);
CreateNative("ExcludeMapTime", Native_ExcludeMapTime);
CreateNative("GetMapCooldown", Native_GetMapCooldown);
CreateNative("GetMapCooldownTime", Native_GetMapCooldownTime);
CreateNative("GetMapMinTime", Native_GetMapMinTime);
CreateNative("GetMapMaxTime", Native_GetMapMaxTime);
CreateNative("GetMapMinPlayers", Native_GetMapMinPlayers);
CreateNative("GetMapMaxPlayers", Native_GetMapMaxPlayers);
CreateNative("GetMapTimeRestriction", Native_GetMapTimeRestriction);
CreateNative("GetMapPlayerRestriction", Native_GetMapPlayerRestriction);
CreateNative("GetMapGroups", Native_GetMapGroups);
CreateNative("GetMapGroupRestriction", Native_GetMapGroupRestriction);
CreateNative("GetMapVIPRestriction", Native_GetMapVIPRestriction);
CreateNative("GetExtendsLeft", Native_GetExtendsLeft);
CreateNative("AreRestrictionsActive", Native_AreRestrictionsActive);
CreateNative("SimulateMapEnd", Native_SimulateMapEnd);
CreateNative("GetAveragePlayerTimeOnServerMapRestriction", Native_GetAveragePlayerTimeOnServerMapRestriction);
return APLRes_Success;
return APLRes_Success;
}
public void OnMapStart()
@ -665,6 +669,12 @@ public Action Command_ReloadMaps(int client, int args)
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)
{
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);
}
//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)
{
int len;

View File

@ -360,100 +360,107 @@ public void OnNominationRemoved(const char[] map)
public Action Command_Addmap(int client, int args)
{
if(args == 0)
{
AttemptAdminNominate(client);
return Plugin_Handled;
}
if(args == 0)
{
AttemptAdminNominate(client);
return Plugin_Handled;
}
if(args != 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>");
return Plugin_Handled;
}
if(args != 1)
{
CReplyToCommand(client, "[NE] Usage: sm_nominate_addmap <mapname>");
return Plugin_Handled;
}
static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
static char mapname[PLATFORM_MAX_PATH];
GetCmdArg(1, mapname, sizeof(mapname));
if(!IsMapValid(mapname))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
AttemptAdminNominate(client, mapname);
return Plugin_Handled;
}
if(!IsMapValid(mapname))
{
CReplyToCommand(client, "%t", "Map was not found", mapname);
AttemptAdminNominate(client, mapname);
return Plugin_Handled;
}
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
{
bool RestrictionsActive = AreRestrictionsActive();
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
{
bool RestrictionsActive = AreRestrictionsActive();
int status;
if(GetTrieValue(g_mapTrie, mapname, status))
{
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
int status;
if(GetTrieValue(g_mapTrie, mapname, status))
{
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(mapname);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
}
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
int Cooldown = GetMapCooldown(mapname);
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown);
}
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated");
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated");
return Plugin_Handled;
}
}
return Plugin_Handled;
}
}
int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime())
{
int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime())
{
int Seconds = Cooldown - GetTime();
CPrintToChat(client, "[NE] %t", "Map Cooldown Time Error", Seconds / 3600, (Seconds % 3600) / 60);
return Plugin_Handled;
}
return Plugin_Handled;
}
int TimeRestriction = GetMapTimeRestriction(mapname);
if(RestrictionsActive && TimeRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
int TimeRestriction = GetMapTimeRestriction(mapname);
if(RestrictionsActive && TimeRestriction)
{
CPrintToChat(client, "[NE] %t", "Map Nominate Time Error", TimeRestriction / 60, TimeRestriction % 60);
return Plugin_Handled;
}
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);
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;
}
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)
{
/* 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);
NominateResult result = NominateMap(mapname, true, 0);
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);
LogAction(client, -1, "\"%L\" inserted map \"%s\".", client, mapname);
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
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)
@ -695,6 +702,13 @@ public Action Command_Nominate(int client, int args)
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);
if(RestrictionsActive && PlayerRestriction)
{
@ -1003,6 +1017,7 @@ Menu BuildMapMenu(const char[] filter, int client)
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, client)))
{
continue;
@ -1098,6 +1113,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
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() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
return ITEMDRAW_DISABLED;
@ -1258,6 +1275,13 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
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);
if(RestrictionsActive && PlayerRestriction)
{
@ -1352,6 +1376,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You cant nominate this map right now.");