Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //constants
- //WARNING, CANNOT JUST INCREASE RTV_LIMIT, bool doCommand IS HARD-CODED IN HANDLING ONLY 5 MAPS BECAUSE I'M LAZY AS SHIT TO MAKE A INTPARSER FUNCTION
- uint RTV_LIMIT = 5;
- //variables
- int counter;
- int required;
- bool voteStarted;
- array<string> g_RockTheVote = {};
- array<string> g_voting = {};
- array<string> rtvList = {};
- array<string> mapList = {};
- array<uint> twoMaps = {};
- array<uint> voting = {};
- string chosenMap = "";
- void PluginInit()
- {
- g_Module.ScriptInfo.SetAuthor("Some Faggot");
- g_Module.ScriptInfo.SetContactInfo("asdf");
- g_Hooks.RegisterHook(Hooks::Player::ClientSay, @ClientSay);
- g_Hooks.RegisterHook(Hooks::Player::ClientConnected, @ClientConnected);
- g_Hooks.RegisterHook(Hooks::Player::ClientDisconnect, @ClientDisconnect);
- g_Hooks.RegisterHook(Hooks::Player::ClientPutInServer, @ClientPutInServer);
- }
- void MapInit()
- {
- //reset variables
- chosenMap = "";
- voteStarted = false;
- counter = 0;
- required = -1; //not set until a player connects
- g_RockTheVote.resize(0);
- g_voting.resize(0);
- rtvList.resize(0);
- twoMaps.resize(0);
- mapList = g_MapCycle.GetMapCycle();
- voting.resize(RTV_LIMIT);
- for(uint i = 0; i < RTV_LIMIT; i++)
- {
- voting[i] = 0;
- }
- }
- CClientCommand rtv("rtv", "Rock the Vote Menu", @rtvCmd);
- void rtvCmd(const CCommand@ args)
- {
- CBasePlayer@ plr = g_ConCommandSystem.GetCurrentPlayer();
- }
- bool doCommand(CBasePlayer@ plr, const CCommand@ args)
- {
- const string steamId = g_EngineFuncs.GetPlayerAuthId(plr.edict());
- //debugging
- if(args[0] == "rtv_status")
- {
- g_PlayerFuncs.SayTextAll(plr, "counter: " + counter);
- g_PlayerFuncs.SayTextAll(plr, "required: " + required);
- return true;
- }
- if(args.ArgC() > 0 && !voteStarted)
- {
- if(args[0] == "rtv" || args[0] == "rockthevote")
- {
- //check if unique player
- if(g_RockTheVote.find(steamId) < 0)
- {
- g_RockTheVote.insertLast(steamId);
- counter++;
- g_PlayerFuncs.SayText(plr, "Rocked the vote.\n");
- }
- else
- {
- g_PlayerFuncs.SayText(plr, "Already rocked the vote!\n");
- }
- //start rtv if possible
- if(counter >= required && !voteStarted)
- {
- startVote(plr);
- }
- return true;
- }
- if(args[0] == "map" && args.ArgC() == 2)
- {
- string plr_map = args[1];
- //g_PlayerFuncs.SayText(plr, "Voting for " + plr_map + "\n");
- //check if mapcycle is valid
- if (g_MapCycle.Count() <= 0)
- {
- g_PlayerFuncs.SayText(plr, "MapCycle invalid!\n");
- }
- //check if argument is valid map
- else if(mapList.find(plr_map) < 0)
- {
- g_PlayerFuncs.SayText(plr, "Map not found!\n");
- }
- //check if list is not full
- else if(rtvList.length() == RTV_LIMIT)
- {
- g_PlayerFuncs.SayText(plr, "Rock The Vote list is full!\n");
- }
- //add map if not already in list
- else if(rtvList.find(plr_map) < 0)
- {
- rtvList.insertLast(plr_map);
- g_PlayerFuncs.SayText(plr, "Added " + plr_map +".\n");
- }
- else
- {
- g_PlayerFuncs.SayText(plr, "Map already included!\n");
- }
- return true;
- }
- }
- if(voteStarted && args.ArgC() == 2 && args[0] == "rtv")
- {
- //would opt for a switch-case but intparser doesnt seem to work
- string option = args[1];
- uint option_int = 0;
- if(option == "1")
- {
- option_int = 1;
- }
- else if(option == "2")
- {
- option_int = 2;
- }
- else if(option == "3")
- {
- option_int = 3;
- }
- else if(option == "4")
- {
- option_int = 4;
- }
- else if(option == "5")
- {
- option_int = 5;
- }
- else
- {
- g_PlayerFuncs.SayText(plr, "Invalid map choice!\n");
- return true;
- }
- //add the vote
- if(g_voting.find(steamId) < 0)
- {
- g_voting.insertLast(steamId);
- voting[option_int - 1]++;
- g_PlayerFuncs.SayText(plr, "Voted for " + rtvList[option_int - 1] + ".\n");
- }
- else
- {
- g_PlayerFuncs.SayText(plr, "Already voted!\n");
- }
- return true;
- }
- if(args[0] == "listmaps" && args.ArgC() == 1)
- {
- listmaps(plr);
- }
- return false;
- }
- void listmaps(CBasePlayer@ plr)
- {
- string text_maplist = "Maps in Rock The Vote list:";
- uint rtvList_size = rtvList.length();
- for(uint i = 0; i < rtvList_size - 1; i++)
- {
- text_maplist += " " + rtvList[i] + ",";
- }
- text_maplist += " " + rtvList[rtvList_size - 1];
- g_PlayerFuncs.SayTextAll(plr, text_maplist + "\n");
- }
- void startVote(CBasePlayer@ plr)
- {
- if(rtvList.length() < RTV_LIMIT)
- {
- addRandomMaps();
- }
- g_PlayerFuncs.SayTextAll(plr, "Enough players have rocked the vote.\n");
- voteStarted = true;
- g_PlayerFuncs.SayTextAll(plr, "There is 20 seconds to vote.\n");
- listmaps(plr);
- g_PlayerFuncs.SayTextAll(plr, "Type \"rtv [number in respect to map listed]\" to vote for a particular map\n");
- g_Scheduler.SetTimeout("vote", 25, @plr);
- }
- void vote(CBasePlayer@ plr)
- {
- //get two of the highest voted maps
- uint highest = 0;
- int highestIndex = -1;
- uint secondHighest = 0;
- int secondHighestIndex = -1;
- for(uint i = 0; i < voting.length(); i++)
- {
- if(voting[i] > highest)
- {
- secondHighest = highest;
- secondHighestIndex = highestIndex;
- highest = voting[i];
- highestIndex = i;
- }
- }
- if(highestIndex == -1)
- {
- twoMaps.insertLast(0);
- twoMaps.insertLast(1);
- }
- twoMaps.insertLast(highestIndex);
- twoMaps.insertLast(secondHighestIndex);
- if(highest == secondHighest)
- {
- g_PlayerFuncs.SayTextAll(plr, "Tie detected, choosing randomly choosing between: " + rtvList[highestIndex] + " and " + rtvList[secondHighestIndex] + "\n");
- uint randomTieBreaker = Math.RandomLong(0, 1);
- chosenMap = rtvList[twoMaps[randomTieBreaker]];
- }
- else
- {
- chosenMap = rtvList[highestIndex];
- }
- //debugging
- /*
- g_PlayerFuncs.SayTextAll(plr, "voting length: " + voting.length() + "\n");
- for(uint k = 0; k < voting.length(); k++)
- {
- g_PlayerFuncs.SayTextAll(plr, rtvList[k] + " " + voting[k] + "\n");
- }
- */
- g_PlayerFuncs.SayTextAll(plr, "Changing to " + chosenMap + " in 5 seconds....\n");
- g_Scheduler.SetTimeout("changeChosenMap", 5);
- }
- string tiebreaker()
- {
- return "";
- }
- void changeChosenMap()
- {
- g_EngineFuncs.ChangeLevel(chosenMap);
- }
- void addRandomMaps()
- {
- //duplicate maps are not checked for performance reasons
- uint rtvList_size = rtvList.length();
- uint mapList_size = mapList.length();
- for(uint i = 0; i < RTV_LIMIT - rtvList_size; i++)
- {
- rtvList.insertLast(mapList[Math.RandomLong(0, mapList_size - 1)]);
- }
- }
- HookReturnCode ClientSay(SayParameters@ pParams)
- {
- CBasePlayer@ plr = pParams.GetPlayer();
- const CCommand@ args = pParams.GetArguments();
- if(doCommand(plr, args))
- {
- pParams.ShouldHide = true;
- return HOOK_HANDLED;
- }
- return HOOK_CONTINUE;
- }
- //first player joined
- HookReturnCode ClientPutInServer(CBasePlayer@ plr)
- {
- float math = g_PlayerFuncs.GetNumPlayers() * 0.66;
- required = uint(math + 0.5);
- return HOOK_CONTINUE;
- }
- //player joined
- HookReturnCode ClientConnected(edict_t@, const string& in, const string& in, bool& out, string& out)
- {
- //update rtv player requirement
- float math = g_PlayerFuncs.GetNumPlayers() * 0.66;
- required = uint(math + 0.5);
- return HOOK_CONTINUE;
- }
- //player left
- HookReturnCode ClientDisconnect(CBasePlayer@ plr)
- {
- //update player requirement
- float math = g_PlayerFuncs.GetNumPlayers() * 0.66;
- required = uint(math + 0.5);
- return HOOK_CONTINUE;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement