3 * =============================================================================
4 * SourceMod Basefuncommands Plugin
5 * Provides gravity functionality
7 * SourceMod (C)2004-2008 AlliedModders LLC. All rights reserved.
8 * =============================================================================
10 * This program is free software; you can redistribute it and/or modify it under
11 * the terms of the GNU General Public License, version 3.0, as published by the
12 * Free Software Foundation.
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 * You should have received a copy of the GNU General Public License along with
20 * this program. If not, see <http://www.gnu.org/licenses/>.
22 * As a special exception, AlliedModders LLC gives you permission to link the
23 * code of this program (as well as its derivative works) to "Half-Life 2," the
24 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
25 * by the Valve Corporation. You must obey the GNU General Public License in
26 * all respects for all other code used. Additionally, AlliedModders LLC grants
27 * this exception to all derivative works. AlliedModders LLC defines further
28 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
29 * or <http://www.sourcemod.net/license.php>.
34 new g_GravityTarget[MAXPLAYERS+1];
36 PerformGravity(client, target, Float:amount)
38 new offset = FindDataMapOffs(client, "m_flGravity");
39 new Float:temp = GetEntDataFloat(client, offset);
40 PrintToChatAll("Gravity check %f", temp);
42 SetEntityGravity(target, amount);
43 LogAction(client, target, "\"%L\" set gravity on \"%L\" to %d.", client, target, amount);
46 public AdminMenu_Gravity(Handle:topmenu,
48 TopMenuObject:object_id,
53 if (action == TopMenuAction_DisplayOption)
55 Format(buffer, maxlength, "%T", "Gravity player", param);
57 else if (action == TopMenuAction_SelectOption)
59 DisplayGravityMenu(param);
63 DisplayGravityMenu(client)
65 new Handle:menu = CreateMenu(MenuHandler_Gravity);
67 decl String:title[100];
68 Format(title, sizeof(title), "%T:", "Gravity player", client);
69 SetMenuTitle(menu, title);
70 SetMenuExitBackButton(menu, true);
72 AddTargetsToMenu(menu, client, true, true);
74 DisplayMenu(menu, client, MENU_TIME_FOREVER);
77 DisplayGravityAmountMenu(client)
79 new Handle:menu = CreateMenu(MenuHandler_GravityAmount);
81 decl String:title[100];
82 Format(title, sizeof(title), "%T: %N", "Gravity amount", client, GetClientOfUserId(g_GravityTarget[client]));
83 SetMenuTitle(menu, title);
84 SetMenuExitBackButton(menu, true);
86 AddTranslatedMenuItem(menu, "4.0", "Gravity Very High", client);
87 AddTranslatedMenuItem(menu, "2.0", "Gravity High", client);
88 AddTranslatedMenuItem(menu, "1.0", "Gravity Normal", client);
89 AddTranslatedMenuItem(menu, "0.5", "Gravity Low", client);
90 AddTranslatedMenuItem(menu, "0.1", "Gravity Very Low", client);
92 DisplayMenu(menu, client, MENU_TIME_FOREVER);
95 public MenuHandler_Gravity(Handle:menu, MenuAction:action, param1, param2)
97 if (action == MenuAction_End)
101 else if (action == MenuAction_Cancel)
103 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
105 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
108 else if (action == MenuAction_Select)
110 decl String:info[32];
113 GetMenuItem(menu, param2, info, sizeof(info));
114 userid = StringToInt(info);
116 if ((target = GetClientOfUserId(userid)) == 0)
118 PrintToChat(param1, "[SM] %t", "Player no longer available");
120 else if (!CanUserTarget(param1, target))
122 PrintToChat(param1, "[SM] %t", "Unable to target");
126 g_GravityTarget[param1] = userid;
127 DisplayGravityAmountMenu(param1);
128 return; // Return, because we went to a new menu and don't want the re-draw to occur.
131 /* Re-draw the menu if they're still valid */
132 if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
134 DisplayGravityMenu(param1);
141 public MenuHandler_GravityAmount(Handle:menu, MenuAction:action, param1, param2)
143 if (action == MenuAction_End)
147 else if (action == MenuAction_Cancel)
149 if (param2 == MenuCancel_ExitBack && hTopMenu != INVALID_HANDLE)
151 DisplayTopMenu(hTopMenu, param1, TopMenuPosition_LastCategory);
154 else if (action == MenuAction_Select)
156 decl String:info[32];
157 new Float:amount, target;
159 GetMenuItem(menu, param2, info, sizeof(info));
160 amount = StringToFloat(info);
162 if ((target = GetClientOfUserId(g_GravityTarget[param1])) == 0)
164 PrintToChat(param1, "[SM] %t", "Player no longer available");
166 else if (!CanUserTarget(param1, target))
168 PrintToChat(param1, "[SM] %t", "Unable to target");
173 GetClientName(target, name, sizeof(name));
175 PerformGravity(param1, target, amount);
176 ShowActivity2(param1, "[SM] ", "%t", "Set gravity on target", "_s", name, amount);
179 /* Re-draw the menu if they're still valid */
180 if (IsClientInGame(param1) && !IsClientInKickQueue(param1))
182 DisplayGravityMenu(param1);
187 public Action:Command_Gravity(client, args)
191 ReplyToCommand(client, "[SM] Usage: sm_gravity <#userid|name> [amount]");
192 return Plugin_Handled;
196 GetCmdArg(1, arg, sizeof(arg));
198 new Float:amount = 1.0;
201 decl String:arg2[20];
202 GetCmdArg(2, arg2, sizeof(arg2));
203 if (StringToFloatEx(arg2, amount) == 0)
205 ReplyToCommand(client, "[SM] %t", "Invalid Amount");
206 return Plugin_Handled;
215 decl String:target_name[MAX_TARGET_LENGTH];
216 decl target_list[MAXPLAYERS], target_count, bool:tn_is_ml;
218 if ((target_count = ProcessTargetString(
223 COMMAND_FILTER_ALIVE,
228 ReplyToTargetError(client, target_count);
229 return Plugin_Handled;
232 for (new i = 0; i < target_count; i++)
234 PerformGravity(client, target_list[i], amount);
239 ShowActivity2(client, "[SM] ", "%t", "Set gravity on target", target_name);
243 ShowActivity2(client, "[SM] ", "%t", "Set gravity on target", "_s", target_name);
246 return Plugin_Handled;