Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma semicolon 1
- #define DEBUG
- #define PLUGIN_AUTHOR "Yellon"
- #define PLUGIN_VERSION "1.00"
- #include <sourcemod>
- #include <sdktools>
- #pragma newdecls required
- ConVar Command;
- ConVar TitleMenu;
- int iMaxMenu;
- StringMap CfgName;
- StringMap CfgCommand;
- public Plugin myinfo =
- {
- name = "Menu Main",
- author = PLUGIN_AUTHOR,
- description = "",
- version = PLUGIN_VERSION,
- url = "dangerzone.pl"
- };
- public void OnPluginStart()
- {
- Command = CreateConVar("Menu_Command", "menu,menuservera", "Komendy do wywołania menu");
- TitleMenu = CreateConVar("Menu_Title", "Menu Serwerka [n] DangerZoniaków", "Tytuł menu");
- AutoExecConfig(true, "MainMenu");
- CfgName = new StringMap();
- CfgCommand = new StringMap();
- CreateTimer(5.0, MenuServer, INVALID_HANDLE);
- }
- public Action MenuServer(Handle Timer)
- {
- char szCommand[128];
- char szCommands[10][64];
- char szCommands_sm[64];
- GetConVarString(Command, szCommand, sizeof(szCommand));
- ExplodeString(szCommand, ",", szCommands, 64, 64, false);
- for (int i = 0; i < 10; i++)
- {
- if(!StrEqual(szCommands[i], ""))
- {
- Format(szCommands_sm, 64, "sm_%s", szCommands[i]);
- RegConsoleCmd(szCommands_sm, MainMenu);
- }
- }
- }
- public Action MainMenu(int iClient, int iArg)
- {
- char szTitle[64], szID[10];
- char szNameDisplay[64], szCommand[64];
- Menu _MainMenu = new Menu(MainMenuHandle);
- GetConVarString(TitleMenu, szTitle, sizeof(szTitle));
- ReplaceString(szTitle, sizeof(szTitle), "[n]", "\n", false);
- _MainMenu.SetTitle(szTitle);
- for (int i = 1; i <= iMaxMenu; i++)
- {
- Format(szID, sizeof(szID), "%i", i);
- CfgName.GetString(szID, szNameDisplay, sizeof(szNameDisplay));
- CfgCommand.GetString(szID, szCommand, sizeof(szCommand));
- ReplaceString(szNameDisplay, sizeof(szNameDisplay), "[n]", "\n", false);
- _MainMenu.AddItem(szCommand, szNameDisplay);
- }
- _MainMenu.ExitButton = true;
- _MainMenu.Display(iClient, 0);
- }
- public int MainMenuHandle(Handle mainMenu, MenuAction action, int iClient, int iItemNum)
- {
- if(action == MenuAction_Select)
- {
- char info[32], szComm[32];
- GetMenuItem(mainMenu, iItemNum, info, sizeof(info));
- Format(szComm, sizeof(szComm), "%s", info);
- FakeClientCommand(iClient, "sm_%s", szComm);
- }
- else
- if(action == MenuAction_End)
- {
- CloseHandle(mainMenu);
- }
- }
- public void OnMapEnd()
- {
- iMaxMenu = 0;
- }
- public void OnMapStart()
- {
- iMaxMenu = 0;
- }
- public void OnConfigsExecuted()
- {
- ConfigFiles();
- }
- public void ConfigFiles()
- {
- CfgName.Clear();
- CfgCommand.Clear();
- char sPath[PLATFORM_MAX_PATH];
- Format(sPath, sizeof(sPath), "configs/MainMenu/menu.cfg");
- BuildPath(Path_SM, sPath, sizeof(sPath), sPath);
- if (!FileExists(sPath))
- return;
- KeyValues hKeyValues = CreateKeyValues("MainMenu");
- if (!hKeyValues.ImportFromFile(sPath))
- return;
- if(hKeyValues.GotoFirstSubKey())
- {
- do
- {
- char sSectionName[255];
- char sCfgName[32];
- char sCfgCommand[64];
- hKeyValues.GetSectionName(sSectionName, sizeof(sSectionName));
- hKeyValues.GetString("NameDisplay", sCfgName, sizeof(sCfgName));
- hKeyValues.GetString("Command", sCfgCommand, sizeof(sCfgCommand));
- CfgName.SetString(sSectionName, sCfgName);
- CfgCommand.SetString(sSectionName, sCfgCommand);
- iMaxMenu++;
- }
- while(hKeyValues.GotoNextKey(false));
- }
- hKeyValues.Close();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement