Base Votes import.
3 * Displays and searches SourceMod commands and descriptions.
4 * This file is part of SourceMod, Copyright (C) 2004-2007 AlliedModders LLC
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
27 #define COMMANDS_PER_PAGE 10
29 public Plugin:myinfo =
32 author = "AlliedModders LLC",
33 description = "Display command information",
34 version = SOURCEMOD_VERSION,
35 url = "http://www.sourcemod.net/"
38 public OnPluginStart()
40 LoadTranslations("common.phrases");
41 LoadTranslations("adminhelp.phrases");
42 RegConsoleCmd("sm_help", HelpCmd, "Displays SourceMod commands and descriptions");
43 RegConsoleCmd("sm_searchcmd", HelpCmd, "Searches SourceMod commands");
46 public Action:HelpCmd(client, args)
48 decl String:arg[64], String:CmdName[20];
52 GetCmdArg(0, CmdName, sizeof(CmdName));
54 if (GetCmdArgs() >= 1)
56 GetCmdArg(1, arg, sizeof(arg));
57 StringToIntEx(arg, PageNum);
58 PageNum = (PageNum <= 0) ? 1 : PageNum;
61 DoSearch = (strcmp("sm_help", CmdName) == 0) ? false : true;
63 if (GetCmdReplySource() == SM_REPLY_TO_CHAT)
65 ReplyToCommand(client, "[SM] %t", "See console for output");
69 decl String:Desc[255];
70 decl String:NoDesc[128];
72 new Handle:CmdIter = GetCommandIterator();
74 FormatEx(NoDesc, sizeof(NoDesc), "%t", "No description available");
79 while (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)))
81 if ((StrContains(Name, arg, false) != -1) && CheckCommandAccess(client, Name, Flags))
83 PrintToConsole(client, "[%03d] %s - %s", i++, Name, (Desc[0] == '\0') ? NoDesc : Desc);
89 PrintToConsole(client, "%t", "No matching results found");
92 PrintToConsole(client, "%t", "SM help commands");
94 /* Skip the first N commands if we need to */
98 new EndCmd = (PageNum-1) * COMMANDS_PER_PAGE - 1;
99 for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<EndCmd; )
101 if (CheckCommandAccess(client, Name, Flags))
109 PrintToConsole(client, "%t", "No commands available");
110 CloseHandle(CmdIter);
111 return Plugin_Handled;
115 /* Start printing the commands to the client */
117 new StartCmd = (PageNum-1) * COMMANDS_PER_PAGE;
118 for (i=0; ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && i<COMMANDS_PER_PAGE; )
120 if (CheckCommandAccess(client, Name, Flags))
123 PrintToConsole(client, "[%03d] %s - %s", i+StartCmd, Name, (Desc[0] == '\0') ? NoDesc : Desc);
129 PrintToConsole(client, "%t", "No commands available");
131 PrintToConsole(client, "%t", "Entries n - m in page k", StartCmd+1, i+StartCmd, PageNum);
134 /* Test if there are more commands available */
135 if (ReadCommandIterator(CmdIter, Name, sizeof(Name), Flags, Desc, sizeof(Desc)) && CheckCommandAccess(client, Name, Flags))
137 PrintToConsole(client, "%t", "Type sm_help to see more", PageNum+1);
141 CloseHandle(CmdIter);
143 return Plugin_Handled;