added native to leader to get if a client if one of the possible leaders. added to mapchooser that random picked maps respect cooldowns as well. changed so leaders and admins skip all cooldowns and restrictions

This commit is contained in:
jenz 2024-07-26 18:33:39 +02:00
parent 8b94b0fc45
commit 0115f8bfc2
4 changed files with 68 additions and 117 deletions

View File

@ -1439,6 +1439,7 @@ public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max
{ {
CreateNative("Leader_CurrentLeader", Native_CurrentLeader); CreateNative("Leader_CurrentLeader", Native_CurrentLeader);
CreateNative("Leader_SetLeader", Native_SetLeader); CreateNative("Leader_SetLeader", Native_SetLeader);
CreateNative("Leader_Is", Native_IsPossibleLeader);
return APLRes_Success; return APLRes_Success;
} }
@ -1457,6 +1458,13 @@ public int Native_SetLeader(Handle plugin, int numParams)
{ {
SetLeader(GetNativeCell(1)); SetLeader(GetNativeCell(1));
} }
//----------------------------------------------------------------------------------------------------
// Purpose:
//----------------------------------------------------------------------------------------------------
public int Native_IsPossibleLeader(Handle plugin, int numParams)
{
return IsPossibleLeader(GetNativeCell(1));
}
//---------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------
// Purpose: // Purpose:
@ -1595,4 +1603,4 @@ bool TracePlayerAngles(int client, float vecResult[3])
stock bool TraceEntityFilter_FilterPlayers(int entity, int contentsMask) stock bool TraceEntityFilter_FilterPlayers(int entity, int contentsMask)
{ {
return entity > MaxClients; return entity > MaxClients;
} }

View File

@ -15,3 +15,9 @@ native Leader_CurrentLeader();
* @param client Client index to be set as leader * @param client Client index to be set as leader
*/ */
native Leader_SetLeader(client); native Leader_SetLeader(client);
/**
* checks if client is possible leader
*
* @param client Client index to check if leader
*/
native Leader_Is(client);

View File

