Skip to content

Commit 116e447

Browse files
authored
fix(mce): player nomination handling in voting results (#57)
1 parent 787c510 commit 116e447

8 files changed

Lines changed: 96 additions & 37 deletions

File tree

addons/sourcemod/scripting/include/mapchooser_extended.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141

4242
#define MCE_V_MAJOR "1"
4343
#define MCE_V_MINOR "13"
44-
#define MCE_V_PATCH "10"
44+
#define MCE_V_PATCH "11"
4545

4646
#define MCE_VERSION MCE_V_MAJOR..."."...MCE_V_MINOR..."."...MCE_V_PATCH
4747

addons/sourcemod/scripting/mce/functions.inc

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,11 +170,8 @@ stock void InitializeMapVoteSettings()
170170

171171
g_TotalRounds = 0;
172172
g_Extends = 0;
173-
g_NominateCount = 0;
174-
g_NominateReservedCount = 0;
175173

176-
ClearArray(g_NominateList);
177-
ClearArray(g_NominateOwners);
174+
ClearNominationsLists();
178175

179176
for (int i = 0; i < MAXTEAMS; i++)
180177
g_winCount[i] = 0;
@@ -195,6 +192,15 @@ stock void ConfigureBonusRoundTime()
195192
SetConVarBounds(g_Cvar_Bonusroundtime, ConVarBound_Upper, true, 30.0);
196193
}
197194

195+
stock void ClearNominationsLists()
196+
{
197+
// Wipe out our nominations list
198+
g_NominateCount = 0;
199+
g_NominateReservedCount = 0;
200+
ClearArray(g_NominateOwners);
201+
ClearArray(g_NominateList);
202+
}
203+
198204
stock void CleanOnMapEnd()
199205
{
200206
g_HasVoteStarted = false;

addons/sourcemod/scripting/mce/menus.inc

Lines changed: 58 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,6 @@ void InitiateVote(MapChange when, Handle inputlist=INVALID_HANDLE)
220220
randomizeList = INVALID_HANDLE;
221221
}
222222

223-
/* Wipe out our nominations list - Nominations have already been informed of this */
224-
g_NominateCount = 0;
225-
g_NominateReservedCount = 0;
226-
ClearArray(g_NominateOwners);
227-
ClearArray(g_NominateList);
228-
229223
if (!g_bExtendPositionTop) {
230224
if (InternalGetMapMaxExtends(map) - g_Extends > 0)
231225
FormatEx(allMapsBuffer, allMapsSize, "%s\n- %s", allMapsBuffer, "Extend");
@@ -362,6 +356,7 @@ public void Handler_VoteFinishedGeneric(Handle menu,
362356
g_HasVoteStarted = false;
363357
g_PendingRevoteActive = false;
364358
SetupTimeleftTimer();
359+
ClearNominationsLists();
365360

366361
}
367362
else if (strcmp(map, VOTE_DONTCHANGE, false) == 0)
@@ -380,6 +375,7 @@ public void Handler_VoteFinishedGeneric(Handle menu,
380375
g_HasVoteStarted = false;
381376
g_PendingRevoteActive = false;
382377
SetupTimeleftTimer();
378+
ClearNominationsLists();
383379
}
384380
else
385381
{
@@ -408,47 +404,79 @@ public void Handler_VoteFinishedGeneric(Handle menu,
408404

409405
int percent = RoundToFloor(float(item_info[0][VOTEINFO_ITEM_VOTES])/float(num_votes)*100.0);
410406

411-
// Check who nominated the map
412-
char sPlayer[32];
413-
for (int i = 1; i <= MaxClients; i++)
407+
int owner = -1;
408+
bool foundNomination = false;
409+
410+
if (g_bShowNominator)
414411
{
415-
if (strcmp(g_sNominations[i], map, false) != 0)
416-
continue;
417-
if (!IsClientInGame(i))
418-
continue;
419-
FormatEx(sPlayer, sizeof(sPlayer), "%N", i);
420-
break;
412+
static char nominatedMap[PLATFORM_MAX_PATH];
413+
int nominateCount = GetArraySize(g_NominateList);
414+
for (int i = 0; i < nominateCount; i++)
415+
{
416+
GetArrayString(g_NominateList, i, nominatedMap, sizeof(nominatedMap));
417+
if (strcmp(nominatedMap, map, false) == 0)
418+
{
419+
owner = GetArrayCell(g_NominateOwners, i);
420+
foundNomination = true;
421+
break;
422+
}
423+
}
421424
}
422425

423-
char mapInChat[64];
424-
strcopy(mapInChat, sizeof(mapInChat), map);
425-
int mapTier;
426-
if (InternalShowMapTierInChat() && (mapTier = InternalGetMapTier(map)) && mapTier > 0)
426+
// Cache Nominator Name
427+
char ownerName[MAX_NAME_LENGTH];
428+
bool isOwnerConnected = (g_bShowNominator && foundNomination && owner > 0 && IsClientInGame(owner));
429+
if (isOwnerConnected)
430+
GetClientName(owner, ownerName, sizeof(ownerName));
431+
432+
// Cache Map Display Name with Tier (Static)
433+
char mapInChat[128];
434+
int mapTier = InternalGetMapTier(map);
435+
if (InternalShowMapTierInChat() && mapTier > 0)
427436
{
428437
char tierName[32];
429438
InternalGetTierNameFromInt(mapTier, tierName, sizeof(tierName));
430-
Format(mapInChat, sizeof(mapInChat), "%s %t", map, "MapTierDisplay", tierName);
431-
}
432-
433-
if (sPlayer[0] && g_bShowNominator)
434-
{
435-
CPrintToChatAll("{green}[MCE]{default} %t - %t %s", "Nextmap Voting Finished", mapInChat, percent, num_votes, "Nominated by", sPlayer);
436-
LogAction(-1, -1, "[MCE] Voting for next map has finished. \nNextmap: %s. (Received \"%d\"\%% of %d votes) Nominated by %s", map, percent, num_votes, sPlayer);
439+
FormatEx(mapInChat, sizeof(mapInChat), "%s (%s)", map, tierName);
437440
}
438441
else
439442
{
440-
CPrintToChatAll("{green}[MCE]{default} %t", "Nextmap Voting Finished", mapInChat, percent, num_votes);
441-
LogAction(-1, -1, "[MCE] Voting for next map has finished. \nNextmap: %s. (Received \"%d\"\%% of %d votes)", map, percent, num_votes);
443+
strcopy(mapInChat, sizeof(mapInChat), map);
442444
}
443445

444-
// Vote has finished, clear nominations
446+
// Per-client chat loop
445447
for (int i = 1; i <= MaxClients; i++)
446448
{
447-
if (!IsClientConnected(i) || !IsClientInGame(i))
449+
if (!IsClientInGame(i) || (IsFakeClient(i) && !IsClientSourceTV(i)))
448450
continue;
449451

452+
CPrintToChat(i, "{green}[MCE]{default} %t", "Nextmap Voting Finished", mapInChat, percent, num_votes);
453+
454+
if (g_bShowNominator && foundNomination && owner > 0)
455+
{
456+
if (isOwnerConnected)
457+
CPrintToChat(i, "{green}[MCE]{default} %t %s", "Nominated by", ownerName);
458+
else
459+
CPrintToChat(i, "{green}[MCE]{default} %t %t", "Nominated by", "Disconnected Player");
460+
}
461+
450462
ClearStoredNomination(i);
451463
}
464+
465+
// Build Log String (Server Language)
466+
char sPlayerLog[128];
467+
if (g_bShowNominator && foundNomination && owner > 0)
468+
{
469+
SetGlobalTransTarget(LANG_SERVER);
470+
if (isOwnerConnected)
471+
FormatEx(sPlayerLog, sizeof(sPlayerLog), " \n%t %s", "Nominated by", ownerName);
472+
else
473+
FormatEx(sPlayerLog, sizeof(sPlayerLog), " \n%t %t", "Nominated by", "Disconnected Player");
474+
}
475+
476+
LogAction(-1, -1, "[MCE] Voting for next map has finished. \nNextmap: %s. (Received \"%d\"%% of %d votes)%s",
477+
map, percent, num_votes, sPlayerLog);
478+
479+
ClearNominationsLists();
452480
}
453481
}
454482

addons/sourcemod/translations/chi/mapchooser_extended.phrases.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,11 @@
320320
"chi" "提名人:"
321321
}
322322

