SHARE
TWEET

Untitled

a guest Mar 26th, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma semicolon 1
  2.  
  3. #define DEBUG
  4.  
  5. #define PLUGIN_AUTHOR "Yellon"
  6. #define PLUGIN_VERSION "1.00"
  7.  
  8. #include <sourcemod>
  9. #include <sdktools>
  10.  
  11. #pragma newdecls required
  12.  
  13. ConVar Command;
  14. ConVar TitleMenu;
  15. int iMaxMenu;
  16.  
  17. StringMap CfgName;
  18. StringMap CfgCommand;
  19.  
  20. public Plugin myinfo =
  21. {
  22.     name = "Menu Main",
  23.     author = PLUGIN_AUTHOR,
  24.     description = "",
  25.     version = PLUGIN_VERSION,
  26.     url = "dangerzone.pl"
  27. };
  28.  
  29. public void OnPluginStart()
  30. {
  31.     Command = CreateConVar("Menu_Command", "menu,menuservera", "Komendy do wywołania menu");
  32.     TitleMenu = CreateConVar("Menu_Title", "Menu Serwerka [n] DangerZoniaków", "Tytuł menu");
  33.    
  34.     AutoExecConfig(true, "MainMenu");
  35.    
  36.     CfgName = new StringMap();
  37.     CfgCommand = new StringMap();
  38.    
  39.     CreateTimer(5.0, MenuServer, INVALID_HANDLE);
  40. }
  41.  
  42. public Action MenuServer(Handle Timer)
  43. {
  44.     char szCommand[128];
  45.     char szCommands[10][64];
  46.     char szCommands_sm[64];
  47.    
  48.     GetConVarString(Command, szCommand, sizeof(szCommand));
  49.     ExplodeString(szCommand, ",", szCommands, 64, 64, false);
  50.    
  51.     for (int i = 0; i < 10; i++)
  52.     {
  53.         if(!StrEqual(szCommands[i], ""))
  54.         {
  55.             Format(szCommands_sm, 64, "sm_%s", szCommands[i]);
  56.             RegConsoleCmd(szCommands_sm, MainMenu);
  57.         }
  58.     }
  59. }
  60.  
  61. public Action MainMenu(int iClient, int iArg)
  62. {
  63.     char szTitle[64], szID[10];
  64.     char szNameDisplay[64], szCommand[64];
  65.     Menu _MainMenu = new Menu(MainMenuHandle);
  66.    
  67.     GetConVarString(TitleMenu, szTitle, sizeof(szTitle));
  68.     ReplaceString(szTitle, sizeof(szTitle), "[n]", "\n", false);
  69.     _MainMenu.SetTitle(szTitle);
  70.    
  71.     for (int i = 1; i <= iMaxMenu; i++)
  72.     {
  73.         Format(szID, sizeof(szID), "%i", i);
  74.         CfgName.GetString(szID, szNameDisplay, sizeof(szNameDisplay));
  75.         CfgCommand.GetString(szID, szCommand, sizeof(szCommand));
  76.         ReplaceString(szNameDisplay, sizeof(szNameDisplay), "[n]", "\n", false);
  77.         _MainMenu.AddItem(szCommand, szNameDisplay);
  78.     }
  79.    
  80.     _MainMenu.ExitButton = true;
  81.     _MainMenu.Display(iClient, 0);
  82. }
  83.  
  84. public int MainMenuHandle(Handle mainMenu, MenuAction action, int iClient, int iItemNum)
  85. {
  86.     if(action == MenuAction_Select)
  87.     {
  88.         char info[32], szComm[32];
  89.         GetMenuItem(mainMenu, iItemNum, info, sizeof(info));
  90.        
  91.         Format(szComm, sizeof(szComm), "%s", info);
  92.         FakeClientCommand(iClient, "sm_%s", szComm);
  93.     }
  94.     else
  95.         if(action == MenuAction_End)
  96.     {
  97.         CloseHandle(mainMenu);
  98.     }
  99. }
  100.  
  101. public void OnMapEnd()
  102. {
  103.     iMaxMenu = 0;
  104. }
  105.  
  106. public void OnMapStart()
  107. {
  108.     iMaxMenu = 0;
  109. }
  110.  
  111. public void OnConfigsExecuted()
  112. {
  113.     ConfigFiles();
  114. }
  115.  
  116. public void ConfigFiles()
  117. {
  118.     CfgName.Clear();
  119.     CfgCommand.Clear();
  120.  
  121.     char sPath[PLATFORM_MAX_PATH];
  122.     Format(sPath, sizeof(sPath), "configs/MainMenu/menu.cfg");
  123.     BuildPath(Path_SM, sPath, sizeof(sPath), sPath);
  124.  
  125.     if (!FileExists(sPath))
  126.         return;
  127.  
  128.     KeyValues hKeyValues = CreateKeyValues("MainMenu");
  129.     if (!hKeyValues.ImportFromFile(sPath))
  130.         return;
  131.  
  132.     if(hKeyValues.GotoFirstSubKey())
  133.     {
  134.         do
  135.         {
  136.             char sSectionName[255];
  137.             char sCfgName[32];
  138.             char sCfgCommand[64];
  139.  
  140.             hKeyValues.GetSectionName(sSectionName, sizeof(sSectionName));
  141.             hKeyValues.GetString("NameDisplay",         sCfgName, sizeof(sCfgName));
  142.             hKeyValues.GetString("Command",         sCfgCommand, sizeof(sCfgCommand));
  143.            
  144.            
  145.             CfgName.SetString(sSectionName,             sCfgName);
  146.             CfgCommand.SetString(sSectionName,          sCfgCommand);
  147.            
  148.             iMaxMenu++;
  149.         }
  150.         while(hKeyValues.GotoNextKey(false));
  151.     }
  152.     hKeyValues.Close();
  153. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top