Advertisement
Guest User

slots.sp

a guest
Dec 20th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.14 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <nativevotes>
  3.  
  4. int votefor;
  5.  
  6. public Plugin:myinfo =
  7. {
  8.     name = "slots",
  9.     author = "unknown",
  10.     description = "Changes the slots",
  11.     url = ""
  12. }
  13.  
  14. public OnPluginStart()
  15. {
  16.     RegConsoleCmd("sm_slots", Slots_Vote, "Changes the slots");
  17.     RegConsoleCmd("sm_slot", Slots_Vote, "Changes the slots");
  18. }
  19.  
  20. public Action Slots_Vote(int client, int args)
  21. {  
  22.  
  23.     if (GetClientTeam(client) != 2)
  24.     {
  25.         PrintToChat(client, "\x04You must be on the survivor team to use this command.");
  26.         return Plugin_Handled;
  27.     }
  28.    
  29.     if (args != 1)
  30.     {
  31.         PrintToChat(client, "\x04[SM] Invalid Usage: !slots <#>");
  32.         return Plugin_Handled;
  33.     }
  34.    
  35.     char sArgs[32];
  36.     GetCmdArg(1, sArgs, sizeof(sArgs));
  37.     int voteval = StringToInt(sArgs);
  38.    
  39.     if (voteval < 1 || voteval > 32)
  40.     {
  41.         PrintToChat(client, "\x04[SM] Invalid Usage: value cannot be less than 1 or exceed 32.");
  42.         return Plugin_Handled;
  43.     }
  44.    
  45.     if (voteval == FindConVar("sv_maxplayers").IntValue)
  46.     {
  47.         PrintToChat(client, "\x04Slots are already set to %i", voteval)
  48.         return Plugin_Handled;
  49.     }
  50.    
  51.     if (IsVoteInProgress())
  52.     {
  53.         PrintToChat(client, "\x04[SM] You cannot start a vote while one is currently going.");
  54.         return Plugin_Handled;
  55.     }
  56.  
  57.     // game mode check
  58.     char sGamemode[32];
  59.     GetConVarString(FindConVar("mp_gamemode"), sGamemode, sizeof(sGamemode));
  60.    
  61.     if ((StrContains(sGamemode, "versus") != -1 || StrContains(sGamemode, "scavenge") != -1 || StrContains(sGamemode, "mutation12") != -1 || StrContains(sGamemode, "mutation15") != -1 || StrContains(sGamemode, "mutation18") != -1) && voteval < 8)
  62.     {
  63.         PrintToChat(client, "\x04[SM] Cannot vote for less than 8 slots in %s mode", sGamemode);
  64.         return Plugin_Handled;
  65.     }
  66.    
  67.     votefor = voteval;
  68.    
  69.     Handle vote = NativeVotes_Create(MenuHandler_VoteCallback, NativeVotesType_Custom_YesNo);
  70.     NativeVotes_SetInitiator(vote, client);
  71.    
  72.     char sDetails[256];
  73.     FormatEx(sDetails, sizeof(sDetails), "Change slot limit to %i?", votefor);
  74.     NativeVotes_SetDetails(vote, sDetails);
  75.     NativeVotes_SetResultCallback(vote, VoteResultHandler);
  76.     NativeVotes_DisplayToAll(vote, 20);
  77.    
  78.     return Plugin_Handled;
  79. }
  80.  
  81. public int MenuHandler_VoteCallback(Menu menu, MenuAction action, int param1, int param2)
  82. {
  83.     switch (action)
  84.     {
  85.         case MenuAction_VoteCancel:
  86.         {
  87.             if (param1 == VoteCancel_NoVotes)
  88.             {
  89.                 NativeVotes_DisplayFail(menu, NativeVotesFail_NotEnoughVotes);
  90.             }
  91.             else
  92.             {
  93.                 NativeVotes_DisplayFail(menu, NativeVotesFail_Generic);
  94.             }
  95.         }
  96.        
  97.         case MenuAction_End:
  98.         {
  99.             NativeVotes_Close(menu);
  100.         }
  101.     }
  102. }
  103.  
  104. public int VoteResultHandler(Handle vote, int num_votes, int num_clients, const int[] client_indexes, const int[] client_votes, int num_items, const int[] item_indexes, const int[] item_votes)
  105. {
  106.     for (int i=0; i<num_items; i++)
  107.     {
  108.         if (item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients / 2))
  109.         {
  110.             char sDetails[256];
  111.             FormatEx(sDetails, sizeof(sDetails), "Changing slots to %i...", votefor);
  112.             NativeVotes_DisplayPass(vote, sDetails);
  113.            
  114.             SetConVarInt(FindConVar("sv_maxplayers"), votefor);
  115.             return;
  116.         }
  117.     }
  118.    
  119.     NativeVotes_DisplayFail(vote, NativeVotesFail_Loses);
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement