Fix MAP and LIST vote type cooldown issue.
Updates
1. (2020-03-11) SourceMod 1.10 build 6478 may update its code checking and compiling will encounter error 047. Fixed
2. (2020-05-09) Left some Chinese characters in the plugin which can't be translated by phrases file. Seperate the plugin into Chinese version and English Version.
I debugged the plugin sourcecode and found why cooldown doesn't work. The key is g_iVoteLast[iVoter][iVote] value assignment failed.
Here's an example (List Vote Type):
Code:
public MenuHandler_ListVote(Handle:hMenu, MenuAction:iAction, iVoter, iParam2)
{
if(iAction == MenuAction_End)
{
CloseHandle(hMenu);
return;
}
if(iAction == MenuAction_Cancel && iParam2 == MenuCancel_ExitBack)
{
Menu_ChooseVote(iVoter);
return;
}
if(iAction == MenuAction_Select)
{
decl String:strBuffer[MAX_NAME_LENGTH];
GetMenuItem(hMenu, iParam2, strBuffer, sizeof(strBuffer));
new iVote = g_iVoteCurrent[iVoter];
if(iVote == -1)
{
PrintToChat(iVoter, "iVote = %i", iVote);
return;
}
if(IsVoteInProgress())
{
CPrintToChat(iVoter, "[SM] %t", "Vote in Progress");
return;
}
if(g_iVoteMaxCalls[iVote] > 0 && !CheckCommandAccess(iVoter, "customvotes_maxvotes", ADMFLAG_GENERIC))
{
g_iVoteRemaining[iVoter][iVote]--;
CPrintToChat(iVoter, "%t", "Votes Remaining", g_iVoteRemaining[iVoter][iVote]);
}
new iOption = StringToInt(strBuffer);
g_iVoteLast[iVoter][iVote] = GetTime();
if(g_bVoteCallVote[iVote]) <------------------------------ Check whether the vote type is "vote" "1"
{
Vote_List(iVote, iVoter, iOption); <------------------------------ Build Menu "Vote_List" and show it to iVoter
return; <- ---------------------------------Always Return here and skip GetTime() below
}
if(g_bVoteForOption[iVoter][iVote][iOption])
{
CPrintToChat(iVoter, "%t", "Already Voted");
Menu_ChooseVote(iVoter);
return;
}
g_bVoteForOption[iVoter][iVote][iOption] = true;
if(!g_bVoteMultiple[iVote])
{
for(new iOptionList = 0; iOptionList < GetArraySize(g_hArrayVoteOptionName[iVote]); iOptionList++)
{
if(iOptionList != iOption)
g_bVoteForOption[iVoter][iVote][iOptionList] = false;
}
}
if(g_strVoteCallNotify[iVote][0])
{
decl String:strNotification[255];
strcopy(strNotification, sizeof(strNotification), g_strVoteCallNotify[iVote]);
FormatVoteString(iVote, iOption, strNotification, sizeof(strNotification));
FormatVoterString(iVote, iVoter, strNotification, sizeof(strNotification));
FormatOptionString(iVote, iOption, strNotification, sizeof(strNotification));
ReplaceString(strNotification, sizeof(strNotification), "{Yes|No}", "Yes", true);
ReplaceString(strNotification, sizeof(strNotification), "{yes|no}", "yes", true);
CPrintToChatAll("%s", strNotification);
}
g_iVoteLast[iVoter][iVote] = GetTime(); <------------------------------------------Here the key line GetTime() to g_iVoteLast
CheckVotesForOption(iVote, iOption);
Menu_ChooseVote(iVoter);
}
}
As showing above, the MenuHandler always return after building and showing "Vote_List", the value assignment is always outside of "if(iAction == MenuAction_Select)" and is skipped
So:
Code:
g_iVoteLast[iVoter][iVote] = GetTime(); <- --------------------------------------------------Move GetTime() here
if(g_bVoteCallVote[iVote])
{
Vote_List(iVote, iVoter, iOption);
return;
}
Only the PlayerVote's and SimpleVote's GetTime() put in the right place and cooldown work properly. So I fix the other two vote types ( Map and List).
In addition, the cooldown will be checked at the very beginning while players chat "!votemenu" and plugin showing Vote Menu which you can choose Vote Type from it. ( public Menu_ChooseVote )
For example, one player already called a Kick Player Vote and the cooldown is 60. The Vote Menu will blank out the Kick Player Option ( as the option being "iFlags = ITEMDRAW_DISABLED" ).
Anyway, now the CoolDown limit and those admin_overrides are all working! enjoy it!
PS: I change #include <colorvariables> in order to support custom color variables. You can modify the translation phrases with prefix {yelloe}, {lightgreen}, {green}, etc.
Please let me know if there's any issue. (Email:
[email protected])