Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <sourcemod>
- #include <nativevotes>
- int votefor;
- public Plugin:myinfo =
- {
- name = "slots",
- author = "unknown",
- description = "Changes the slots",
- url = ""
- }
- public OnPluginStart()
- {
- RegConsoleCmd("sm_slots", Slots_Vote, "Changes the slots");
- RegConsoleCmd("sm_slot", Slots_Vote, "Changes the slots");
- }
- public Action Slots_Vote(int client, int args)
- {
- if (GetClientTeam(client) != 2)
- {
- PrintToChat(client, "\x04You must be on the survivor team to use this command.");
- return Plugin_Handled;
- }
- if (args != 1)
- {
- PrintToChat(client, "\x04[SM] Invalid Usage: !slots <#>");
- return Plugin_Handled;
- }
- char sArgs[32];
- GetCmdArg(1, sArgs, sizeof(sArgs));
- int voteval = StringToInt(sArgs);
- if (voteval < 1 || voteval > 32)
- {
- PrintToChat(client, "\x04[SM] Invalid Usage: value cannot be less than 1 or exceed 32.");
- return Plugin_Handled;
- }
- if (voteval == FindConVar("sv_maxplayers").IntValue)
- {
- PrintToChat(client, "\x04Slots are already set to %i", voteval)
- return Plugin_Handled;
- }
- if (IsVoteInProgress())
- {
- PrintToChat(client, "\x04[SM] You cannot start a vote while one is currently going.");
- return Plugin_Handled;
- }
- // game mode check
- char sGamemode[32];
- GetConVarString(FindConVar("mp_gamemode"), sGamemode, sizeof(sGamemode));
- if ((StrContains(sGamemode, "versus") != -1 || StrContains(sGamemode, "scavenge") != -1 || StrContains(sGamemode, "mutation12") != -1 || StrContains(sGamemode, "mutation15") != -1 || StrContains(sGamemode, "mutation18") != -1) && voteval < 8)
- {
- PrintToChat(client, "\x04[SM] Cannot vote for less than 8 slots in %s mode", sGamemode);
- return Plugin_Handled;
- }
- votefor = voteval;
- Handle vote = NativeVotes_Create(MenuHandler_VoteCallback, NativeVotesType_Custom_YesNo);
- NativeVotes_SetInitiator(vote, client);
- char sDetails[256];
- FormatEx(sDetails, sizeof(sDetails), "Change slot limit to %i?", votefor);
- NativeVotes_SetDetails(vote, sDetails);
- NativeVotes_SetResultCallback(vote, VoteResultHandler);
- NativeVotes_DisplayToAll(vote, 20);
- return Plugin_Handled;
- }
- public int MenuHandler_VoteCallback(Menu menu, MenuAction action, int param1, int param2)
- {
- switch (action)
- {
- case MenuAction_VoteCancel:
- {
- if (param1 == VoteCancel_NoVotes)
- {
- NativeVotes_DisplayFail(menu, NativeVotesFail_NotEnoughVotes);
- }
- else
- {
- NativeVotes_DisplayFail(menu, NativeVotesFail_Generic);
- }
- }
- case MenuAction_End:
- {
- NativeVotes_Close(menu);
- }
- }
- }
- 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)
- {
- for (int i=0; i<num_items; i++)
- {
- if (item_indexes[i] == NATIVEVOTES_VOTE_YES && item_votes[i] > (num_clients / 2))
- {
- char sDetails[256];
- FormatEx(sDetails, sizeof(sDetails), "Changing slots to %i...", votefor);
- NativeVotes_DisplayPass(vote, sDetails);
- SetConVarInt(FindConVar("sv_maxplayers"), votefor);
- return;
- }
- }
- NativeVotes_DisplayFail(vote, NativeVotesFail_Loses);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement