1.1 --- a/plugins/basevotes.sp Thu Aug 09 20:06:42 2007 +0000
1.2 +++ b/plugins/basevotes.sp Thu Aug 09 23:34:53 2007 +0000
1.3 @@ -33,21 +33,22 @@
1.4 url = "http://www.sourcemod.net/"
1.5 };
1.6
1.7 +#define VOTE_NO "###no###"
1.8 +#define VOTE_YES "###yes###"
1.9 +
1.10 new Handle:g_hVoteMenu = INVALID_HANDLE;
1.11
1.12 new Handle:g_hBanForward = INVALID_HANDLE;
1.13
1.14 -new Handle:g_Cvar_VoteMap = INVALID_HANDLE;
1.15 -new Handle:g_Cvar_VoteKick = INVALID_HANDLE;
1.16 -new Handle:g_Cvar_VoteBan = INVALID_HANDLE;
1.17 +new Handle:g_Cvar_Limits[3] = {INVALID_HANDLE, ...};
1.18 //new Handle:g_Cvar_VoteSay = INVALID_HANDLE;
1.19
1.20 enum voteType
1.21 {
1.22 - question = 0,
1.23 map,
1.24 kick,
1.25 - ban
1.26 + ban,
1.27 + question
1.28 }
1.29
1.30 new voteType:g_voteType = voteType:question;
1.31 @@ -66,8 +67,6 @@
1.32
1.33 new String:g_voteArg[256]; /* Used to hold ban/kick reasons or vote questions */
1.34
1.35 -// Temporary global until GetMenuTitle() is added.
1.36 -new String:g_votetitle[64];
1.37
1.38 public OnPluginStart()
1.39 {
1.40 @@ -79,11 +78,17 @@
1.41 RegAdminCmd("sm_voteban", Command_Voteban, ADMFLAG_VOTE|ADMFLAG_BAN, "sm_voteban <player> [reason]");
1.42 RegAdminCmd("sm_vote", Command_Vote, ADMFLAG_VOTE, "sm_vote <question> [Answer1] [Answer2] ... [Answer5]");
1.43
1.44 - //g_Cvar_VoteShow = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
1.45 + /*
1.46 + g_Cvar_Show = FindConVar("sm_vote_show");
1.47 + if (g_Cvar_Show == INVALID_HANDLE)
1.48 + {
1.49 + g_Cvar_Show = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
1.50 + }
1.51 + */
1.52
1.53 - g_Cvar_VoteMap = CreateConVar("sm_vote_map", "0.60", "percent required for successful map vote.", 0, true, 0.05, true, 1.0);
1.54 - g_Cvar_VoteKick = CreateConVar("sm_vote_kick", "0.60", "percent required for successful kick vote.", 0, true, 0.05, true, 1.0);
1.55 - g_Cvar_VoteBan = CreateConVar("sm_vote_ban", "0.60", "percent required for successful ban vote.", 0, true, 0.05, true, 1.0);
1.56 + g_Cvar_Limits[0] = CreateConVar("sm_vote_map", "0.60", "percent required for successful map vote.", 0, true, 0.05, true, 1.0);
1.57 + g_Cvar_Limits[1] = CreateConVar("sm_vote_kick", "0.60", "percent required for successful kick vote.", 0, true, 0.05, true, 1.0);
1.58 + g_Cvar_Limits[2] = CreateConVar("sm_vote_ban", "0.60", "percent required for successful ban vote.", 0, true, 0.05, true, 1.0);
1.59
1.60 g_hBanForward = CreateGlobalForward("OnClientBanned", ET_Ignore, Param_Cell, Param_Cell, Param_Cell, Param_String);
1.61 }
1.62 @@ -101,6 +106,11 @@
1.63 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.64 return Plugin_Handled;
1.65 }
1.66 +
1.67 + if (!TestVoteDelay(client))
1.68 + {
1.69 + return Plugin_Handled;
1.70 + }
1.71
1.72 decl String:text[256];
1.73 GetCmdArgString(text, sizeof(text));
1.74 @@ -131,26 +141,20 @@
1.75
1.76 g_voteType = voteType:map;
1.77
1.78 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MENU_ACTIONS_ALL);
1.79 + g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.80
1.81 if (mapCount == 1)
1.82 {
1.83 strcopy(g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]), maps[0]);
1.84 -
1.85 - // Temp
1.86 - strcopy(g_votetitle, sizeof(g_votetitle), "Change Map To");
1.87
1.88 SetMenuTitle(g_hVoteMenu, "Change Map To");
1.89 AddMenuItem(g_hVoteMenu, maps[0], "Yes");
1.90 - AddMenuItem(g_hVoteMenu, "no", "No");
1.91 + AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.92 }
1.93 else
1.94 {
1.95 g_voteInfo[VOTE_NAME][0] = '\0';
1.96
1.97 - // Temp
1.98 - strcopy(g_votetitle, sizeof(g_votetitle), "Map Vote");
1.99 -
1.100 SetMenuTitle(g_hVoteMenu, "Map Vote");
1.101 for (new i = 0; i < mapCount; i++)
1.102 {
1.103 @@ -177,6 +181,11 @@
1.104 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.105 return Plugin_Handled;
1.106 }
1.107 +
1.108 + if (!TestVoteDelay(client))
1.109 + {
1.110 + return Plugin_Handled;
1.111 + }
1.112
1.113 decl String:text[256];
1.114 GetCmdArgString(text, sizeof(text));
1.115 @@ -201,13 +210,13 @@
1.116
1.117 g_voteType = voteType:question;
1.118
1.119 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MENU_ACTIONS_ALL);
1.120 + g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.121 SetMenuTitle(g_hVoteMenu, "%s?", g_voteArg);
1.122
1.123 if (answerCount < 2)
1.124 {
1.125 - AddMenuItem(g_hVoteMenu, "Yes", "Yes");
1.126 - AddMenuItem(g_hVoteMenu, "No", "No");
1.127 + AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.128 + AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.129 }
1.130 else
1.131 {
1.132 @@ -236,7 +245,12 @@
1.133 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.134 return Plugin_Handled;
1.135 }
1.136 -
1.137 +
1.138 + if (!TestVoteDelay(client))
1.139 + {
1.140 + return Plugin_Handled;
1.141 + }
1.142 +
1.143 decl String:text[256], String:arg[64];
1.144 GetCmdArgString(text, sizeof(text));
1.145
1.146 @@ -266,13 +280,10 @@
1.147
1.148 g_voteType = voteType:kick;
1.149
1.150 - // Temp
1.151 - strcopy(g_votetitle, sizeof(g_votetitle), "Votekick Player");
1.152 -
1.153 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MENU_ACTIONS_ALL);
1.154 + g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.155 SetMenuTitle(g_hVoteMenu, "Votekick Player");
1.156 - AddMenuItem(g_hVoteMenu, "No", "Yes");
1.157 - AddMenuItem(g_hVoteMenu, "No", "No");
1.158 + AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.159 + AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.160 SetMenuExitButton(g_hVoteMenu, false);
1.161 VoteMenuToAll(g_hVoteMenu, 20);
1.162
1.163 @@ -292,7 +303,12 @@
1.164 ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.165 return Plugin_Handled;
1.166 }
1.167 -
1.168 +
1.169 + if (!TestVoteDelay(client))
1.170 + {
1.171 + return Plugin_Handled;
1.172 + }
1.173 +
1.174 decl String:text[256], String:arg[64];
1.175 GetCmdArgString(text, sizeof(text));
1.176
1.177 @@ -324,13 +340,10 @@
1.178
1.179 g_voteType = voteType:ban;
1.180
1.181 - // Temp
1.182 - strcopy(g_votetitle, sizeof(g_votetitle), "Voteban Player");
1.183 -
1.184 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MENU_ACTIONS_ALL);
1.185 + g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.186 SetMenuTitle(g_hVoteMenu, "Voteban Player");
1.187 - AddMenuItem(g_hVoteMenu, "No", "Yes");
1.188 - AddMenuItem(g_hVoteMenu, "No", "No");
1.189 + AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.190 + AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.191 SetMenuExitButton(g_hVoteMenu, false);
1.192 VoteMenuToAll(g_hVoteMenu, 20);
1.193
1.194 @@ -348,8 +361,7 @@
1.195 if (g_voteType != voteType:question)
1.196 {
1.197 decl String:title[64];
1.198 - //GetMenuTitle(g_hVoteMenu, title, sizeof(title));
1.199 - strcopy(title, sizeof(title), g_votetitle);
1.200 + GetMenuTitle(g_hVoteMenu, title, sizeof(title));
1.201
1.202 decl String:buffer[255];
1.203 Format(buffer, sizeof(buffer), "%T", title, param1, g_voteInfo[VOTE_NAME]);
1.204 @@ -374,41 +386,32 @@
1.205 {
1.206 VoteSelect(menu, param1, param2);
1.207 }*/
1.208 + else if (action == MenuAction_NoVotes)
1.209 + {
1.210 + PrintToChatAll("[SM] %t", "No Votes Cast");
1.211 + }
1.212 else if (action == MenuAction_VoteEnd)
1.213 {
1.214 decl String:item[64], String:display[64];
1.215 new Float:percent, Float:limit, votes, totalVotes;
1.216 +
1.217 GetMenuVoteInfo(param2, votes, totalVotes);
1.218 -
1.219 - if (totalVotes < 1)
1.220 - {
1.221 - PrintToChatAll("[SM] %t", "No Votes Cast");
1.222 - return 0;
1.223 - }
1.224 -
1.225 GetMenuItem(menu, param1, item, sizeof(item), _, display, sizeof(display));
1.226
1.227 - if (strcmp(display,"No") == 0 && param1 == 1)
1.228 + if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
1.229 {
1.230 votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
1.231 }
1.232
1.233 percent = GetVotePercent(votes, totalVotes);
1.234
1.235 - switch (g_voteType)
1.236 + if (g_voteType != voteType:question)
1.237 {
1.238 - case (voteType:map):
1.239 - limit = GetConVarFloat(g_Cvar_VoteMap);
1.240 -
1.241 - case (voteType:kick):
1.242 - limit = GetConVarFloat(g_Cvar_VoteKick);
1.243 -
1.244 - case (voteType:ban):
1.245 - limit = GetConVarFloat(g_Cvar_VoteBan);
1.246 + limit = GetConVarFloat(g_Cvar_Limits[g_voteType]);
1.247 }
1.248
1.249 // A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
1.250 - if ((strcmp(display,"Yes") == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(display,"No") == 0 && param1 == 1))
1.251 + if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
1.252 {
1.253 LogMessage("Vote failed.");
1.254 PrintToChatAll("[SM] %t", "Vote Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
1.255 @@ -421,6 +424,11 @@
1.256 {
1.257 case (voteType:question):
1.258 {
1.259 + if (strcmp(item, VOTE_NO) == 0 || strcmp(item, VOTE_YES) == 0)
1.260 + {
1.261 + strcopy(item, sizeof(item), display);
1.262 + }
1.263 +
1.264 PrintToChatAll("[SM] %t", "Vote End", g_voteArg, item);
1.265 }
1.266
1.267 @@ -498,6 +506,27 @@
1.268 return FloatDiv(float(votes),float(totalVotes));
1.269 }
1.270
1.271 +bool:TestVoteDelay(client)
1.272 +{
1.273 + new delay = CheckVoteDelay();
1.274 +
1.275 + if (delay > 0)
1.276 + {
1.277 + if (delay > 60)
1.278 + {
1.279 + ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
1.280 + }
1.281 + else
1.282 + {
1.283 + ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);
1.284 + }
1.285 +
1.286 + return false;
1.287 + }
1.288 +
1.289 + return true;
1.290 +}
1.291 +
1.292 public Action:Timer_ChangeMap(Handle:timer, Handle:dp)
1.293 {
1.294 decl String:mapname[65];