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
@@ -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;