1.1 --- a/plugins/funcommands/blind.sp Fri Jul 11 06:51:21 2008 +0000
1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000
1.3 @@ -1,279 +0,0 @@
1.4 -/**
1.5 - * vim: set ts=4 :
1.6 - * =============================================================================
1.7 - * SourceMod Basefuncommands Plugin
1.8 - * Provides blind functionality
1.9 - *
1.10 - * SourceMod (C)2004-2008 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 -new g_BlindTarget[MAXPLAYERS+1];
1.38 -
1.39 -SetupBlind()
1.40 -{
1.41 - RegAdminCmd("sm_blind", Command_Blind, ADMFLAG_SLAY, "sm_blind <#userid|name> [amount] - Leave amount off to reset.");
1.42 -}
1.43 -
1.44 -PerformBlind(client, target, amount)
1.45 -{
1.46 - new targets[2];
1.47 - targets[0] = target;
1.48 -
1.49 - new Handle:message = StartMessageEx(g_FadeUserMsgId, targets, 1);
1.50 - BfWriteShort(message, 1536);
1.51 - BfWriteShort(message, 1536);
1.52 -
1.53 - if (amount == 0)
1.54 - {
1.55 - BfWriteShort(message, (0x0001 | 0x0010));
1.56 - }
1.57 - else
1.58 - {
1.59 - BfWriteShort(message, (0x0002 | 0x0008));
1.60 - }
1.61 -
1.62 - BfWriteByte(message, 0);
1.63 - BfWriteByte(message, 0);
1.64 - BfWriteByte(message, 0);
1.65 - BfWriteByte(message, amount);
1.66 -
1.67 - EndMessage();
1.68 -
1.69 - LogAction(client, target, "\"%L\" set blind on \"%L\", amount %d.", client, target, amount);
1.70 -}
1.71 -
1.72 -public AdminMenu_Blind(Handle:topmenu,
1.73 - TopMenuAction:action,
1.74 - TopMenuObject:object_id,
1.75 - param,
1.76 - String:buffer[],
1.77 - maxlength)
1.78 -{
1.79 - if (action == TopMenuAction_DisplayOption)
1.80 - {
1.81 - Format(buffer, maxlength, "%T", "Blind player", param);
1.82 - }
1.83 - else if (action == TopMenuAction_SelectOption)
1.84 - {
1.85 - DisplayBlindMenu(param);
1.86 - }
1.87 - else if (action == TopMenuAction_DrawOption)
1.88 - {
1.89 - // Disable if we could not find the user message id for Fade.
1.90 - buffer[0] = ((g_FadeUserMsgId == INVALID_MESSAGE_ID) ? ITEMDRAW_IGNORE : ITEMDRAW_DEFAULT);
1.91 - }
1.92 -}
1.93 -
1.94 -DisplayBlindMenu(client)
1.95 -{
1.96 - new Handle:menu = CreateMenu(MenuHandler_Blind);
1.97 -
1.98 - decl String:title[100];
1.99 - Format(title, sizeof(title), "%T:", "Blind player", client);
1.100 - SetMenuTitle(menu, title);
1.101 - SetMenuExitBackButton(menu, true);
1.102 -
1.103 - AddTargetsToMenu(menu, client, true, true);
1.104 -
1.105 - DisplayMenu(menu, client, MENU_TIME_FOREVER);
1.106 -}
1.107 -
1.108 -DisplayAmountMenu(client)
1.109 -{
1.110 - new Handle:menu = CreateMenu(MenuHandler_Amount);
1.111 -
1.112 - decl String:title[100];
1.113 - Format(title, sizeof(title), "%T:", "Blind amount", client);
1.114 - SetMenuTitle(menu, title);
1.115 - SetMenuExitBackButton(menu, true);
1.116 -
1.117 - AddMenuItem(menu, "255", "Fully blind");
1.118 - AddMenuItem(menu, "240", "Half blind");
1.119 - AddMenuItem(menu, "0", "No blind");
1.120 -
1.121 - DisplayMenu(menu, client, MENU_TIME_FOREVER);
1.122 -}
1.123 -
1.124 -public MenuHandler_Blind(Handle:menu, MenuAction:action, param1, param2)
1.125 -{
1.126 - if (action == MenuAction_End)
1.127 - {
1.128 - CloseHandle(menu);
1.129 - }
1.130 - else if (action == MenuAction_Cancel)
1.131 - {
1.132 - if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.133 - {
1.134 - DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.135 - }
1.136 - }
1.137 - else if (action == MenuAction_Select)
1.138 - {
1.139 - decl String:info[32];
1.140 - new userid, target;
1.141 -
1.142 - GetMenuItem(menu, param2, info, sizeof(info));
1.143 - userid = StringToInt(info);
1.144 -
1.145 - if ((target = GetClientOfUserId(userid)) == 0)
1.146 - {
1.147 - PrintToChat(param1, "[SM] %t", "Player no longer available");
1.148 - }
1.149 - else if (!CanUserTarget(param1, target))
1.150 - {
1.151 - PrintToChat(param1, "[SM] %t", "Unable to target");
1.152 - }
1.153 - else
1.154 - {
1.155 - g_BlindTarget[param1] = userid;
1.156 - DisplayAmountMenu(param1);
1.157 - return; // Return, because we went to a new menu and don't want the re-draw to occur.
1.158 - }
1.159 -
1.160 - /* Re-draw the menu if they're still valid */
1.161 - if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
1.162 - {
1.163 - DisplayBlindMenu(param1);
1.164 - }
1.165 - }
1.166 -
1.167 - return;
1.168 -}
1.169 -
1.170 -public MenuHandler_Amount(Handle:menu, MenuAction:action, param1, param2)
1.171 -{
1.172 - if (action == MenuAction_End)
1.173 - {
1.174 - CloseHandle(menu);
1.175 - }
1.176 - else if (action == MenuAction_Cancel)
1.177 - {
1.178 - if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
1.179 - {
1.180 - DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
1.181 - }
1.182 - }
1.183 - else if (action == MenuAction_Select)
1.184 - {
1.185 - decl String:info[32];
1.186 - new amount, target;
1.187 -
1.188 - GetMenuItem(menu, param2, info, sizeof(info));
1.189 - amount = StringToInt(info);
1.190 -
1.191 - if ((target = GetClientOfUserId(g_BlindTarget[param1])) == 0)
1.192 - {
1.193 - PrintToChat(param1, "[SM] %t", "Player no longer available");
1.194 - }
1.195 - else if (!CanUserTarget(param1, target))
1.196 - {
1.197 - PrintToChat(param1, "[SM] %t", "Unable to target");
1.198 - }
1.199 - else
1.200 - {
1.201 - new String:name[32];
1.202 - GetClientName(target, name, sizeof(name));
1.203 -
1.204 - PerformBlind(param1, target, amount);
1.205 - ShowActivity2(param1, "[SM] ", "%t", "Set blind on target", "_s", name, amount);
1.206 - }
1.207 -
1.208 - /* Re-draw the menu if they're still valid */
1.209 - if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
1.210 - {
1.211 - DisplayBlindMenu(param1);
1.212 - }
1.213 - }
1.214 -}
1.215 -
1.216 -
1.217 -public Action:Command_Blind(client, args)
1.218 -{
1.219 - if (args < 1)
1.220 - {
1.221 - ReplyToCommand(client, "[SM] Usage: sm_blind <#userid|name> [amount]");
1.222 - return Plugin_Handled;
1.223 - }
1.224 -
1.225 - decl String:arg[65];
1.226 - GetCmdArg(1, arg, sizeof(arg));
1.227 -
1.228 - new amount = 0;
1.229 - if (args > 1)
1.230 - {
1.231 - decl String:arg2[20];
1.232 - GetCmdArg(2, arg2, sizeof(arg2));
1.233 - if (StringToIntEx(arg2, amount) == 0)
1.234 - {
1.235 - ReplyToCommand(client, "[SM] %t", "Invalid Amount");
1.236 - return Plugin_Handled;
1.237 - }
1.238 -
1.239 - if (amount < 0)
1.240 - {
1.241 - amount = 0;
1.242 - }
1.243 -
1.244 - if (amount > 255)
1.245 - {
1.246 - amount = 255;
1.247 - }
1.248 - }
1.249 -
1.250 - decl String:target_name[MAX_TARGET_LENGTH];
1.251 - decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
1.252 -
1.253 - if ((target_count = ProcessTargetString(
1.254 - arg,
1.255 - client,
1.256 - target_list,
1.257 - MAXPLAYERS,
1.258 - COMMAND_FILTER_ALIVE,
1.259 - target_name,
1.260 - sizeof(target_name),
1.261 - tn_is_ml)) <= 0)
1.262 - {
1.263 - ReplyToTargetError(client, target_count);
1.264 - return Plugin_Handled;
1.265 - }
1.266 -
1.267 - for (new i = 0; i < target_count; i++)
1.268 - {
1.269 - PerformBlind(client, target_list[i], amount);
1.270 - }
1.271 -
1.272 - if (tn_is_ml)
1.273 - {
1.274 - ShowActivity2(client, "[SM] ", "%t", "Set blind on target", target_name);
1.275 - }
1.276 - else
1.277 - {
1.278 - ShowActivity2(client, "[SM] ", "%t", "Set blind on target", "_s", target_name);
1.279 - }
1.280 -
1.281 - return Plugin_Handled;
1.282 -}