Initial Import of beta structs extension.
3 * =============================================================================
4 * SourceMod Admin Menu Plugin
5 * Creates the base admin menu, for plugins to add items to.
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>.
39 public Plugin:myinfo =
42 author = "AlliedModders LLC",
43 description = "Administration Menu",
44 version = SOURCEMOD_VERSION,
45 url = "http://www.sourcemod.net/"
51 new Handle:hOnAdminMenuReady = INVALID_HANDLE;
52 new Handle:hOnAdminMenuCreated = INVALID_HANDLE;
55 new Handle:hAdminMenu = INVALID_HANDLE;
57 /* Top menu objects */
58 new TopMenuObject:obj_playercmds = INVALID_TOPMENUOBJECT;
59 new TopMenuObject:obj_servercmds = INVALID_TOPMENUOBJECT;
60 new TopMenuObject:obj_votingcmds = INVALID_TOPMENUOBJECT;
62 #include "adminmenu/dynamicmenu.sp"
64 public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
66 CreateNative("GetAdminTopMenu", __GetAdminTopMenu);
67 CreateNative("AddTargetsToMenu", __AddTargetsToMenu);
68 CreateNative("AddTargetsToMenu2", __AddTargetsToMenu2);
69 RegPluginLibrary("adminmenu");
73 public OnPluginStart()
75 LoadTranslations("common.phrases");
76 LoadTranslations("adminmenu.phrases");
78 hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
79 hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
81 RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "Displays the admin menu");
84 public OnConfigsExecuted()
86 decl String:path[PLATFORM_MAX_PATH];
87 decl String:error[256];
89 BuildPath(Path_SM, path, sizeof(path), "configs/adminmenu_sorting.txt");
91 if (!LoadTopMenuConfig(hAdminMenu, path, error, sizeof(error)))
93 LogError("Could not load admin menu config (file \"%s\": %s)", path, error);
100 g_maxPlayers = GetMaxClients();
105 public OnAllPluginsLoaded()
107 hAdminMenu = CreateTopMenu(DefaultCategoryHandler);
109 obj_playercmds = AddToTopMenu(hAdminMenu,
111 TopMenuObject_Category,
112 DefaultCategoryHandler,
113 INVALID_TOPMENUOBJECT);
115 obj_servercmds = AddToTopMenu(hAdminMenu,
117 TopMenuObject_Category,
118 DefaultCategoryHandler,
119 INVALID_TOPMENUOBJECT);
121 obj_votingcmds = AddToTopMenu(hAdminMenu,
123 TopMenuObject_Category,
124 DefaultCategoryHandler,
125 INVALID_TOPMENUOBJECT);
129 Call_StartForward(hOnAdminMenuCreated);
130 Call_PushCell(hAdminMenu);
133 Call_StartForward(hOnAdminMenuReady);
134 Call_PushCell(hAdminMenu);
138 public DefaultCategoryHandler(Handle:topmenu,
139 TopMenuAction:action,
140 TopMenuObject:object_id,
145 if (action == TopMenuAction_DisplayTitle)
147 if (object_id == INVALID_TOPMENUOBJECT)
149 Format(buffer, maxlength, "%T:", "Admin Menu", param);
151 else if (object_id == obj_playercmds)
153 Format(buffer, maxlength, "%T:", "Player Commands", param);
155 else if (object_id == obj_servercmds)
157 Format(buffer, maxlength, "%T:", "Server Commands", param);
159 else if (object_id == obj_votingcmds)
161 Format(buffer, maxlength, "%T:", "Voting Commands", param);
164 else if (action == TopMenuAction_DisplayOption)
166 if (object_id == obj_playercmds)
168 Format(buffer, maxlength, "%T", "Player Commands", param);
170 else if (object_id == obj_servercmds)
172 Format(buffer, maxlength, "%T", "Server Commands", param);
174 else if (object_id == obj_votingcmds)
176 Format(buffer, maxlength, "%T", "Voting Commands", param);
181 public __GetAdminTopMenu(Handle:plugin, numParams)
186 public __AddTargetsToMenu(Handle:plugin, numParams)
188 new bool:alive_only = false;
192 alive_only = GetNativeCell(4);
195 return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3), alive_only);
198 public __AddTargetsToMenu2(Handle:plugin, numParams)
200 return UTIL_AddTargetsToMenu2(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3));
203 public Action:Command_DisplayMenu(client, args)
207 ReplyToCommand(client, "[SM] %t", "Command is in-game only");
208 return Plugin_Handled;
211 DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start);
213 return Plugin_Handled;
216 stock UTIL_AddTargetsToMenu2(Handle:menu, source_client, flags)
218 new max_clients = GetMaxClients();
219 decl String:user_id[12];
220 decl String:name[MAX_NAME_LENGTH];
221 decl String:display[MAX_NAME_LENGTH+12];
225 for (new i = 1; i <= max_clients; i++)
227 if (!IsClientConnected(i) || IsClientInKickQueue(i))
232 PrintToServer("%d, %d, %d", i, flags, IsFakeClient(i));
234 if (((flags & COMMAND_FILTER_NO_BOTS) == COMMAND_FILTER_NO_BOTS)
240 if (((flags & COMMAND_FILTER_CONNECTED) != COMMAND_FILTER_CONNECTED)
241 && !IsClientInGame(i))
246 if (((flags & COMMAND_FILTER_ALIVE) == COMMAND_FILTER_ALIVE)
247 && !IsPlayerAlive(i))
252 if (((flags & COMMAND_FILTER_DEAD) == COMMAND_FILTER_DEAD)
258 if ((source_client && ((flags & COMMAND_FILTER_NO_IMMUNITY) != COMMAND_FILTER_NO_IMMUNITY))
259 && !CanUserTarget(source_client, i))
264 IntToString(GetClientUserId(i), user_id, sizeof(user_id));
265 GetClientName(i, name, sizeof(name));
266 Format(display, sizeof(display), "%s (%s)", name, user_id);
267 AddMenuItem(menu, user_id, display);
274 stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only, bool:alive_only)
280 flags |= COMMAND_FILTER_CONNECTED;
285 flags |= COMMAND_FILTER_ALIVE;
288 return UTIL_AddTargetsToMenu2(menu, source_client, flags);