rehawl of mapchooser so clients can have multiple nominations where the maps with most nominations get into the vote

This commit is contained in:
jenz 2023-01-27 21:07:48 +01:00
parent 1c851906db
commit 987c643838
2 changed files with 1288 additions and 1145 deletions

333
mapchooser_extended/scripting/mapchooser_extended.sp Normal file → Executable file
View File

@ -92,8 +92,6 @@ ConVar g_Cvar_Winlimit;
ConVar g_Cvar_Maxrounds;
ConVar g_Cvar_Fraglimit;
ConVar g_Cvar_Bonusroundtime;
ConVar g_Cvar_MatchClinch;
ConVar g_Cvar_VoteNextLevel;
ConVar g_Cvar_GameType;
ConVar g_Cvar_GameMode;
@ -120,7 +118,7 @@ Handle g_WarningTimer = INVALID_HANDLE;
/* Data Handles */
Handle g_MapList = INVALID_HANDLE;
Handle g_NominateList = INVALID_HANDLE;
Handle g_NominateList[MAXPLAYERS + 1];
Handle g_NominateOwners = INVALID_HANDLE;
StringMap g_OldMapList;
StringMap g_TimeMapList;
@ -215,6 +213,25 @@ enum WarningType
#define LINE_SPACER "##linespacer##"
#define FAILURE_TIMER_LENGTH 5
//call forward to reset all nominations
public void OnPluginEnd()
{
for (int i = 0; i < MaxClients; i++)
{
int index = FindValueInArray(g_NominateOwners, i);
if (index == -1) continue;
for (int j = 0; j < GetArraySize(g_NominateList[i]); j++)
{
char oldmap[PLATFORM_MAX_PATH];
Call_StartForward(g_NominationsResetForward);
GetArrayString(g_NominateList[i], j, oldmap, PLATFORM_MAX_PATH);
Call_PushString(oldmap);
Call_PushCell(GetArrayCell(g_NominateOwners, index));
Call_Finish();
}
}
}
public void OnPluginStart()
{
LoadTranslations("mapchooser_extended.phrases");
@ -223,13 +240,17 @@ public void OnPluginStart()
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
g_MapList = CreateArray(arraySize);
g_NominateList = CreateArray(arraySize);
g_NominateOwners = CreateArray(1);
g_OldMapList = new StringMap();
g_TimeMapList = new StringMap();
g_NextMapList = CreateArray(arraySize);
g_OfficialList = CreateArray(arraySize);
for (int i = 0; i < MaxClients; i++)
{
g_NominateList[i] = CreateArray(arraySize);
}
GetGameFolderName(g_GameModName, sizeof(g_GameModName));
g_Cvar_EndOfMapVote = CreateConVar("mce_endvote", "1", "Specifies if MapChooser should run an end of map vote", _, true, 0.0, true, 1.0);
@ -246,7 +267,7 @@ public void OnPluginStart()
g_Cvar_IncludeMapsReserved = CreateConVar("mce_include_reserved", "2", "Specifies how many private/random maps to include in the vote.", _, true, 0.0, true, 5.0);
g_Cvar_NoVoteMode = CreateConVar("mce_novote", "1", "Specifies whether or not MapChooser should pick a map if no votes are received.", _, true, 0.0, true, 1.0);
g_Cvar_Extend = CreateConVar("mce_extend", "0", "Number of extensions allowed each map.", _, true, 0.0);
g_Cvar_DontChange = CreateConVar("mce_dontchange", "1", "Specifies if a 'Don't Change' option should be added to early votes", _, true, 0.0);
g_Cvar_DontChange = CreateConVar("mce_dontchange", "1", "Specifies if a 'Don't Change option should be added to early votes", _, true, 0.0);
g_Cvar_VoteDuration = CreateConVar("mce_voteduration", "20", "Specifies how long the mapvote should be available for.", _, true, 5.0);
// MapChooser Extended cvars
@ -263,7 +284,7 @@ public void OnPluginStart()
g_Cvar_RunOffWarningTime = CreateConVar("mce_runoffvotewarningtime", "5.0", "Warning time for runoff vote in seconds.", _, true, 0.0, true, 30.0);
g_Cvar_TimerLocation = CreateConVar("mce_warningtimerlocation", "0", "Location for the warning timer text. 0 is HintBox, 1 is Center text, 2 is Chat. Defaults to HintBox.", _, true, 0.0, true, 2.0);
g_Cvar_MarkCustomMaps = CreateConVar("mce_markcustommaps", "1", "Mark custom maps in the vote list. 0 = Disabled, 1 = Mark with *, 2 = Mark with phrase.", _, true, 0.0, true, 2.0);
g_Cvar_ExtendPosition = CreateConVar("mce_extendposition", "0", "Position of Extend/Don't Change options. 0 = at end, 1 = at start.", _, true, 0.0, true, 1.0);
g_Cvar_ExtendPosition = CreateConVar("mce_extendposition", "0", "Position of Extend/Dont Change options. 0 = at end, 1 = at start.", _, true, 0.0, true, 1.0);
g_Cvar_RandomizeNominations = CreateConVar("mce_randomizeorder", "0", "Randomize map order?", _, true, 0.0, true, 1.0);
g_Cvar_HideTimer = CreateConVar("mce_hidetimer", "0", "Hide the MapChooser Extended warning timer", _, true, 0.0, true, 1.0);
g_Cvar_NoVoteOption = CreateConVar("mce_addnovote", "1", "Add \"No Vote\" to vote menu?", _, true, 0.0, true, 1.0);
@ -296,13 +317,11 @@ public void OnPluginStart()
{
case Engine_TF2:
{
g_Cvar_VoteNextLevel = FindConVar("sv_vote_issue_nextlevel_allowed");
g_Cvar_Bonusroundtime = FindConVar("mp_bonusroundtime");
}
case Engine_CSGO:
{
g_Cvar_VoteNextLevel = FindConVar("mp_endmatch_votenextmap");
g_Cvar_GameType = FindConVar("game_type");
g_Cvar_GameMode = FindConVar("game_mode");
g_Cvar_Bonusroundtime = FindConVar("mp_round_restart_delay");
@ -324,8 +343,6 @@ public void OnPluginStart()
}
}
if(g_Cvar_Winlimit != INVALID_HANDLE || g_Cvar_Maxrounds != INVALID_HANDLE)
{
switch(version)
{
case Engine_TF2:
@ -346,7 +363,6 @@ public void OnPluginStart()
HookEvent("round_end", Event_RoundEnd);
HookEvent("cs_intermission", Event_Intermission);
HookEvent("announce_phase_end", Event_PhaseEnd);
g_Cvar_MatchClinch = FindConVar("mp_match_can_clinch");
}
case Engine_DODS:
@ -359,16 +375,13 @@ public void OnPluginStart()
HookEvent("round_end", Event_RoundEnd);
}
}
}
if(g_Cvar_Fraglimit != INVALID_HANDLE)
HookEvent("player_death", Event_PlayerDeath);
AutoExecConfig(true, "mapchooser_extended");
//Change the mp_bonusroundtime max so that we have time to display the vote
//If you display a vote during bonus time good defaults are 17 vote duration and 19 mp_bonustime
if(g_Cvar_Bonusroundtime != INVALID_HANDLE)
SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);
g_NominationsResetForward = CreateGlobalForward("OnNominationRemoved", ET_Ignore, Param_String, Param_Cell);
@ -488,11 +501,6 @@ public void OnConfigsExecuted()
LogError("Unable to create a valid map list.");
}
// Disable the next level vote in TF2 and CS:GO
// In TF2, this has two effects: 1. Stop the next level vote (which overlaps rtv functionality).
// 2. Stop the built-in end level vote. This is the only thing that happens in CS:GO
if(g_Cvar_VoteNextLevel != INVALID_HANDLE)
SetConVarBool(g_Cvar_VoteNextLevel, false);
SetupTimeleftTimer();
@ -504,14 +512,21 @@ public void OnConfigsExecuted()
g_NominateCount = 0;
g_NominateReservedCount = 0;
ClearArray(g_NominateList);
for (int i = 0; i < MaxClients; i++)
{
if (g_NominateList[i] != INVALID_HANDLE)
{
ClearArray(g_NominateList[i]);
}
}
ClearArray(g_NominateOwners);
for(int i = 0; i < MAXTEAMS; i++)
g_winCount[i] = 0;
/* Check if mapchooser will attempt to start mapvote during bonus round time */
if((g_Cvar_Bonusroundtime != INVALID_HANDLE) && !GetConVarInt(g_Cvar_StartRounds))
if (!GetConVarInt(g_Cvar_StartRounds))
{
if(!GetConVarInt(g_Cvar_StartTime) && GetConVarFloat(g_Cvar_Bonusroundtime) <= GetConVarFloat(g_Cvar_VoteDuration))
LogError("Warning - Bonus Round Time shorter than Vote Time. Votes during bonus round may not have time to complete");
@ -576,6 +591,10 @@ public void OnMapEnd()
public void OnClientPutInServer(int client)
{
if (g_NominateList[client] != INVALID_HANDLE)
{
ClearArray(g_NominateList[client]);
}
CheckMapRestrictions(false, true);
}
@ -591,15 +610,24 @@ public void OnClientDisconnect(int client)
if(index == -1)
return;
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH);
//2023 edit for handling multiple nominations -jenz
for (int i = 0; i < GetArraySize(g_NominateList[client]); i++)
{
Call_StartForward(g_NominationsResetForward);
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList[client], i, oldmap, PLATFORM_MAX_PATH);
Call_PushString(oldmap);
Call_PushCell(GetArrayCell(g_NominateOwners, index));
Call_Finish();
}
RemoveFromArray(g_NominateOwners, index);
RemoveFromArray(g_NominateList, index);
for (int i = 0; i < GetArraySize(g_NominateList[client]); i++)
{
RemoveFromArray(g_NominateList[client], i);
}
ClearArray(g_NominateList[client]);
g_NominateCount--;
}
@ -897,8 +925,6 @@ public void Event_RoundEnd(Handle event, const char[] name, bool dontBroadcast)
}
public void CheckWinLimit(int winner_score)
{
if(g_Cvar_Winlimit != INVALID_HANDLE)
{
int winlimit = GetConVarInt(g_Cvar_Winlimit);
if(winlimit)
@ -914,27 +940,6 @@ public void CheckWinLimit(int winner_score)
}
}
if(g_Cvar_MatchClinch != INVALID_HANDLE && g_Cvar_Maxrounds != INVALID_HANDLE)
{
bool clinch = GetConVarBool(g_Cvar_MatchClinch);
if(clinch)
{
int maxrounds = GetConVarInt(g_Cvar_Maxrounds);
int winlimit = RoundFloat(maxrounds / 2.0);
if(winner_score == winlimit - 1)
{
if(!g_WarningInProgress || g_WarningTimer == INVALID_HANDLE)
{
SetupWarningTimer(WarningType_Vote, MapChange_MapEnd);
//InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
}
}
}
}
}
public void CheckMaxRounds(int roundcount)
{
int maxrounds = 0;
@ -943,8 +948,6 @@ public void CheckMaxRounds(int roundcount)
maxrounds = GameRules_GetProp("m_iNumGunGameProgressiveWeaponsCT");
else if(g_RoundCounting == RoundCounting_MvM)
maxrounds = GetEntProp(g_ObjectiveEnt, Prop_Send, "m_nMannVsMachineMaxWaveCount");
else if(g_Cvar_Maxrounds != INVALID_HANDLE)
maxrounds = GetConVarInt(g_Cvar_Maxrounds);
else
return;
@ -961,21 +964,21 @@ public void CheckMaxRounds(int roundcount)
}
}
public void Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast)
public Action Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcast)
{
if(!GetArraySize(g_MapList) || g_Cvar_Fraglimit == INVALID_HANDLE || g_HasVoteStarted)
return;
if(!GetArraySize(g_MapList) || g_HasVoteStarted)
return Plugin_Continue;
if(!GetConVarInt(g_Cvar_Fraglimit) || !GetConVarBool(g_Cvar_EndOfMapVote))
return;
return Plugin_Continue;
if(g_MapVoteCompleted)
return;
return Plugin_Continue;
int fragger = GetClientOfUserId(GetEventInt(event, "attacker"));
if(!fragger)
return;
return Plugin_Continue;
if(GetClientFrags(fragger) >= (GetConVarInt(g_Cvar_Fraglimit) - GetConVarInt(g_Cvar_StartFrags)))
{
@ -985,6 +988,7 @@ public void Event_PlayerDeath(Handle event, const char[] name, bool dontBroadcas
//InitiateVote(MapChange_MapEnd, INVALID_HANDLE);
}
}
return Plugin_Continue;
}
public Action Command_Mapvote(int client, int args)
@ -998,6 +1002,68 @@ public Action Command_Mapvote(int client, int args)
return Plugin_Handled;
}
public Handle get_most_nominated_maps()
{
int voteSize = GetVoteSize(2);
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
Handle most_nominated_maps = CreateArray(arraySize);
StringMap sm = new StringMap();
for (int i = 0; i < MaxClients; i++)
{
for (int j = 0; j < GetArraySize(g_NominateList[i]); j++)
{
char map_iteration[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList[i], j, map_iteration, PLATFORM_MAX_PATH);
//PrintToChatAll("map_iteration: %s", map_iteration);
int nominate_count_for_particular_map = 0;
sm.GetValue(map_iteration, nominate_count_for_particular_map);
nominate_count_for_particular_map++;
sm.SetValue(map_iteration, nominate_count_for_particular_map, true);
}
}
for (int i = 0; i < voteSize; i++)
{
int max_count = 0;
char picked_map[PLATFORM_MAX_PATH];
StringMapSnapshot keys = sm.Snapshot();
for (int j = 0; j < keys.Length; j++)
{
int size = keys.KeyBufferSize(j);
char[] buffer = new char[size];
keys.GetKey(j, buffer, size);
//PrintToChatAll("buffer: %s", buffer);
if (StrEqual(buffer, "nominated_maps"))
{
continue;
}
int value = 0;
sm.GetValue(buffer, value);
//PrintToChatAll("value: %i", value);
//first selection has most nominates, second selection second most etc etc
if (value >= max_count)
{
max_count = value;
strcopy(picked_map, sizeof(picked_map), buffer);
}
}
delete keys;
if (strlen(picked_map) == 0)
{
continue;
}
sm.Remove(picked_map);
PushArrayString(most_nominated_maps, picked_map);
//PrintToChatAll("picked_map: %s", picked_map);
}
delete sm;
return most_nominated_maps;
}
/**
* Starts a new map vote
*
@ -1014,7 +1080,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
// Check if a vote is in progress first
if(IsVoteInProgress())
{
// Can't start a vote, try again in 5 seconds.
// Cant start a vote, try again in 5 seconds.
//g_RetryTimer = CreateTimer(5.0, Timer_StartMapVote, _, TIMER_FLAG_NO_MAPCHANGE);
CPrintToChatAll("[MCE] %t", "Cannot Start Vote", FAILURE_TIMER_LENGTH);
@ -1097,12 +1163,16 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
if(inputlist == INVALID_HANDLE)
{
Handle randomizeList = INVALID_HANDLE;
//2023 edit to allow multiple nominations per player
Handle most_nominated_maps = get_most_nominated_maps();
int voteSize = GetVoteSize(2); //voteSize wrong size probably for my for loop
if(GetConVarBool(g_Cvar_RandomizeNominations))
randomizeList = CloneArray(g_NominateList);
randomizeList = CloneArray(most_nominated_maps);
int nominateCount = GetArraySize(g_NominateList);
int nominateCount = GetArraySize(most_nominated_maps);
int voteSize = GetVoteSize(2);
/* Smaller of the two - It should be impossible for nominations to exceed the size though (cvar changed mid-map?) */
int nominationsToAdd = nominateCount >= voteSize ? voteSize : nominateCount;
@ -1116,7 +1186,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
for(int i = 0; i < nominationsToAdd; i++)
{
GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH);
GetArrayString(most_nominated_maps, i, map, PLATFORM_MAX_PATH);
if(randomizeList == INVALID_HANDLE)
AddMapItem(map);
@ -1133,7 +1203,8 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
/* Clear out the rest of the nominations array */
for(int i = nominationsToAdd; i < nominateCount; i++)
{
GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH);
//2023 edit: might need to run all g_NominateList[client] through this instead
GetArrayString(most_nominated_maps, i, map, PLATFORM_MAX_PATH);
/* These maps shouldn't be excluded from the vote as they weren't really nominated at all */
/* Notify Nominations that this map is now free */
@ -1199,13 +1270,18 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
delete randomizeList;
randomizeList = INVALID_HANDLE;
delete most_nominated_maps;
most_nominated_maps = INVALID_HANDLE;
}
/* Wipe out our nominations list - Nominations have already been informed of this */
g_NominateCount = 0;
g_NominateReservedCount = 0;
ClearArray(g_NominateOwners);
ClearArray(g_NominateList);
for (int j = 0; j < MaxClients; j++)
{
ClearArray(g_NominateList[j]);
}
if(!extendFirst) {
AddExtendToMenu(g_VoteMenu, when);
@ -1227,7 +1303,7 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
// New in Mapchooser Extended
else if(StrEqual(map, VOTE_DONTCHANGE))
{
AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Don't Change");
AddMenuItem(g_VoteMenu, VOTE_DONTCHANGE, "Dont Change");
}
else if(StrEqual(map, VOTE_EXTEND))
{
@ -1288,32 +1364,23 @@ public void Handler_VoteFinishedGeneric(Handle menu,
ExtendMapTimeLimit(GetConVarInt(g_Cvar_ExtendTimeStep)*60);
}
if(g_Cvar_Winlimit != INVALID_HANDLE)
{
int winlimit = GetConVarInt(g_Cvar_Winlimit);
if(winlimit)
SetConVarInt(g_Cvar_Winlimit, winlimit + GetConVarInt(g_Cvar_ExtendRoundStep));
}
if(g_Cvar_Maxrounds != INVALID_HANDLE)
{
int maxrounds = GetConVarInt(g_Cvar_Maxrounds);
if(maxrounds)
SetConVarInt(g_Cvar_Maxrounds, maxrounds + GetConVarInt(g_Cvar_ExtendRoundStep));
}
if(g_Cvar_Fraglimit != INVALID_HANDLE)
{
int fraglimit = GetConVarInt(g_Cvar_Fraglimit);
if(fraglimit)
SetConVarInt(g_Cvar_Fraglimit, fraglimit + GetConVarInt(g_Cvar_ExtendFragStep));
}
CPrintToChatAll("[MCE] %t", "Current Map Extended", RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0), num_votes);
LogAction(-1, -1, "Voting for next map has finished. The current map has been extended.");
CPrintToChatAll("[MCE] Available Extends: %d", GetConVarInt(g_Cvar_Extend) - g_Extends);
// We extended, so we'll have to vote again.
// We extended, so well have to vote again.
g_RunoffCount = 0;
g_HasVoteStarted = false;
SetupTimeleftTimer();
@ -1624,9 +1691,12 @@ void CreateNextVote()
// populate groupmap with maps from nomination list
static char map_[PLATFORM_MAX_PATH];
int groups_[32];
for(int i = 0; i < GetArraySize(g_NominateList); i++)
//2023 edit
Handle most_nominated_maps = get_most_nominated_maps();
for(int i = 0; i < GetArraySize(most_nominated_maps); i++)
{
GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH);
GetArrayString(most_nominated_maps, i, map_, PLATFORM_MAX_PATH);
int groupsfound = InternalGetMapGroups(map_, groups_, sizeof(groups_));
for(int group = 0; group < groupsfound; group++)
{
@ -1699,63 +1769,75 @@ bool CanVoteStart()
{
if(g_WaitingForVote || g_HasVoteStarted)
return false;
return true;
}
NominateResult InternalNominateMap(char[] map, bool force, int owner)
NominateResult InternalNominateMap(char[] map, int owner)
{
if(!IsMapValid(map))
{
return Nominate_InvalidMap;
}
/* Map already in the vote */
if(FindStringInArray(g_NominateList, map) != -1)
{
return Nominate_AlreadyInVote;
}
int index;
/* Look to replace an existing nomination by this client - Nominations made with owner = 0 aren't replaced */
if(owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1))
/* Look to replace an existing nomination by this client - Nominations made with owner = 0 arent replaced */
//2023 edit: change clients first nomination out of the clients multiple nominations, make a check if client filled all his nomination slots
//currently hard coded to 3 maps, just add a cvar to replace it with in the future
if(owner && ((FindValueInArray(g_NominateOwners, owner)) != -1) && GetArraySize(g_NominateList[owner]) > 2)
{
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH);
GetArrayString(g_NominateList[owner], 0, oldmap, PLATFORM_MAX_PATH);
Call_StartForward(g_NominationsResetForward);
Call_PushString(oldmap);
Call_PushCell(owner);
Call_Finish();
SetArrayString(g_NominateList, index, map);
RemoveFromArray(g_NominateList[owner], 0);
PushArrayString(g_NominateList[owner], map);
return Nominate_Replaced;
}
/* Too many nominated maps. */
//2023 edit: we dont want this check
/*
if(g_NominateCount >= GetVoteSize(0) && !force)
{
return Nominate_VoteFull;
}
*/
PushArrayString(g_NominateList, map);
PushArrayCell(g_NominateOwners, owner);
if (owner != 0)
{
for (int j = 0; j < GetArraySize(g_NominateList[owner]); j++)
{
char map_iteration[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList[owner], j, map_iteration, PLATFORM_MAX_PATH);
if (StrEqual(map, map_iteration, false))
{
return Nominate_InvalidMap;
}
}
}
PushArrayString(g_NominateList[owner], map);
PushArrayCell(g_NominateOwners, owner); //maybe i only want to do this for the first nomination of each client
if(owner == 0 && g_NominateReservedCount < GetVoteSize(1))
g_NominateReservedCount++;
else
g_NominateCount++;
while(GetArraySize(g_NominateList) > GetVoteSize(2))
while(GetArraySize(g_NominateList[owner]) > GetVoteSize(2))
{
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, 0, oldmap, PLATFORM_MAX_PATH);
GetArrayString(g_NominateList[owner], 0, oldmap, PLATFORM_MAX_PATH);
Call_StartForward(g_NominationsResetForward);
Call_PushString(oldmap);
int owner_ = GetArrayCell(g_NominateOwners, 0);
Call_PushCell(owner_);
Call_Finish();
RemoveFromArray(g_NominateList, 0);
RemoveFromArray(g_NominateList[owner], 0);
RemoveFromArray(g_NominateOwners, 0);
if(owner_ == 0)
g_NominateReservedCount--;
@ -1780,15 +1862,17 @@ public int Native_NominateMap(Handle plugin, int numParams)
char[] map = new char[len+1];
GetNativeString(1, map, len+1);
return view_as<int>(InternalNominateMap(map, GetNativeCell(2), GetNativeCell(3)));
return view_as<int>(InternalNominateMap(map, GetNativeCell(3)));
}
bool InternalRemoveNominationByMap(char[] map)
{
for(int i = 0; i < GetArraySize(g_NominateList); i++)
for (int client = 0; client < MaxClients; client++)
{
for(int i = 0; i < GetArraySize(g_NominateList[client]); i++)
{
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, i, oldmap, PLATFORM_MAX_PATH);
GetArrayString(g_NominateList[client], i, oldmap, PLATFORM_MAX_PATH);
if(strcmp(map, oldmap, false) == 0)
{
@ -1803,13 +1887,13 @@ bool InternalRemoveNominationByMap(char[] map)
else
g_NominateReservedCount--;
RemoveFromArray(g_NominateList, i);
RemoveFromArray(g_NominateList[client], i);
RemoveFromArray(g_NominateOwners, i);
return true;
}
}
}
return false;
}
@ -1835,14 +1919,15 @@ bool InternalRemoveNominationByOwner(int owner)
if(owner && ((index = FindValueInArray(g_NominateOwners, owner)) != -1))
{
char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH);
GetArrayString(g_NominateList[owner], index, oldmap, PLATFORM_MAX_PATH);
Call_StartForward(g_NominationsResetForward);
Call_PushString(oldmap);
Call_PushCell(owner);
Call_Finish();
RemoveFromArray(g_NominateList, index);
RemoveFromArray(g_NominateList[owner], index);
//maybe only do once or change g_NominateOwners
RemoveFromArray(g_NominateOwners, index);
g_NominateCount--;
@ -1911,16 +1996,19 @@ public int Native_GetNominatedMapList(Handle plugin, int numParams)
static char map[PLATFORM_MAX_PATH];
for(int i = 0; i < GetArraySize(g_NominateList); i++)
for (int client = 0; client < MaxClients; client++)
{
GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH);
for(int i = 0; i < GetArraySize(g_NominateList[client]); i++)
{
GetArrayString(g_NominateList[client], i, map, PLATFORM_MAX_PATH);
PushArrayString(maparray, map);
// If the optional parameter for an owner list was passed, then we need to fill that out as well
if(ownerarray != INVALID_HANDLE)
{
int index = GetArrayCell(g_NominateOwners, i);
PushArrayCell(ownerarray, index);
//int index = GetArrayCell(g_NominateOwners, i);
PushArrayCell(ownerarray, client);
}
}
}
}
@ -2295,14 +2383,24 @@ public int Native_GetMapGroupRestriction(Handle plugin, int numParams)
if(groupmax >= 0)
{
static char map_[PLATFORM_MAX_PATH];
char kv_map[PLATFORM_MAX_PATH];
int groups_[32];
for(int i = 0; i < GetArraySize(g_NominateList); i++)
KeyValues kv = CreateKeyValues("cur_groups");
for (int clienti = 0; clienti < MaxClients; clienti++)
{
GetArrayString(g_NominateList, i, map_, PLATFORM_MAX_PATH);
for(int i = 0; i < GetArraySize(g_NominateList[clienti]); i++)
{
GetArrayString(g_NominateList[clienti], i, map_, PLATFORM_MAX_PATH);
int tmp = InternalGetMapGroups(map_, groups_, sizeof(groups_));
if(FindIntInArray(groups_, tmp, groups[group]) != -1)
kv.GetString(map_, kv_map, sizeof(kv_map), "not_found");
if(FindIntInArray(groups_, tmp, groups[group]) != -1 && StrEqual(kv_map, "not_found"))
{
groupcur++;
kv.SetString(map_, map_);
}
}
}
delete kv;
if(groupcur >= groupmax)
{
@ -2314,7 +2412,7 @@ public int Native_GetMapGroupRestriction(Handle plugin, int numParams)
if(index != -1)
{
static char oldmap[PLATFORM_MAX_PATH];
GetArrayString(g_NominateList, index, oldmap, PLATFORM_MAX_PATH);
GetArrayString(g_NominateList[client], index, oldmap, PLATFORM_MAX_PATH);
static int oldgroups[32];
int tmp = InternalGetMapGroups(oldmap, oldgroups, sizeof(oldgroups));
if(FindIntInArray(groups_, tmp, groups[group]) != -1)
@ -2390,8 +2488,8 @@ stock void AddExtendToMenu(Handle menu, MapChange when)
if((when == MapChange_Instant || when == MapChange_RoundEnd) && GetConVarBool(g_Cvar_DontChange))
{
// Built-in votes doesn't have "Don't Change", send Extend instead
AddMenuItem(menu, VOTE_DONTCHANGE, "Don't Change");
// Built-in votes doesnt have "Dont Change", send Extend instead
AddMenuItem(menu, VOTE_DONTCHANGE, "Dont Change");
}
else if(GetConVarBool(g_Cvar_Extend) && g_Extends < GetConVarInt(g_Cvar_Extend))
{
@ -2452,17 +2550,15 @@ void CheckMapRestrictions(bool time = false, bool players = false)
return;
static char map[PLATFORM_MAX_PATH];
for(int i = 0; i < GetArraySize(g_NominateList); i++)
{
int client = GetArrayCell(g_NominateOwners, i);
if(!client)
continue;
for (int client = 0; client < MaxClients; client++)
{
if(CheckCommandAccess(client, "sm_nominate_ignore", ADMFLAG_CHEATS, true))
continue;
for (int i = 0; i < GetArraySize(g_NominateList[client]); i++)
{
bool remove;
GetArrayString(g_NominateList, i, map, PLATFORM_MAX_PATH);
GetArrayString(g_NominateList[client], i, map, PLATFORM_MAX_PATH);
if (time)
{
@ -2496,12 +2592,13 @@ void CheckMapRestrictions(bool time = false, bool players = false)
Call_PushCell(GetArrayCell(g_NominateOwners, i));
Call_Finish();
RemoveFromArray(g_NominateList, i);
RemoveFromArray(g_NominateList[client], i);
RemoveFromArray(g_NominateOwners, i);
g_NominateCount--;
}
}
}
}
stock int InternalGetMapMinTime(const char[] map)
{

96
mapchooser_extended/scripting/nominations_extended.sp Normal file → Executable file
View File

@ -187,14 +187,7 @@ public void OnConfigsExecuted()
void UpdateMapMenus()
{
if(g_MapMenu != INVALID_HANDLE)
delete g_MapMenu;
g_MapMenu = BuildMapMenu("");
if(g_AdminMapMenu != INVALID_HANDLE)
delete g_AdminMapMenu;
g_MapMenu = BuildMapMenu("", 0);
g_AdminMapMenu = BuildAdminMapMenu("");
}
@ -244,7 +237,6 @@ void UpdateMapTrie()
public void OnNominationRemoved(const char[] map, int owner)
{
int status;
/* Is the map in our list? */
if(!GetTrieValue(g_mapTrie, map, status))
return;
@ -290,7 +282,7 @@ public Action Command_Addmap(int client, int args)
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map");
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
@ -345,7 +337,7 @@ public Action Command_Addmap(int client, int args)
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 can't be full */
/* 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;
@ -388,7 +380,7 @@ public Action Command_Removemap(int client, int args)
if(!RemoveNominationByMap(mapname))
{
CReplyToCommand(client, "This map isn't nominated.", mapname);
CReplyToCommand(client, "This map isnt nominated.", mapname);
return Plugin_Handled;
}
@ -561,7 +553,7 @@ public Action Command_Nominate(int client, int args)
if((status & MAPSTATUS_DISABLED) == MAPSTATUS_DISABLED)
{
if((status & MAPSTATUS_EXCLUDE_CURRENT) == MAPSTATUS_EXCLUDE_CURRENT)
CPrintToChat(client, "[NE] %t", "Can't Nominate Current Map");
CPrintToChat(client, "[NE] %t", "Cant Nominate Current Map");
if(RestrictionsActive && (status & MAPSTATUS_EXCLUDE_PREVIOUS) == MAPSTATUS_EXCLUDE_PREVIOUS)
{
@ -620,6 +612,11 @@ public Action Command_Nominate(int client, int args)
NominateResult result = NominateMap(mapname, false, client);
if (result == Nominate_InvalidMap)
{
CPrintToChat(client, "[NE] %t", "You already nominated the map ", mapname);
return Plugin_Handled;
}
if(result > Nominate_Replaced)
{
if(result == Nominate_AlreadyInVote)
@ -632,7 +629,7 @@ public Action Command_Nominate(int client, int args)
/* Map was nominated! - Disable the menu item and update the trie */
SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
//SetTrieValue(g_mapTrie, mapname, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
static char name[MAX_NAME_LENGTH];
GetClientName(client, name, sizeof(name));
@ -705,8 +702,7 @@ void AttemptNominate(int client, const char[] filter = "")
return;
Menu menu = g_MapMenu;
if(filter[0])
menu = BuildMapMenu(filter);
menu = BuildMapMenu(filter, client);
SetMenuTitle(menu, "%T", "Nominate Title", client);
DisplayMenu(menu, client, MENU_TIME_FOREVER);
@ -786,11 +782,36 @@ bool PopulateNominateListMenu(Menu menu, int client, const char[] filter = "")
return true;
}
Menu BuildMapMenu(const char[] filter)
Menu BuildMapMenu(const char[] filter, int client)
{
Menu menu = CreateMenu(Handler_MapSelectMenu, MENU_ACTIONS_DEFAULT|MenuAction_DrawItem|MenuAction_DisplayItem);
static char map[PLATFORM_MAX_PATH];
static char map[PLATFORM_MAX_PATH * 2];
int arraySize = ByteCountToCells(PLATFORM_MAX_PATH);
ArrayList MapList = CreateArray(arraySize);
ArrayList OwnerList = CreateArray();
StringMap sm = new StringMap();
GetNominatedMapList(MapList, OwnerList);
bool nominated_maps = true;
if (!GetArraySize(MapList))
{
nominated_maps = false;
}
if (client != 0 && nominated_maps)
{
for(int j = 0; j < GetArraySize(MapList); j++)
{
int owner = GetArrayCell(OwnerList, j);
if (client == owner)
{
GetArrayString(MapList, j, map, sizeof(map));
sm.SetValue(map, 1);
}
}
}
for(int i = 0; i < GetArraySize(g_MapList); i++)
{
@ -798,10 +819,24 @@ Menu BuildMapMenu(const char[] filter)
if(!filter[0] || StrContains(map, filter, false) != -1)
{
if (client != 0 && nominated_maps)
{
int map_present = 0;
sm.GetValue(map, map_present);
if (map_present == 1)
{
//PrintToChatAll("client %N here. map: %s", client, map);
StrCat(map, sizeof(map), " (Nominated)");
}
}
AddMenuItem(menu, map, map);
}
}
delete MapList;
delete OwnerList;
delete sm;
SetMenuExitButton(menu, true);
return menu;
@ -845,8 +880,10 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
case MenuAction_End:
{
if (menu != g_MapMenu)
{
delete menu;
}
}
case MenuAction_Select:
{
if(g_Player_NominationDelay[param1] > GetTime())
@ -869,13 +906,19 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
GetMapGroupRestriction(map, param1) >= 0 ||
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You can't nominate this map right now.");
PrintToChat(param1, "[NE] You cant nominate this map right now.");
return 0;
}
NominateResult result = NominateMap(map, false, param1);
/* Don't need to check for InvalidMap because the menu did that already */
if (result == Nominate_InvalidMap)
{
PrintToChat(param1, "[NE] You already nominated the map %s", map);
return 0;
}
/* Dont need to check for InvalidMap because the menu did that already */
if(result == Nominate_AlreadyInVote)
{
PrintToChat(param1, "[NE] %t", "Map Already Nominated");
@ -887,7 +930,7 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return 0;
}
SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
//SetTrieValue(g_mapTrie, map, MAPSTATUS_DISABLED|MAPSTATUS_EXCLUDE_NOMINATED);
if(result == Nominate_Added)
PrintToChatAll("[NE] %t", "Map Nominated", name, map);
@ -1032,12 +1075,15 @@ public int Handler_MapSelectMenu(Menu menu, MenuAction action, int param1, int p
return RedrawMenuItem(display);
}
//2023 edit for multiple nominations
/*
int GroupRestriction = GetMapGroupRestriction(map, param1);
if(RestrictionsActive && GroupRestriction >= 0)
{
Format(display, sizeof(display), "%s (%T)", buffer, "Map Group Restriction", param1, GroupRestriction);
return RedrawMenuItem(display);
}
*/
if(RestrictionsActive && VIPRestriction)
{
@ -1124,7 +1170,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
GetMapGroupRestriction(map, param1) >= 0 ||
GetMapVIPRestriction(map, param1)))
{
PrintToChat(param1, "[NE] You can't nominate this map right now.");
PrintToChat(param1, "[NE] You cant nominate this map right now.");
return 0;
}
}
@ -1133,7 +1179,7 @@ public int Handler_AdminMapSelectMenu(Menu menu, MenuAction action, int param1,
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 can't be full */
/* We assume already in vote is the casue because the maplist does a Map Validity check and we forced, so it cant be full */
PrintToChat(param1, "[NE] %t", "Map Already In Vote", map);
return 0;
}
@ -1180,7 +1226,7 @@ public int Handler_AdminRemoveMapMenu(Menu menu, MenuAction action, int param1,
if(!RemoveNominationByMap(map))
{
CReplyToCommand(param1, "This map isn't nominated.", map);
CReplyToCommand(param1, "This map isnt nominated.", map);
return 0;
}
@ -1302,7 +1348,7 @@ stock int GetVIPTimeRestriction()
MinTime = (MinTime <= CurTime) ? MinTime + 2400 : MinTime;
MinTime = (MinTime <= MaxTime) ? MinTime + 2400 : MinTime;
// Convert our 'time' to minutes.
// Convert our time to minutes.
CurTime = ((CurTime / 100) * 60) + (CurTime % 100);
MinTime = ((MinTime / 100) * 60) + (MinTime % 100);
MaxTime = ((MaxTime / 100) * 60) + (MaxTime % 100);