3 * =============================================================================
4 * SourceMod Admin Menu Plugin
5 * Creates the base admin menu, for plugins to add items to.
7 * SourceMod (C)2004-2007 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/"
49 new Handle:hOnAdminMenuReady = INVALID_HANDLE;
50 new Handle:hOnAdminMenuCreated = INVALID_HANDLE;
53 new Handle:hAdminMenu = INVALID_HANDLE;
55 /* Top menu objects */
56 new TopMenuObject:obj_playercmds = INVALID_TOPMENUOBJECT;
57 new TopMenuObject:obj_servercmds = INVALID_TOPMENUOBJECT;
58 new TopMenuObject:obj_votingcmds = INVALID_TOPMENUOBJECT;
60 public bool:AskPluginLoad(Handle:myself, bool:late, String:error[], err_max)
62 CreateNative("GetAdminTopMenu", __GetAdminTopMenu);
63 CreateNative("AddTargetsToMenu", __AddTargetsToMenu);
64 RegPluginLibrary("adminmenu");
68 public OnPluginStart()
70 LoadTranslations("common.phrases");
72 hOnAdminMenuCreated = CreateGlobalForward("OnAdminMenuCreated", ET_Ignore, Param_Cell);
73 hOnAdminMenuReady = CreateGlobalForward("OnAdminMenuReady", ET_Ignore, Param_Cell);
75 RegAdminCmd("sm_admin", Command_DisplayMenu, ADMFLAG_GENERIC, "sm_admin");
78 public OnAllPluginsLoaded()
80 hAdminMenu = CreateTopMenu(CategoryHandler);
82 obj_playercmds = AddToTopMenu(hAdminMenu,
84 TopMenuObject_Category,
86 INVALID_TOPMENUOBJECT);
88 obj_servercmds = AddToTopMenu(hAdminMenu,
90 TopMenuObject_Category,
92 INVALID_TOPMENUOBJECT);
94 obj_votingcmds = AddToTopMenu(hAdminMenu,
96 TopMenuObject_Category,
98 INVALID_TOPMENUOBJECT);
100 Call_StartForward(hOnAdminMenuCreated);
101 Call_PushCell(hAdminMenu);
104 Call_StartForward(hOnAdminMenuReady);
105 Call_PushCell(hAdminMenu);
109 public CategoryHandler(Handle:topmenu,
110 TopMenuAction:action,
111 TopMenuObject:object_id,
116 PrintToServer("CategoryHandler(%x, %d, %x)", topmenu, action, object_id);
117 if (action == TopMenuAction_DisplayTitle)
119 if (object_id == INVALID_TOPMENUOBJECT)
121 Format(buffer, maxlength, "%T:", "Admin Menu", param);
123 else if (object_id == obj_playercmds)
125 Format(buffer, maxlength, "%T:", "Player Commands", param);
127 else if (object_id == obj_servercmds)
129 Format(buffer, maxlength, "%T:", "Server Commands", param);
131 else if (object_id == obj_votingcmds)
133 Format(buffer, maxlength, "%T:", "Voting Commands", param);
136 else if (action == TopMenuAction_DisplayOption)
138 if (object_id == obj_playercmds)
140 Format(buffer, maxlength, "%T", "Player Commands", param);
142 else if (object_id == obj_servercmds)
144 Format(buffer, maxlength, "%T", "Server Commands", param);
146 else if (object_id == obj_votingcmds)
148 Format(buffer, maxlength, "%T", "Voting Commands", param);
153 public __GetAdminTopMenu(Handle:plugin, numParams)
158 public __AddTargetsToMenu(Handle:plugin, numParams)
160 return UTIL_AddTargetsToMenu(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3));
163 public Action:Command_DisplayMenu(client, args)
165 DisplayTopMenu(hAdminMenu, client, TopMenuPosition_Start);
167 return Plugin_Handled;
170 stock UTIL_AddTargetsToMenu(Handle:menu, source_client, bool:in_game_only)
172 new max_clients = GetMaxClients();
173 decl String:user_id[12];
174 decl String:name[MAX_NAME_LENGTH];
175 decl String:display[MAX_NAME_LENGTH+12];
179 for (new i = 1; i <= max_clients; i++)
181 if (!IsClientConnected(i) || IsClientInKickQueue(i))
186 if (in_game_only && !IsClientInGame(i))
191 if (source_client && !CanUserTarget(source_client, i))
196 IntToString(GetClientUserId(i), user_id, sizeof(user_id));
197 GetClientName(i, name, sizeof(name));
198 Format(display, sizeof(display), "%s (%s)", name, user_id);
199 AddMenuItem(menu, user_id, display);