1.1 --- a/plugins/basefunvotes.sp Mon Oct 08 22:13:49 2007 +0000
1.2 +++ b/plugins/basefunvotes.sp Sat Oct 13 04:43:42 2007 +0000
1.3 @@ -36,6 +36,9 @@
1.4 #include <sourcemod>
1.5 #include <sdktools>
1.6
1.7 +#undef REQUIRE_PLUGIN
1.8 +#include <adminmenu>
1.9 +
1.10 public Plugin:myinfo =
1.11 {
1.12 name = "Basic Fun Votes",
1.13 @@ -64,7 +67,7 @@
1.14 slay,
1.15 alltalk,
1.16 ff
1.17 -}
1.18 +};
1.19
1.20 new voteType:g_voteType = voteType:gravity;
1.21
1.22 @@ -80,6 +83,14 @@
1.23 #define VOTE_IP 2
1.24 new String:g_voteInfo[3][65]; /* Holds the target's name, authid, and IP */
1.25
1.26 +new Handle:hTopMenu = INVALID_HANDLE;
1.27 +
1.28 +#include "basefunvotes/votegravity.sp"
1.29 +#include "basefunvotes/voteburn.sp"
1.30 +#include "basefunvotes/voteslay.sp"
1.31 +#include "basefunvotes/votealltalk.sp"
1.32 +#include "basefunvotes/voteff.sp"
1.33 +
1.34 public OnPluginStart()
1.35 {
1.36 LoadTranslations("common.phrases");
1.37 @@ -109,279 +120,71 @@
1.38 g_Cvar_Show = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
1.39 }
1.40 */
1.41 -}
1.42 -
1.43 -public Action:Command_VoteGravity(client, args)
1.44 -{
1.45 - if (args < 1)
1.46 - {
1.47 - ReplyToCommand(client, "[SM] Usage: sm_votegravity <amount> [amount2] ... [amount5]");
1.48 - return Plugin_Handled;
1.49 - }
1.50
1.51 - if (IsVoteInProgress())
1.52 - {
1.53 - ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.54 - return Plugin_Handled;
1.55 - }
1.56 -
1.57 - if (!TestVoteDelay(client))
1.58 - {
1.59 - return Plugin_Handled;
1.60 - }
1.61 -
1.62 - decl String:text[256];
1.63 - GetCmdArgString(text, sizeof(text));
1.64 -
1.65 - decl String:items[5][64];
1.66 - new count;
1.67 - new len, pos;
1.68 -
1.69 - while (pos != -1 && count < 5)
1.70 - {
1.71 - pos = BreakString(text[len], items[count], sizeof(items[]));
1.72 -
1.73 - decl Float:temp;
1.74 - if (StringToFloatEx(items[count], temp) == 0)
1.75 - {
1.76 - ReplyToCommand(client, "[SM] %t", "Invalid Amount");
1.77 - return Plugin_Handled;
1.78 - }
1.79 -
1.80 - count++;
1.81 -
1.82 - if (pos != -1)
1.83 - {
1.84 - len += pos;
1.85 - }
1.86 - }
1.87 -
1.88 - LogAction(client, -1, "\"%L\" initiated a gravity vote.", client);
1.89 - ShowActivity(client, "%t", "Initiated Vote Gravity");
1.90 -
1.91 - g_voteType = voteType:gravity;
1.92 -
1.93 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.94 -
1.95 - if (count == 1)
1.96 - {
1.97 - strcopy(g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]), items[0]);
1.98 -
1.99 - SetMenuTitle(g_hVoteMenu, "Change Gravity To");
1.100 - AddMenuItem(g_hVoteMenu, items[0], "Yes");
1.101 - AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.102 - }
1.103 - else
1.104 + /* Account for late loading */
1.105 + new Handle:topmenu;
1.106 + if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
1.107 {
1.108 - g_voteInfo[VOTE_NAME][0] = '\0';
1.109 -
1.110 - SetMenuTitle(g_hVoteMenu, "Gravity Vote");
1.111 - for (new i = 0; i < count; i++)
1.112 - {
1.113 - AddMenuItem(g_hVoteMenu, items[i], items[i]);
1.114 - }
1.115 - }
1.116 -
1.117 - SetMenuExitButton(g_hVoteMenu, false);
1.118 - VoteMenuToAll(g_hVoteMenu, 20);
1.119 -
1.120 - return Plugin_Handled;
1.121 -}
1.122 -
1.123 -public Action:Command_VoteBurn(client, args)
1.124 -{
1.125 - if (args < 1)
1.126 - {
1.127 - ReplyToCommand(client, "[SM] Usage: sm_voteburn <player>");
1.128 - return Plugin_Handled;
1.129 - }
1.130 -
1.131 - if (IsVoteInProgress())
1.132 - {
1.133 - ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.134 - return Plugin_Handled;
1.135 - }
1.136 -
1.137 - if (!TestVoteDelay(client))
1.138 - {
1.139 - return Plugin_Handled;
1.140 + OnAdminMenuReady(topmenu);
1.141 }
1.142 -
1.143 - decl String:text[256], String:arg[64];
1.144 - GetCmdArgString(text, sizeof(text));
1.145 -
1.146 - BreakString(text, arg, sizeof(arg));
1.147 -
1.148 - new target = FindTarget(client, arg);
1.149 - if (target == -1)
1.150 - {
1.151 - return Plugin_Handled;
1.152 - }
1.153 -
1.154 - if (!IsPlayerAlive(target))
1.155 - {
1.156 - ReplyToCommand(client, "[SM] %t", "Cannot performed on dead", arg);
1.157 - return Plugin_Handled;
1.158 - }
1.159 -
1.160 - g_voteClient[VOTE_CLIENTID] = target;
1.161 - GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
1.162 -
1.163 - LogAction(client, target, "\"%L\" initiated a burn vote against \"%L\"", client, target);
1.164 - ShowActivity(client, "%t", "Initiated Vote Burn", g_voteInfo[VOTE_NAME]);
1.165 -
1.166 - g_voteType = voteType:burn;
1.167 -
1.168 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.169 - SetMenuTitle(g_hVoteMenu, "Voteburn Player");
1.170 - AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.171 - AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.172 - SetMenuExitButton(g_hVoteMenu, false);
1.173 - VoteMenuToAll(g_hVoteMenu, 20);
1.174 -
1.175 - return Plugin_Handled;
1.176 }
1.177
1.178 -public Action:Command_VoteSlay(client, args)
1.179 +public OnAdminMenuReady(Handle:topmenu)
1.180 {
1.181 - if (args < 1)
1.182 - {
1.183 - ReplyToCommand(client, "[SM] Usage: sm_voteslay <player>");
1.184 - return Plugin_Handled;
1.185 - }
1.186 -
1.187 - if (IsVoteInProgress())
1.188 - {
1.189 - ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.190 - return Plugin_Handled;
1.191 - }
1.192 -
1.193 - if (!TestVoteDelay(client))
1.194 - {
1.195 - return Plugin_Handled;
1.196 - }
1.197 -
1.198 - decl String:text[256], String:arg[64];
1.199 - GetCmdArgString(text, sizeof(text));
1.200 -
1.201 - BreakString(text, arg, sizeof(arg));
1.202 -
1.203 - new target = FindTarget(client, arg);
1.204 - if (target == -1)
1.205 + /* Block us from being called twice */
1.206 + if (topmenu == hTopMenu)
1.207 {
1.208 - return Plugin_Handled;
1.209 - }
1.210 -
1.211 - if (!IsPlayerAlive(target))
1.212 - {
1.213 - ReplyToCommand(client, "[SM] %t", "Cannot performed on dead", arg);
1.214 - return Plugin_Handled;
1.215 - }
1.216 -
1.217 - g_voteClient[VOTE_CLIENTID] = target;
1.218 - GetClientName(target, g_voteInfo[VOTE_NAME], sizeof(g_voteInfo[]));
1.219 -
1.220 - LogAction(client, target, "\"%L\" initiated a slay vote against \"%L\"", client, target);
1.221 - ShowActivity(client, "%t", "Initiated Vote Slay", g_voteInfo[VOTE_NAME]);
1.222 -
1.223 - g_voteType = voteType:slay;
1.224 -
1.225 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.226 - SetMenuTitle(g_hVoteMenu, "Voteslay Player");
1.227 - AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.228 - AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.229 - SetMenuExitButton(g_hVoteMenu, false);
1.230 - VoteMenuToAll(g_hVoteMenu, 20);
1.231 -
1.232 - return Plugin_Handled;
1.233 -}
1.234 -
1.235 -public Action:Command_VoteAlltalk(client, args)
1.236 -{
1.237 - if (args > 0)
1.238 - {
1.239 - ReplyToCommand(client, "[SM] Usage: sm_votealltalk");
1.240 - return Plugin_Handled;
1.241 + return;
1.242 }
1.243
1.244 - if (IsVoteInProgress())
1.245 - {
1.246 - ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.247 - return Plugin_Handled;
1.248 - }
1.249 -
1.250 - if (!TestVoteDelay(client))
1.251 - {
1.252 - return Plugin_Handled;
1.253 - }
1.254 -
1.255 - LogAction(client, -1, "\"%L\" initiated an alltalk vote.", client);
1.256 - ShowActivity(client, "%t", "Initiated Vote Alltalk");
1.257 + /* Save the Handle */
1.258 + hTopMenu = topmenu;
1.259
1.260 - g_voteType = voteType:alltalk;
1.261 - g_voteInfo[VOTE_NAME][0] = '\0';
1.262 -
1.263 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.264 -
1.265 - if (GetConVarBool(g_Cvar_Alltalk))
1.266 - {
1.267 - SetMenuTitle(g_hVoteMenu, "Votealltalk Off");
1.268 - }
1.269 - else
1.270 - {
1.271 - SetMenuTitle(g_hVoteMenu, "Votealltalk On");
1.272 - }
1.273 -
1.274 - AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.275 - AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.276 - SetMenuExitButton(g_hVoteMenu, false);
1.277 - VoteMenuToAll(g_hVoteMenu, 20);
1.278 -
1.279 - return Plugin_Handled;
1.280 -}
1.281 + /* Build the "Voting Commands" category */
1.282 + new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
1.283
1.284 -public Action:Command_VoteFF(client, args)
1.285 -{
1.286 - if (args > 0)
1.287 + if (voting_commands != INVALID_TOPMENUOBJECT)
1.288 {
1.289 - ReplyToCommand(client, "[SM] Usage: sm_voteff");
1.290 - return Plugin_Handled;
1.291 - }
1.292 -
1.293 - if (IsVoteInProgress())
1.294 - {
1.295 - ReplyToCommand(client, "[SM] %t", "Vote in Progress");
1.296 - return Plugin_Handled;
1.297 - }
1.298 -
1.299 - if (!TestVoteDelay(client))
1.300 - {
1.301 - return Plugin_Handled;
1.302 + AddToTopMenu(hTopMenu,
1.303 + "Vote Gravity",
1.304 + TopMenuObject_Item,
1.305 + AdminMenu_VoteGravity,
1.306 + voting_commands,
1.307 + "sm_votegravity",
1.308 + ADMFLAG_VOTE);
1.309 +
1.310 + AddToTopMenu(hTopMenu,
1.311 + "Vote Burn",
1.312 + TopMenuObject_Item,
1.313 + AdminMenu_VoteBurn,
1.314 + voting_commands,
1.315 + "sm_voteburn",
1.316 + ADMFLAG_VOTE|ADMFLAG_SLAY);
1.317 +
1.318 + AddToTopMenu(hTopMenu,
1.319 + "Vote Slay",
1.320 + TopMenuObject_Item,
1.321 + AdminMenu_VoteSlay,
1.322 + voting_commands,
1.323 + "sm_voteslay",
1.324 + ADMFLAG_VOTE|ADMFLAG_SLAY);
1.325 +
1.326 + AddToTopMenu(hTopMenu,
1.327 + "Vote AllTalk",
1.328 + TopMenuObject_Item,
1.329 + AdminMenu_VoteAllTalk,
1.330 + voting_commands,
1.331 + "sm_votealltalk",
1.332 + ADMFLAG_VOTE);
1.333 +
1.334 + AddToTopMenu(hTopMenu,
1.335 + "Vote FF",
1.336 + TopMenuObject_Item,
1.337 + AdminMenu_VoteFF,
1.338 + voting_commands,
1.339 + "sm_voteff",
1.340 + ADMFLAG_VOTE);
1.341 }
1.342 -
1.343 - LogAction(client, -1, "\"%L\" initiated a friendly fire vote.", client);
1.344 - ShowActivity(client, "%t", "Initiated Vote FF");
1.345 -
1.346 - g_voteType = voteType:ff;
1.347 - g_voteInfo[VOTE_NAME][0] = '\0';
1.348 -
1.349 - g_hVoteMenu = CreateMenu(Handler_VoteCallback, MenuAction:MENU_ACTIONS_ALL);
1.350 -
1.351 - if (GetConVarBool(g_Cvar_Alltalk))
1.352 - {
1.353 - SetMenuTitle(g_hVoteMenu, "Voteff Off");
1.354 - }
1.355 - else
1.356 - {
1.357 - SetMenuTitle(g_hVoteMenu, "Voteff On");
1.358 - }
1.359 -
1.360 - AddMenuItem(g_hVoteMenu, VOTE_YES, "Yes");
1.361 - AddMenuItem(g_hVoteMenu, VOTE_NO, "No");
1.362 - SetMenuExitButton(g_hVoteMenu, false);
1.363 - VoteMenuToAll(g_hVoteMenu, 20);
1.364 -
1.365 - return Plugin_Handled;
1.366 }
1.367
1.368 public Handler_VoteCallback(Handle:menu, MenuAction:action, param1, param2)