323+
"Disconnected Player"
324+
{
325+
"chi" "断开连接的玩家"
326+
}
327+
323328
"Client inserted Map"
324329
{
325330
"chi" "{1} 将 {2} 插入到提名中."

addons/sourcemod/translations/es/mapchooser_extended.phrases.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@
321321
"es" "Nominado por:"
322322
}
323323

324+
"Disconnected Player"
325+
{
326+
"es" "Jugador desconectado"
327+
}
328+
324329
"Client inserted Map"
325330
{
326331
"es" "{1} ha insertado {2} en las nominaciones."

addons/sourcemod/translations/fr/mapchooser_extended.phrases.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,11 @@
321321
"fr" "Séléctionné par:"
322322
}
323323

324+
"Disconnected Player"
325+
{
326+
"fr" "Joueur déconnecté"
327+
}
328+
324329
"Client inserted Map"
325330
{
326331
"fr" "{1} a inséré {2} dans les nominations."

addons/sourcemod/translations/mapchooser_extended.phrases.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,11 @@
360360
"en" "Nominated by:"
361361
}
362362

363+
"Disconnected Player"
364+
{
365+
"en" "Disconnected player"
366+
}
367+
363368
"Client inserted Map"
364369
{
365370
"#format" "{1:N},{2:s}"

addons/sourcemod/translations/ru/mapchooser_extended.phrases.txt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@
9999

100100
"Custom Marked"
101101
{
102-
"en" "*{1}"
102+
"ru" "*{1}"
103103
}
104104

105105
"Map Cooldown Time Error"
@@ -314,14 +314,19 @@
314314

315315
"Menu Got UnNombanned"
316316
{
317-
"en" "Вы были разбанены в номинировании карт."
317+
"ru" "Вы были разбанены в номинировании карт."
318318
}
319319

320320
"Nominated by"
321321
{
322322
"ru" "Предложена:"
323323
}
324324

325+
"Disconnected Player"
326+
{
327+
"ru" "Игрок отключен."
328+
}
329+
325330
"Client inserted Map"
326331
{
327332
"ru" "{1} предложил {2} в номинации."

0 commit comments

Comments
 (0)