@ -55,6 +55,7 @@
#include <nominations_extended> #include <nominations_extended>
#include <rockthevote_extended> #include <rockthevote_extended>
#include <AFKManager> #include <AFKManager>
#include <leader>
#pragma semicolon 1 #pragma semicolon 1
#pragma newdecls required #pragma newdecls required
@ -1059,11 +1060,6 @@ public Handle get_most_nominated_maps(bool create_next_vote)
Handle most_nominated_maps = CreateArray(arraySize); Handle most_nominated_maps = CreateArray(arraySize);
StringMap sm = new StringMap(); StringMap sm = new StringMap();
//november 2023 edit: now the leader can nominate one map per map played that can skip requirements: Expectation is the leader will want to lead the map.
//if leaders abuse the feature they should simply be removed from the leader list file.
char MapleaderNominatedMap[PLATFORM_MAX_PATH];
GetMapleaderNominatedMap(MapleaderNominatedMap);
for (int i = 0; i < MaxClients; i++) for (int i = 0; i < MaxClients; i++)
{ {
for (int j = 0; j < GetArraySize(g_NominateList[i]); j++) for (int j = 0; j < GetArraySize(g_NominateList[i]); j++)
@ -1079,7 +1075,7 @@ public Handle get_most_nominated_maps(bool create_next_vote)
{ {
nominate_count_for_particular_map = 1999; nominate_count_for_particular_map = 1999;
} }
else if(StrEqual(map_iteration, MapleaderNominatedMap, false)) else if(Leader_Is(i))
{ {
nominate_count_for_particular_map = 999; nominate_count_for_particular_map = 999;
} }
@ -2024,6 +2020,9 @@ void CreateNextVote()
if(InternalGetMapVIPRestriction(map)) if(InternalGetMapVIPRestriction(map))
continue; continue;
if(InternalGetMapCooldownTime(map) > GetTime())
continue;
if(InternalGetMapTimeRestriction(map) != 0) if(InternalGetMapTimeRestriction(map) != 0)
continue; continue;

View File

@ -84,8 +84,6 @@ Handle g_Cvar_VIPTimeframeMaxTime = INVALID_HANDLE;
int g_Player_NominationDelay[MAXPLAYERS+1]; int g_Player_NominationDelay[MAXPLAYERS+1];
int g_NominationDelay; int g_NominationDelay;
int g_iMapleaderWhoNominatedMap = -1;
char g_cMapLeaderNominatedMap[256];
//clients ignoring maps that are unavailable //clients ignoring maps that are unavailable
bool g_bClientsIgnoring[MAXPLAYERS + 1]; bool g_bClientsIgnoring[MAXPLAYERS + 1];
@ -139,8 +137,6 @@ public void OnPluginStart()
public void OnMapStart() public void OnMapStart()
{ {
Format(g_cMapLeaderNominatedMap, sizeof(g_cMapLeaderNominatedMap), "");
g_iMapleaderWhoNominatedMap = -1;
if (!g_dDatabase) if (!g_dDatabase)
{ {
//we have too many dbs so i am just re-using racetimercss //we have too many dbs so i am just re-using racetimercss
@ -265,7 +261,6 @@ public APLRes AskPluginLoad2(Handle hThis, bool bLate, char[] err, int iErrLen)
CreateNative("PushMapsIntoNominationPool", Native_PushMapsIntoNominationPool); CreateNative("PushMapsIntoNominationPool", Native_PushMapsIntoNominationPool);
CreateNative("RemoveMapFromNominationPool", Native_RemoveMapFromNominationPool); CreateNative("RemoveMapFromNominationPool", Native_RemoveMapFromNominationPool);
CreateNative("RemoveMapsFromNominationPool", Native_RemoveMapsFromNominationPool); CreateNative("RemoveMapsFromNominationPool", Native_RemoveMapsFromNominationPool);
CreateNative("GetMapleaderNominatedMap", Native_GetMapleaderNominatedMap);
return APLRes_Success; return APLRes_Success;
} }
@ -375,29 +370,6 @@ public void OnNominationRemoved(const char[] map, int client)
/* Is the map in our list? */ /* Is the map in our list? */
if(!GetTrieValue(g_mapTrie, map, status)) if(!GetTrieValue(g_mapTrie, map, status))
return; return;
int newclient = 0;
//just differientiating between if nomination was removed because of starting vote or because of anything else possible.
if (client > 100)
{
newclient = client - 100;
}
else
{
newclient = client;
}
if (newclient == g_iMapleaderWhoNominatedMap && StrEqual(map, g_cMapLeaderNominatedMap, false))
{
if (client > 100)
{
CPrintToChatAll("{darkorange}[UNLOZE Nominations] {white}The map leader {lightgreen}%N {white}nomination {red}%s {white}was forced into the mapvote.", newclient, map);
}
else
{
CPrintToChatAll("{darkorange}[UNLOZE Nominations] {white}The map leader {lightgreen}%N {white}has removed his Mapleader nomination {red}%s", newclient, map);
}
Format(g_cMapLeaderNominatedMap, sizeof(g_cMapLeaderNominatedMap), "");
g_iMapleaderWhoNominatedMap = -1;
}
/* Was the map disabled due to being nominated */ /* Was the map disabled due to being nominated */
if((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED) if((status & MAPSTATUS_EXCLUDE_NOMINATED) != MAPSTATUS_EXCLUDE_NOMINATED)
return; return;
@ -706,37 +678,29 @@ public Action Command_Nominate(int client, int args)
return Plugin_Handled; return Plugin_Handled;
} }
bool RestrictionsActive = AreRestrictionsActive(); //July 2024 edit: any person who is potential leader can just skip all cooldowns and map restrictions. same for admins.
if(!CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_KICK, true) && !Leader_Is(client))
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{ {
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT) bool RestrictionsActive = AreRestrictionsActive();
ReplyToCommand(client, "Cant Nominate Current Map.");
//CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS) if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{ {
int Cooldown = GetMapCooldown(mapname); if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t (%d)", "Map in Exclude List", Cooldown); ReplyToCommand(client, "Cant Nominate Current Map.");
//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((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated");
return Plugin_Handled;
} }
if((status & MAPSTATUS_EXCLUDE_NOMINATED) == MAPSTATUS_EXCLUDE_NOMINATED)
CPrintToChat(client, "[NE] %t", "Map Already Nominated");
return Plugin_Handled;
}
int mapLeader = Leader_CurrentLeader();
//2023 November edit: one map nominated by mapleader will automatically go to the vote.
if (client == mapLeader && StrEqual(g_cMapLeaderNominatedMap, ""))
{
CPrintToChatAll("{darkorange}[UNLOZE Nominations] {white}The map leader {lightgreen}%N {white}has nominated the map {red}%s{white}. The map will be in the next mapvote.", client, mapname);
CPrintToChatAll("{lightblue}If the map is nextmap and the leader wont play it he will be removed from leader access.");
Format(g_cMapLeaderNominatedMap, sizeof(g_cMapLeaderNominatedMap), mapname);
g_iMapleaderWhoNominatedMap = client;
}
else
{
int Cooldown = GetMapCooldownTime(mapname); int Cooldown = GetMapCooldownTime(mapname);
if(RestrictionsActive && Cooldown > GetTime()) if(RestrictionsActive && Cooldown > GetTime())
{ {
@ -884,21 +848,13 @@ void AttemptNominate(int client, const char[] filter = "")
Menu menu = g_MapMenu; Menu menu = g_MapMenu;
menu = BuildMapMenu(filter, client); menu = BuildMapMenu(filter, client);
int mapLeader = Leader_CurrentLeader(); GetPlayerWorthRTV_(client);
if (client == mapLeader && StrEqual(g_cMapLeaderNominatedMap, "")) int nominate_worth = RoundToFloor(GetPlayerWorthRTV_boost_(client));
if (nominate_worth < 1)
{ {
SetMenuTitle(menu, "Nominate Map as Mapleader:", client); nominate_worth = 1;
}
else
{
GetPlayerWorthRTV_(client);
int nominate_worth = RoundToFloor(GetPlayerWorthRTV_boost_(client));
if (nominate_worth < 1)
{
nominate_worth = 1;
}
SetMenuTitle(menu, "%T", "Nominate Title", client, nominate_worth);
} }
SetMenuTitle(menu, "%T", "Nominate Title", client, nominate_worth);
DisplayMenu(menu, client, MENU_TIME_FOREVER); DisplayMenu(menu, client, MENU_TIME_FOREVER);
} }
@ -981,12 +937,12 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
int owner = GetArrayCell(OwnerList, i); int owner = GetArrayCell(OwnerList, i);
int nominate_count_for_particular_map = 0; int nominate_count_for_particular_map = 0;
sm.GetValue(map, nominate_count_for_particular_map); sm.GetValue(map, nominate_count_for_particular_map);
//if its console its admin nomination. if its g_iMapleaderWhoNominatedMap it was map nominated by leader, also has to be correct map out of 3. //if its console its admin nomination. if its nominated by leader it will also go to the vote just.
if (!owner) if (!owner)
{ {
nominate_count_for_particular_map = 1999; nominate_count_for_particular_map = 1999;
} }
else if(owner == g_iMapleaderWhoNominatedMap && StrEqual(map, g_cMapLeaderNominatedMap)) else if(Leader_Is(owner))
{ {
nominate_count_for_particular_map = 999; nominate_count_for_particular_map = 999;
} }
@ -1035,11 +991,9 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
if(!owner) if(!owner)
Format(display, sizeof(display), "%s (Admin)", display); Format(display, sizeof(display), "%s (Admin)", display);
else if (StrEqual(map, g_cMapLeaderNominatedMap)) else if (Leader_Is(owner))
{ {
char leadername[MAX_NAME_LENGTH]; Format(display, sizeof(display), "%s (Mapleader)", display);
GetClientName(g_iMapleaderWhoNominatedMap, leadername, MAX_NAME_LENGTH);
Format(display, sizeof(display), "%s (Mapleader %s)", display, leadername);
} }
else else
Format(display, sizeof(display), "%s (%i %s)", display, nominate_count_for_particular_map, spelling); Format(display, sizeof(display), "%s (%i %s)", display, nominate_count_for_particular_map, spelling);
@ -1213,24 +1167,18 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetClientName(param1, name, MAX_NAME_LENGTH); GetClientName(param1, name, MAX_NAME_LENGTH);
int mapLeader = Leader_CurrentLeader(); if(!CheckCommandAccess(param1, "sm_nominate_ignore", ADMFLAG_KICK, true) && !Leader_Is(param1))
//2023 November edit: one map nominated by mapleader will automatically go to the vote.
if (param1 == mapLeader && StrEqual(g_cMapLeaderNominatedMap, ""))
{ {
CPrintToChatAll("{darkorange}[UNLOZE Nominations] {white}The map leader {lightgreen}%N {white}has nominated the map {red}%s{white}. The map will be in the mapvote.", param1, map); if(AreRestrictionsActive() && (
CPrintToChatAll("{lightblue}If the map is nextmap and the leader wont play it he will be removed from leader access."); GetMapCooldownTime(map) > GetTime() ||
Format(g_cMapLeaderNominatedMap, sizeof(g_cMapLeaderNominatedMap), map); GetMapTimeRestriction(map) ||
g_iMapleaderWhoNominatedMap = param1; GetMapPlayerRestriction(map) ||
} GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
else if(AreRestrictionsActive() && ( GetMapVIPRestriction(map, param1)))
GetMapCooldownTime(map) > GetTime() || {
GetMapTimeRestriction(map) || PrintToChat(param1, "[NE] You cant nominate this map right now.");
GetMapPlayerRestriction(map) || return 0;
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 || }
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You cant nominate this map right now.");
return 0;
} }
NominateResult result = NominateMap(map, false, param1); NominateResult result = NominateMap(map, false, param1);
@ -1301,22 +1249,18 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
} }
} }
int mapLeader = Leader_CurrentLeader(); if(!CheckCommandAccess(param1, "sm_nominate_ignore", ADMFLAG_KICK, true) && !Leader_Is(param1))
if (param1 == mapLeader && StrEqual(g_cMapLeaderNominatedMap, ""))
{ {
return ITEMDRAW_DEFAULT; if(AreRestrictionsActive() && (
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
return ITEMDRAW_DISABLED;
}
} }
if(AreRestrictionsActive() && (
GetMapCooldownTime(map) > GetTime() ||
GetMapTimeRestriction(map) ||
GetMapPlayerRestriction(map) ||
GetAveragePlayerTimeOnServerMapRestriction(map) > 0 ||
GetMapVIPRestriction(map, param1)))
{
return ITEMDRAW_DISABLED;
}
return ITEMDRAW_DEFAULT; return ITEMDRAW_DEFAULT;
} }
@ -1663,12 +1607,6 @@ public int Native_RemoveMapsFromNominationPool(Handle plugin, int numArgs)
return 0; return 0;
} }
public int Native_GetMapleaderNominatedMap(Handle plugin, int numArgs)
{
SetNativeString(1, g_cMapLeaderNominatedMap, sizeof(g_cMapLeaderNominatedMap), true);
return 0;
}
stock int GetVIPTimeRestriction() stock int GetVIPTimeRestriction()
{ {
if (!GetConVarBool(g_Cvar_VIPTimeframe)) if (!GetConVarBool(g_Cvar_VIPTimeframe))