Advertisement
Guest User

Untitled

a guest
May 24th, 2023
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 9.24 KB | None | 0 0
  1. #include <sdktools>
  2. #include <vip_core>
  3.  
  4. public Plugin myinfo = {name = "VIP_WeaponPack | Weapon set", author = "Drumanid", version = "2.0 [ FINAL ? ]", url = "http://vk.com/drumanid | http://hlmod.ru"}
  5.  
  6. #pragma newdecls required
  7. #pragma semicolon 1
  8.  
  9. int g_iRounds;
  10. int g_iRound[MAXPLAYERS+1];
  11.  
  12. #define VIP_WEAPONPACK  "Weaponpack"
  13.  
  14. ConVar c_RoundMenu;
  15. ConVar c_RoundLimit;
  16.  
  17. Handle kv;
  18. char MenuName[PLATFORM_MAX_PATH];
  19.  
  20. //======================================================================================================================================================================
  21. // Registration
  22. //======================================================================================================================================================================
  23. public void OnPluginStart()
  24. {
  25.     RegConsoleCmd("wp", WeaponMenuCmd);
  26.    
  27.     HookEvent("round_start", RoundStart, EventHookMode_Pre);
  28.     c_RoundMenu = CreateConVar("c_RoundMenu", "0", "1 - Turn on / 0 - Switch off | Displays a menu at the beginning of the round for VIP players");
  29.     c_RoundLimit = CreateConVar("c_RoundLimit", "1", "0 - Can always be used | How many rounds to prevent a VIP player from using again WeaponPack");  
  30.    
  31.     if(VIP_IsVIPLoaded())
  32.     {
  33.         VIP_OnVIPLoaded();
  34.     }
  35.    
  36.     kv = CreateKeyValues("WeaponPack");
  37.     if(FileToKeyValues(kv, "addons/sourcemod/data/vip/modules/WeaponPack.ini"))
  38.     {
  39.         PrintToServer("| VIP | WeaponPack.ini uploaded successfully!");
  40.     }
  41.     else
  42.     {
  43.         PrintToServer("No found: addons/sourcemod/data/vip/modules/WeaponPack.ini");
  44.         LogError("No found: addons/sourcemod/data/vip/modules/WeaponPack.ini");
  45.     }
  46.    
  47.     AutoExecConfig(true, "VIP_WeaponPack", "vip");
  48. }
  49.  
  50. //======================================================================================================================================================================
  51. // We issue the menu "Do you want" at the beginning of each round to the VIP player
  52. //======================================================================================================================================================================
  53. public Action RoundStart(Handle event, const char[] name, bool dontBroadcast)
  54. {
  55.     if(GetConVarInt(c_RoundMenu) == 1)
  56.     {
  57.         for(int i = 1; i <= MaxClients; i++)
  58.         {
  59.             if(IsClientInGame(i))
  60.             {
  61.                 if(VIP_IsClientVIP(i) && VIP_IsClientFeatureUse(i, VIP_WEAPONPACK))
  62.                 {
  63.                     RoundMenu(i);
  64.                 }
  65.             }
  66.         }
  67.     }
  68. }
  69.  
  70. public int RoundMenu(int client)
  71. {
  72.     char map[PLATFORM_MAX_PATH];
  73.     GetCurrentMap(map, sizeof(map));
  74.  
  75.     if((strncmp(map, "35hp_", 5) == 0) || (strncmp(map, "awp_", 4) == 0))
  76.     {
  77.         return;
  78.     }
  79.     else
  80.     {
  81.         if(GameRules_GetProp("m_bWarmupPeriod") == 1)
  82.         {
  83.             return;
  84.         }
  85.         else
  86.         {
  87.             g_iRounds = GetRound();
  88.             if(g_iRounds < 2)
  89.             {
  90.                 return;
  91.             }
  92.         }
  93.    
  94.         if(IsPlayerAlive(client))
  95.         {
  96.             if(g_iRound[client] > g_iRounds)
  97.             {
  98.                 PrintToChat(client, " \x07The weapon set will be available through: \x04%i\x07 round(s)!", g_iRound[client] - g_iRounds);
  99.                 return;
  100.             }
  101.             else
  102.             {
  103.                 Panel hPanel = new Panel();
  104.                 hPanel.SetTitle( "Do you want to use WeaponPack?\n \n");
  105.                 hPanel.DrawItem("Yes");
  106.                 hPanel.DrawItem("No");
  107.  
  108.                 hPanel.Send(client, SelectMenu, 0);
  109.                 delete hPanel;
  110.             }
  111.         }
  112.     }
  113. }
  114.  
  115. public int SelectMenu(Menu hPanel, MenuAction action, int client, int option)
  116. {
  117.     if(action == MenuAction_Select && option == 1)
  118.     {
  119.         WeaponMenu(client);
  120.     }
  121. }
  122.  
  123. //======================================================================================================================================================================
  124. // Register the module in the VIP system
  125. //======================================================================================================================================================================
  126. public void VIP_OnVIPLoaded()
  127. {
  128.     VIP_RegisterFeature(VIP_WEAPONPACK, BOOL, SELECTABLE, OnSelectItem);
  129. }
  130.  
  131. public bool OnSelectItem(int client, const char[] sFeatureName)
  132. {
  133.     WeaponMenu(client);
  134.     return;
  135. }
  136.  
  137. //======================================================================================================================================================================
  138. // Checking and running the !wp command
  139. //======================================================================================================================================================================
  140. public Action WeaponMenuCmd(int client, int args)
  141. {
  142.     if(client > 0 && args < 1 && VIP_IsClientVIP(client) && VIP_IsClientFeatureUse(client, VIP_WEAPONPACK))
  143.     {
  144.         WeaponMenu(client);
  145.     }
  146.     return Plugin_Handled;
  147. }
  148.  
  149. //======================================================================================================================================================================
  150. // Execute menu items
  151. //======================================================================================================================================================================
  152. public int SelectWeapon(Handle menu, MenuAction action, int client, int option)
  153. {
  154.     switch(action)
  155.     {
  156.         case MenuAction_End:
  157.         {
  158.             CloseHandle(menu);
  159.         }
  160.         case MenuAction_Select:
  161.         {
  162.             GetMenuItem(menu, option, MenuName, sizeof(MenuName));
  163.  
  164.             KvRewind(kv);
  165.             if(KvJumpToKey(kv, MenuName, false))
  166.             {
  167.                 char sBuffer[64];
  168.                 if(KvGotoFirstSubKey(kv, false))
  169.                 {
  170.                     g_iRound[client] = g_iRounds + GetConVarInt(c_RoundLimit);
  171.                     do
  172.                     {
  173.                         KvGetSectionName(kv, sBuffer, sizeof(sBuffer));
  174.                         if(!StrEqual(sBuffer, "weapon"))
  175.                         {
  176.                             continue;
  177.                         }
  178.                         KvGetString(kv, NULL_STRING, sBuffer, sizeof(sBuffer));
  179.                         GivePlayerItem(client, sBuffer);
  180.                     }
  181.                     while(KvGotoNextKey(kv, false));
  182.                 }
  183.             }
  184.         }
  185.     }
  186. }
  187.  
  188. //======================================================================================================================================================================
  189. // The menu itself
  190. //======================================================================================================================================================================
  191. public int WeaponMenu(int client)
  192. {
  193.     char map[PLATFORM_MAX_PATH];
  194.     GetCurrentMap(map, sizeof(map));
  195.  
  196.     if((strncmp(map, "35hp_", 5) == 0) || (strncmp(map, "awp_", 4) == 0))
  197.     {
  198.         PrintToChat(client, " \x07You can't pick up a set of weapons on this map!");
  199.         ClientCommand(client,"play buttons/weapon_cant_buy.wav");
  200.         return;
  201.     }
  202.     else
  203.     {
  204.         if(GameRules_GetProp("m_bWarmupPeriod") == 1)
  205.         {
  206.             PrintToChat(client, " \x07You can not take a set of weapons during the warm-up!");
  207.             ClientCommand(client,"play buttons/weapon_cant_buy.wav");
  208.             return;
  209.         }
  210.         else
  211.         {
  212.             g_iRounds = GetRound();
  213.             if(g_iRounds < 2)
  214.             {
  215.                 PrintToChat(client, " \x07You cannot take a set of weapons in \x02first\x07 round!");
  216.                 ClientCommand(client,"play buttons/weapon_cant_buy.wav");
  217.                 return;
  218.             }
  219.         }
  220.         if(IsPlayerAlive(client))
  221.         {
  222.             if(g_iRound[client] > g_iRounds)
  223.             {
  224.                 PrintToChat(client, " \x07It will be possible to take again through \x04%i\x07 round(s)!", g_iRound[client] - g_iRounds);
  225.                 ClientCommand(client,"play buttons/weapon_cant_buy.wav");
  226.                 return;
  227.             }
  228.             else
  229.             {
  230.                 Handle menu = CreateMenu(SelectWeapon);
  231.                 SetMenuTitle(menu, "★ Weapon Pack Menu ★");
  232.                
  233.                 KvRewind(kv);
  234.                 if(KvGotoFirstSubKey(kv))
  235.                 {
  236.                     do
  237.                     {
  238.                         if(KvGetSectionName(kv, MenuName, sizeof(MenuName)))
  239.                         {
  240.                             if(GetClientTeam(client) == KvGetNum(kv, "Team", 0) || KvGetNum(kv, "Team", 0) == 0)
  241.                             {
  242.                                 AddMenuItem(menu, MenuName, MenuName);
  243.                             }
  244.                         }
  245.                     }
  246.                     while(KvGotoNextKey(kv));
  247.                 }
  248.                 SetMenuExitButton(menu, true);
  249.                 DisplayMenu(menu, client, 0);
  250.             }
  251.         }
  252.         else
  253.         {
  254.             PrintToChat(client, " \x07You must be alive in order to take a set of weapons!");
  255.             ClientCommand(client,"play buttons/weapon_cant_buy.wav");
  256.         }
  257.     }
  258. }
  259. public void OnClientPostAdminCheck(int client)
  260. {
  261.     g_iRound[client] = 0;
  262. }
  263.  
  264. //======================================================================================================================================================================
  265. // Checking the rounds
  266. //======================================================================================================================================================================
  267. stock int GetRound()
  268. {
  269.     static ConVar mp_halftime, mp_maxrounds;
  270.     if(!mp_halftime)
  271.     {
  272.         mp_halftime = FindConVar("mp_halftime");
  273.         mp_maxrounds = FindConVar("mp_maxrounds");
  274.     }
  275.        
  276.     int total_score = GetTeamScore(2) + GetTeamScore(3) + 1;
  277.     if (mp_halftime.IntValue == 1)
  278.     {
  279.         int halftimer = mp_maxrounds.IntValue/2;
  280.         if(halftimer < total_score) return total_score - mp_maxrounds.IntValue/2;
  281.     }
  282.     return total_score;
  283. }
  284.  
  285. //======================================================================================================================================================================
  286. // Unloading a module
  287. //======================================================================================================================================================================
  288. public void OnPluginEnd()
  289. {
  290.     if(CanTestFeatures() && GetFeatureStatus(FeatureType_Native, "VIP_WEAPONPACK") == FeatureStatus_Available)
  291.     {
  292.         VIP_UnregisterFeature(VIP_WEAPONPACK);
  293.     }
  294. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement