1.1 --- a/plugins/basefunvotes.sp Fri Feb 22 19:22:22 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,350 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Fun Votes Plugin
1.8 - * Implements extra fun vote commands.
1.9 - *
1.10 - * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
1.11 - * =============================================================================
1.12 - *
1.13 - * This program is free software; you can redistribute it and/or modify it under
1.14 - * the terms of the GNU General Public License, version 3.0, as published by the
1.15 - * Free Software Foundation.
1.16 - *
1.17 - * This program is distributed in the hope that it will be useful, but WITHOUT
1.18 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.19 - * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.20 - * details.
1.21 - *
1.22 - * You should have received a copy of the GNU General Public License along with
1.23 - * this program. If not, see <http://www.gnu.org/licenses/>.
1.24 - *
1.25 - * As a special exception, AlliedModders LLC gives you permission to link the
1.26 - * code of this program (as well as its derivative works) to "Half-Life 2," the
1.27 - * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
1.28 - * by the Valve Corporation. You must obey the GNU General Public License in
1.29 - * all respects for all other code used. Additionally, AlliedModders LLC grants
1.30 - * this exception to all derivative works. AlliedModders LLC defines further
1.31 - * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
1.32 - * or <http://www.sourcemod.net/license.php>.
1.33 - *
1.34 - * Version: $Id$
1.35 - */
1.36 -
1.37 -#pragma semicolon 1
1.38 -
1.39 -#include <sourcemod>
1.40 -#include <sdktools>
1.41 -
1.42 -#undef REQUIRE_PLUGIN
1.43 -#include <adminmenu>
1.44 -
1.45 -public Plugin:myinfo =
1.46 -{
1.47 - name = "Basic Fun Votes",
1.48 - author = "AlliedModders LLC",
1.49 - description = "Fun Vote Commands",
1.50 - version = SOURCEMOD_VERSION,
1.51 - url = "http://www.sourcemod.net/"
1.52 -};
1.53 -
1.54 -#define VOTE_NO "###no###"
1.55 -#define VOTE_YES "###yes###"
1.56 -
1.57 -new Handle:g_hVoteMenu = INVALID_HANDLE;
1.58 -
1.59 -new Handle:g_Cvar_Limits[5] = {INVALID_HANDLE, ...};
1.60 -new Handle:g_Cvar_Gravity = INVALID_HANDLE;
1.61 -new Handle:g_Cvar_Alltalk = INVALID_HANDLE;
1.62 -new Handle:g_Cvar_FF = INVALID_HANDLE;
1.63 -
1.64 -// new Handle:g_Cvar_Show = INVALID_HANDLE;
1.65 -
1.66 -enum voteType
1.67 -{
1.68 - gravity = 0,
1.69 - burn,
1.70 - slay,
1.71 - alltalk,
1.72 - ff
1.73 -};
1.74 -
1.75 -new voteType:g_voteType = voteType:gravity;
1.76 -
1.77 -// Menu API does not provide us with a way to pass multiple peices of data with a single
1.78 -// choice, so some globals are used to hold stuff.
1.79 -//
1.80 -#define VOTE_CLIENTID 0
1.81 -#define VOTE_USERID 1
1.82 -new g_voteClient[2]; /* Holds the target's client id and user id */
1.83 -
1.84 -#define VOTE_NAME 0
1.85 -#define VOTE_AUTHID 1
1.86 -#define VOTE_IP 2
1.87 -new String:g_voteInfo[3][65]; /* Holds the target's name, authid, and IP */
1.88 -
1.89 -new Handle:hTopMenu = INVALID_HANDLE;
1.90 -
1.91 -#include "basefunvotes/votegravity.sp"
1.92 -#include "basefunvotes/voteburn.sp"
1.93 -#include "basefunvotes/voteslay.sp"
1.94 -#include "basefunvotes/votealltalk.sp"
1.95 -#include "basefunvotes/voteff.sp"
1.96 -
1.97 -public OnPluginStart()
1.98 -{
1.99 - LoadTranslations("common.phrases");
1.100 - LoadTranslations("basevotes.phrases");
1.101 - LoadTranslations("basefunvotes.phrases");
1.102 - LoadTranslations("basefuncommands.phrases");
1.103 -
1.104 - RegAdminCmd("sm_votegravity", Command_VoteGravity, ADMFLAG_VOTE, "sm_votegravity <amount> [amount2] ... [amount5]");
1.105 - RegAdminCmd("sm_voteburn", Command_VoteBurn, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteburn <player>");
1.106 - RegAdminCmd("sm_voteslay", Command_VoteSlay, ADMFLAG_VOTE|ADMFLAG_SLAY, "sm_voteslay <player>");
1.107 - RegAdminCmd("sm_votealltalk", Command_VoteAlltalk, ADMFLAG_VOTE, "sm_votealltalk");
1.108 - RegAdminCmd("sm_voteff", Command_VoteFF, ADMFLAG_VOTE, "sm_voteff");
1.109 -
1.110 - g_Cvar_Limits[0] = CreateConVar("sm_vote_gravity", "0.60", "percent required for successful gravity vote.", 0, true, 0.05, true, 1.0);
1.111 - g_Cvar_Limits[1] = CreateConVar("sm_vote_burn", "0.60", "percent required for successful burn vote.", 0, true, 0.05, true, 1.0);
1.112 - g_Cvar_Limits[2] = CreateConVar("sm_vote_slay", "0.60", "percent required for successful slay vote.", 0, true, 0.05, true, 1.0);
1.113 - g_Cvar_Limits[3] = CreateConVar("sm_vote_alltalk", "0.60", "percent required for successful alltalk vote.", 0, true, 0.05, true, 1.0);
1.114 - g_Cvar_Limits[4] = CreateConVar("sm_vote_ff", "0.60", "percent required for successful friendly fire vote.", 0, true, 0.05, true, 1.0);
1.115 -
1.116 - g_Cvar_Gravity = FindConVar("sv_gravity");
1.117 - g_Cvar_Alltalk = FindConVar("sv_alltalk");
1.118 - g_Cvar_FF = FindConVar("mp_friendlyfire");
1.119 -
1.120 - /*
1.121 - g_Cvar_Show = FindConVar("sm_vote_show");
1.122 - if (g_Cvar_Show == INVALID_HANDLE)
1.123 - {
1.124 - g_Cvar_Show = CreateConVar("sm_vote_show", "1", "Show player's votes? Default on.", 0, true, 0.0, true, 1.0);
1.125 - }
1.126 - */
1.127 -
1.128 - /* Account for late loading */
1.129 - new Handle:topmenu;
1.130 - if (LibraryExists("adminmenu") && ((topmenu = GetAdminTopMenu()) != INVALID_HANDLE))
1.131 - {
1.132 - OnAdminMenuReady(topmenu);
1.133 - }
1.134 -}
1.135 -
1.136 -public OnAdminMenuReady(Handle:topmenu)
1.137 -{
1.138 - /* Block us from being called twice */
1.139 - if (topmenu == hTopMenu)
1.140 - {
1.141 - return;
1.142 - }
1.143 -
1.144 - /* Save the Handle */
1.145 - hTopMenu = topmenu;
1.146 -
1.147 - /* Build the "Voting Commands" category */
1.148 - new TopMenuObject:voting_commands = FindTopMenuCategory(hTopMenu, ADMINMENU_VOTINGCOMMANDS);
1.149 -
1.150 - if (voting_commands != INVALID_TOPMENUOBJECT)
1.151 - {
1.152 - AddToTopMenu(hTopMenu,
1.153 - "sm_votegravity",
1.154 - TopMenuObject_Item,
1.155 - AdminMenu_VoteGravity,
1.156 - voting_commands,
1.157 - "sm_votegravity",
1.158 - ADMFLAG_VOTE);
1.159 -
1.160 - AddToTopMenu(hTopMenu,
1.161 - "sm_voteburn",
1.162 - TopMenuObject_Item,
1.163 - AdminMenu_VoteBurn,
1.164 - voting_commands,
1.165 - "sm_voteburn",
1.166 - ADMFLAG_VOTE|ADMFLAG_SLAY);
1.167 -
1.168 - AddToTopMenu(hTopMenu,
1.169 - "sm_voteslay",
1.170 - TopMenuObject_Item,
1.171 - AdminMenu_VoteSlay,
1.172 - voting_commands,
1.173 - "sm_voteslay",
1.174 - ADMFLAG_VOTE|ADMFLAG_SLAY);
1.175 -
1.176 - AddToTopMenu(hTopMenu,
1.177 - "sm_votealltalk",
1.178 - TopMenuObject_Item,
1.179 - AdminMenu_VoteAllTalk,
1.180 - voting_commands,
1.181 - "sm_votealltalk",
1.182 - ADMFLAG_VOTE);
1.183 -
1.184 - AddToTopMenu(hTopMenu,
1.185 - "sm_voteff",
1.186 - TopMenuObject_Item,
1.187 - AdminMenu_VoteFF,
1.188 - voting_commands,
1.189 - "sm_voteff",
1.190 - ADMFLAG_VOTE);
1.191 - }
1.192 -}
1.193 -
1.194 -public Handler_VoteCallback(Handle:menu, MenuAction:action, param1, param2)
1.195 -{
1.196 - if (action == MenuAction_End)
1.197 - {
1.198 - VoteMenuClose();
1.199 - }
1.200 - else if (action == MenuAction_Display)
1.201 - {
1.202 - decl String:title[64];
1.203 - GetMenuTitle(menu, title, sizeof(title));
1.204 -
1.205 - decl String:buffer[255];
1.206 - Format(buffer, sizeof(buffer), "%T", title, param1, g_voteInfo[VOTE_NAME]);
1.207 -
1.208 - new Handle:panel = Handle:param2;
1.209 - SetPanelTitle(panel, buffer);
1.210 - }
1.211 - else if (action == MenuAction_DisplayItem)
1.212 - {
1.213 - decl String:display[64];
1.214 - GetMenuItem(menu, param2, "", 0, _, display, sizeof(display));
1.215 -
1.216 - if (strcmp(display, VOTE_NO) == 0 || strcmp(display, VOTE_YES) == 0)
1.217 - {
1.218 - decl String:buffer[255];
1.219 - Format(buffer, sizeof(buffer), "%T", display, param1);
1.220 -
1.221 - return RedrawMenuItem(buffer);
1.222 - }
1.223 - }
1.224 - /* else if (action == MenuAction_Select)
1.225 - {
1.226 - VoteSelect(menu, param1, param2);
1.227 - }*/
1.228 - else if (action == MenuAction_VoteCancel && param1 == VoteCancel_NoVotes)
1.229 - {
1.230 - PrintToChatAll("[SM] %t", "No Votes Cast");
1.231 - }
1.232 - else if (action == MenuAction_VoteEnd)
1.233 - {
1.234 - decl String:item[64];
1.235 - new Float:percent, Float:limit, votes, totalVotes;
1.236 -
1.237 - GetMenuVoteInfo(param2, votes, totalVotes);
1.238 - GetMenuItem(menu, param1, item, sizeof(item));
1.239 -
1.240 - if (strcmp(item, VOTE_NO) == 0 && param1 == 1)
1.241 - {
1.242 - votes = totalVotes - votes; // Reverse the votes to be in relation to the Yes option.
1.243 - }
1.244 -
1.245 - percent = GetVotePercent(votes, totalVotes);
1.246 -
1.247 - limit = GetConVarFloat(g_Cvar_Limits[g_voteType]);
1.248 -
1.249 - /* :TODO: g_voteClient[userid] needs to be checked.
1.250 - */
1.251 -
1.252 - // A multi-argument vote is "always successful", but have to check if its a Yes/No vote.
1.253 - if ((strcmp(item, VOTE_YES) == 0 && FloatCompare(percent,limit) < 0 && param1 == 0) || (strcmp(item, VOTE_NO) == 0 && param1 == 1))
1.254 - {
1.255 - /* :TODO: g_voteClient[userid] should be used here and set to -1 if not applicable.
1.256 - */
1.257 - LogAction(-1, -1, "Vote failed.");
1.258 - PrintToChatAll("[SM] %t", "Vote Failed", RoundToNearest(100.0*limit), RoundToNearest(100.0*percent), totalVotes);
1.259 - }
1.260 - else
1.261 - {
1.262 - PrintToChatAll("[SM] %t", "Vote Successful", RoundToNearest(100.0*percent), totalVotes);
1.263 -
1.264 - switch (g_voteType)
1.265 - {
1.266 - case (voteType:gravity):
1.267 - {
1.268 - PrintToChatAll("[SM] %t", "Cvar changed", "sv_gravity", item);
1.269 - LogAction(-1, -1, "Changing gravity to %s due to vote.", item);
1.270 - SetConVarInt(g_Cvar_Gravity, StringToInt(item));
1.271 - }
1.272 -
1.273 - case (voteType:burn):
1.274 - {
1.275 - PrintToChatAll("[SM] %t", "Set target on fire", "_s", g_voteInfo[VOTE_NAME]);
1.276 - LogAction(-1, g_voteClient[VOTE_CLIENTID], "Vote burn successful, igniting \"%L\"", g_voteClient[VOTE_CLIENTID]);
1.277 -
1.278 - IgniteEntity(g_voteClient[VOTE_CLIENTID], 19.8);
1.279 - }
1.280 -
1.281 - case (voteType:slay):
1.282 - {
1.283 - PrintToChatAll("[SM] %t", "Slayed player", g_voteInfo[VOTE_NAME]);
1.284 - LogAction(-1, g_voteClient[VOTE_CLIENTID], "Vote slay successful, slaying \"%L\"", g_voteClient[VOTE_CLIENTID]);
1.285 -
1.286 - ExtinguishEntity(g_voteClient[VOTE_CLIENTID]);
1.287 - ForcePlayerSuicide(g_voteClient[VOTE_CLIENTID]);
1.288 - }
1.289 -
1.290 - case (voteType:alltalk):
1.291 - {
1.292 - PrintToChatAll("[SM] %t", "Cvar changed", "sv_alltalk", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
1.293 - LogAction(-1, -1, "Changing alltalk to %s due to vote.", (GetConVarBool(g_Cvar_Alltalk) ? "0" : "1"));
1.294 - SetConVarBool(g_Cvar_Alltalk, !GetConVarBool(g_Cvar_Alltalk));
1.295 - }
1.296 -
1.297 - case (voteType:ff):
1.298 - {
1.299 - PrintToChatAll("[SM] %t", "Cvar changed", "mp_friendlyfire", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
1.300 - LogAction(-1, -1, "Changing friendly fire to %s due to vote.", (GetConVarBool(g_Cvar_FF) ? "0" : "1"));
1.301 - SetConVarBool(g_Cvar_FF, !GetConVarBool(g_Cvar_FF));
1.302 - }
1.303 - }
1.304 - }
1.305 - }
1.306 -
1.307 - return 0;
1.308 -}
1.309 -
1.310 -/*
1.311 -VoteSelect(Handle:menu, param1, param2 = 0)
1.312 -{
1.313 - if (GetConVarInt(g_Cvar_VoteShow) == 1)
1.314 - {
1.315 - decl String:voter[64], String:junk[64], String:choice[64];
1.316 - GetClientName(param1, voter, sizeof(voter));
1.317 - GetMenuItem(menu, param2, junk, sizeof(junk), _, choice, sizeof(choice));
1.318 - PrintToChatAll("[SM] %T", "Vote Select", LANG_SERVER, voter, choice);
1.319 - }
1.320 -}
1.321 -*/
1.322 -
1.323 -VoteMenuClose()
1.324 -{
1.325 - CloseHandle(g_hVoteMenu);
1.326 - g_hVoteMenu = INVALID_HANDLE;
1.327 -}
1.328 -
1.329 -Float:GetVotePercent(votes, totalVotes)
1.330 -{
1.331 - return FloatDiv(float(votes),float(totalVotes));
1.332 -}
1.333 -
1.334 -bool:TestVoteDelay(client)
1.335 -{
1.336 - new delay = CheckVoteDelay();
1.337 -
1.338 - if (delay > 0)
1.339 - {
1.340 - if (delay > 60)
1.341 - {
1.342 - ReplyToCommand(client, "[SM] %t", "Vote Delay Minutes", delay % 60);
1.343 - }
1.344 - else
1.345 - {
1.346 - ReplyToCommand(client, "[SM] %t", "Vote Delay Seconds", delay);
1.347 - }
1.348 -
1.349 - return false;
1.350 - }
1.351 -
1.352 - return true;
1.353 -}