Advertisement
Guest User

hacker sp

a guest
Nov 24th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 19.09 KB | None | 0 0
  1. #include <sourcemod>
  2. #include <adt_array>
  3. #include <SDKTools>
  4. #include <cstrike>
  5. #include <CustomPlayerSkins>
  6. #include <sdkhooks>
  7. #include <halflife>
  8.  
  9. // Game constants - use these first, if need be to implement file I/O just exchange these constants with file loaded values!
  10. int MAX_PLAYERS = 12;
  11. int MIN_PLAYERS = 2;
  12. int HACKER_VOTE_DUR = 8;
  13.  
  14. char CLR_HEADER[9] = " \x01\x0B";
  15. char CLR_DEFAULT[4] = "\x01";
  16. char CLR_ERROR[4] = "\x02";
  17. char CLR_NOTIFY[4] = "\x03";
  18. char CLR_SUCCESS[4] = "\x04";
  19. char CLR_GOLD[4] =  "\x10";
  20.  
  21. // Game vars
  22. int hacker;
  23. int hackerTeam;
  24. int prevHacker;
  25. int prevHackerTeam;
  26. int roundCount;
  27. int ghost;
  28. char gameState[64];
  29. bool runningGame;
  30. bool ctHasPerk;
  31. bool tHasPerk;
  32.  
  33. ArrayList queue;
  34. ArrayList ct;
  35. ArrayList t;
  36. ArrayList readyQueue;
  37. ArrayList playerList;
  38.  
  39. public Plugin myinfo = {
  40.     name = "Hacker",
  41.     author = "Jonathan Lin",
  42.     description = "Hacker gamemode",
  43.     url = "https://brassygaming.com/",
  44. };
  45.  
  46. public void OnPluginStart() {
  47.    
  48.     // Init variables, these are defaults!
  49.     queue = CreateArray(1);
  50.     ct = CreateArray(1);
  51.     t = CreateArray(1);
  52.     readyQueue = CreateArray(1);
  53.     playerList = CreateArray(1);
  54.  
  55.     roundCount = 0;
  56.     gameState = "";
  57.     runningGame = false;
  58.     hacker = 0;
  59.     hackerTeam = 0;
  60.     prevHacker = 0;
  61.     prevHackerTeam = 0;
  62.     tHasPerk = true;
  63.     ctHasPerk = true;
  64.     ghost = 0;
  65.    
  66.     HookEvent("player_activate", OnPlayerActivate);
  67.     HookEvent("player_disconnect", OnPlayerDisconnect);
  68.     HookEvent("round_poststart", OnRoundPostStart);
  69.     HookEvent("round_end", OnRoundEnd);
  70.     HookEvent("round_start", OnRoundStart);
  71.     HookEvent("cs_intermission", OnGameEnd);
  72.     HookEvent("announce_phase_end", OnHalftime);
  73.  
  74.     HookUserMessage(GetUserMessageId("TextMsg"), OnTextChat, true);
  75.     // what
  76.    
  77.     RegConsoleCmd("queue", Command_Queue);
  78.     RegConsoleCmd("q", Command_Queue);
  79.     RegConsoleCmd("leave", Command_Leave);
  80.     RegConsoleCmd("l", Command_Leave);
  81.     RegConsoleCmd("ready", Command_Ready);
  82.     RegConsoleCmd("r", Command_Ready);
  83.     RegConsoleCmd("notready", Command_NotReady);
  84.     RegConsoleCmd("nr", Command_NotReady);
  85.    
  86.     AddCommandListener(OnJoinTeamCommand, "jointeam");
  87.    
  88.     PrintToServer(">> Hacker has been enabled!");
  89. }
  90.  
  91. public void OnPluginEnd() {
  92.     PrintToServer(">> Hacker has been disabled!");
  93. }
  94.  
  95. public Action OnTextChat(UserMsg msgId, Handle pb, const players[], playersNum, bool reliable, bool init) {
  96.     char msgType[32];
  97.     PbReadString(pb, "params", msgType, sizeof(msgType), 0);
  98.     if (StrContains(msgType, "#SFUI_Notice_Match", false) != -1) {
  99.         return Plugin_Handled;
  100.     }
  101.     return Plugin_Continue;
  102. }
  103.  
  104. public Action OnHalftime(Event event, const char[] name, bool dontBroadcast) {
  105.     PrintToServer("Switched teams");
  106.     ArrayList switchQueue1 = CreateArray(1);
  107.     ArrayList switchQueue2 = CreateArray(1);
  108.     for (int i = 0; i < ct.Length; i++) {
  109.         switchQueue1.Push(ct.Get(i));
  110.     }
  111.  
  112.     for (int i = 0; i < t.Length; i++) {
  113.         switchQueue2.Push(t.Get(i));
  114.     }
  115.  
  116.     ct.Clear();
  117.     t.Clear();
  118.  
  119.     for (int i = 0; i < switchQueue1.Length; i++) {
  120.         t.Push(switchQueue1.Get(i));
  121.     }
  122.  
  123.     for (int i = 0; i < switchQueue2.Length; i++) {
  124.         ct.Push(switchQueue2.Get(i));
  125.     }
  126.  
  127.     delete switchQueue1;
  128.     delete switchQueue2;
  129.     ClearHalf();
  130. }
  131.  
  132. public Action OnGameEnd(Event event, const char[] name, bool dontBroadcast) {
  133.     EndGame();
  134. }
  135.  
  136. // Call for pre-round votes and to increment roundCount
  137. public Action OnRoundStart(Event event, const char[] name, bool dontBroadcast) {
  138.  
  139.     gameState = "pre_round";
  140.     roundCount++;
  141.     PrintToServer("Previous round: %d, Current Round: %d", roundCount - 1, roundCount);
  142.  
  143.     // Vote on the previous round if > 0, meaning hackerTeam must be != 0
  144.     // Hacker has not been assigned yet, hacker team has no been assigned yet
  145.     if (roundCount - 1 > 0) {
  146.         if (hacker == -1) {
  147.             PrintToChatAll("%s%sSince the hacker left last round, there will be no vote.", CLR_HEADER, CLR_NOTIFY);
  148.         } else {
  149.             if (hackerTeam == 2) {
  150.                 new voters[t.Length];
  151.                 for (int i = 0; i < t.Length; i++) {
  152.                     voters[i] = t.Get(i);
  153.                 }
  154.                 Menu_HackerVote(voters, t.Length, HACKER_VOTE_DUR);
  155.             } else if (hackerTeam == 3) {
  156.                 new voters[ct.Length];
  157.                 for (int i = 0; i < ct.Length; i++) {
  158.                     voters[i] = ct.Get(i);
  159.                 }
  160.                 Menu_HackerVote(voters, ct.Length, HACKER_VOTE_DUR);
  161.             }
  162.         }
  163.     }
  164.  
  165.     // Flip the hacker team - this sets hackerTeam
  166.     PrintToServer("Hacker team assigned!");
  167.     if (hackerTeam == 0) {
  168.         int randomInt = GetRandomInt(2, 3);
  169.         hackerTeam = randomInt;
  170.     } else if (hackerTeam == 2) {
  171.         prevHackerTeam = 2;
  172.         hackerTeam = 3;
  173.     } else if (hackerTeam == 3) {
  174.         prevHackerTeam = 3;
  175.         hackerTeam = 2;
  176.     }
  177.  
  178.     // Assign the ghost
  179.     // No ghost is selected if the playerList is only 2
  180.     if (prevHackerTeam == 3 && playerList.Length > 2) {
  181.         int client = t.Get(GetRandomInt(0, t.Length - 1))
  182.         ghost = client;
  183.         PrintToServer("Ghost has been selected: %d", client);
  184.         PrintToChat(client, "%s%s>> You have been selected as the ghost! You are now invisible to the hacker! <<", CLR_HEADER, CLR_GOLD);
  185.     } else if (prevHackerTeam == 2 && playerList.Length > 2) {
  186.         int client = ct.Get(GetRandomInt(0, ct.Length - 1))
  187.         ghost = client;
  188.         PrintToServer("Ghost has been selected: %d", client);
  189.         PrintToChat(client, "%s%s>>You have been selected as the ghost! You are now invisible to the hacker! <<", CLR_HEADER, CLR_GOLD);
  190.     }
  191.  
  192.     // Set the glow
  193.     for (int i = 0; i < playerList.Length; i++) {
  194.         int client = playerList.Get(i);
  195.         if (GetClientTeam(client) != hackerTeam && client != ghost) {
  196.             PrintToServer("Client %d set to glow on team %d", client, GetClientTeam(client));
  197.             SetGlowing(client);
  198.         }
  199.     }
  200.  
  201.     return Plugin_Continue;
  202. }
  203.  
  204. public void SetGlowing(int client) {
  205.     char model[PLATFORM_MAX_PATH];
  206.     GetClientModel(client, model, sizeof(model));
  207.     CPS_RemoveSkin(client);
  208.     CPS_SetSkin(client, model, CPS_RENDER);
  209.     int skin = CPS_GetSkin(client);  
  210.  
  211.     if (SDKHookEx(skin, SDKHook_SetTransmit, OnShouldDisplay)) {
  212.         SetupGlow(skin);
  213.     }
  214. }
  215.  
  216. public void SetupGlow(int skin) {
  217.     SetEntProp(skin, Prop_Send, "m_bShouldGlow", true, true);
  218.     SetEntProp(skin, Prop_Send, "m_nGlowStyle", 0);
  219.     SetEntPropFloat(skin, Prop_Send, "m_flGlowMaxDist", 1000000000.0);
  220.     // So now setup given glow colors for the skin
  221.     SetEntData(skin, GetEntSendPropOffs(skin, "m_clrGlow"), 192, _, true);    // Red
  222.     SetEntData(skin, GetEntSendPropOffs(skin, "m_clrGlow") + 1, 160, _, true); // Green
  223.     SetEntData(skin, GetEntSendPropOffs(skin, "m_clrGlow") + 2, 96, _, true); // Blue
  224.     SetEntData(skin, GetEntSendPropOffs(skin, "m_clrGlow") + 3, 64, _, true); // Alpha
  225. }
  226.  
  227. public Action OnShouldDisplay(int entity, int client) {
  228.     if (client == hacker) {
  229.         return Plugin_Continue;
  230.     }
  231.     return Plugin_Handled;
  232. }
  233.  
  234.  
  235. // When the round actually starts, apply perks and select players
  236. public Action OnRoundPostStart(Event event, const char[] name, bool dontBroadcast) {
  237.     PrintToServer(">> Round start");
  238.     gameState = "round_start";
  239.  
  240.     if (hacker != 0 && hacker != -1) {
  241.         prevHacker = hacker;
  242.         PrintToServer("Previous hacker set to %d", prevHacker);
  243.     }
  244.     // Assign the hacker
  245.     if (hackerTeam == 2) {
  246.         hacker = ct.Get(GetRandomInt(0, ct.Length - 1));
  247.     } else if (hackerTeam == 3) {
  248.         hacker = t.Get(GetRandomInt(0, t.Length - 1));
  249.     } else {
  250.         PrintToServer("Error in assigning hacker, hackerTeam is 0!");
  251.     }
  252.     PrintToServer("Hacker set to: %d", hacker);
  253.     PrintToChat(hacker, "%s%s>> You have been selected as the hacker! <<", CLR_HEADER, CLR_GOLD);
  254.  
  255.     return Plugin_Handled;
  256. }
  257.  
  258. public Action OnRoundEnd(Event event, const char[] name, bool dontBroadcast) {
  259.     if (roundCount == 0) {
  260.         return Plugin_Continue;
  261.     }
  262.  
  263.     ctHasPerk = true;
  264.     tHasPerk = true;
  265.     PrintToServer("Perk reset!");
  266.  
  267.     PrintToServer(">> Round end");
  268.     gameState = "round_end";
  269.  
  270.     return Plugin_Continue;
  271. }
  272.  
  273. public Action OnPlayerDisconnect(Event event, const char[] name, bool dontBroadcast) {
  274.     int client = GetClientOfUserId(event.GetInt("userid"));
  275.     int queueIndex = queue.FindValue(client);
  276.     if (queueIndex != -1) {
  277.         queue.Erase(queueIndex);
  278.     }
  279.     int ctIndex = ct.FindValue(client);
  280.     int tIndex = t.FindValue(client);
  281.     if (ctIndex != -1) {
  282.         ct.Erase(ctIndex);
  283.     }
  284.     if (tIndex != -1) {
  285.         t.Erase(tIndex);
  286.     }
  287.     // If the player amount falls below MIN_PLAYERS, stop the game
  288.     if (runningGame == true && (ct.Length + t.Length < MIN_PLAYERS || ct.Length == 0 || t.Length == 0)) {
  289.         PrintToChatAll("%s%sNot enough players to continue playing!", CLR_HEADER, CLR_ERROR);
  290.         EndGame();
  291.         PrintToServer(">> Game ended because not enough players!");
  292.     }
  293.     // If the hacker leaves the game, set hacker = -1
  294.     if (hacker == client) {
  295.         hacker = -1;
  296.     }
  297.     // Add a 1 minute timer to rejoin, then automatically add someone from the queue?
  298.     return Plugin_Continue;
  299. }
  300.  
  301. public Action OnPlayerActivate(Event event, const char[] name, bool dontBroadcast) {
  302.     int client = GetClientOfUserId(event.GetInt("userid"));
  303.     ChangeClientTeam(client, 1);
  304.     CreateTimer(3.0, Timer_PlayerJoinMessage, client);
  305.     return Plugin_Continue;
  306. }
  307.  
  308. public Action Timer_PlayerJoinMessage(Handle timer, any client) {
  309.     if (IsClientInGame(client)) {
  310.         PrintToChat(client, "%s%sWelcome to %sBrassy Gaming's Hacker Server%s!", CLR_HEADER,
  311.         CLR_DEFAULT, CLR_GOLD, CLR_DEFAULT);
  312.         PrintToChat(client, "%s%sType %s/queue %sor %s/q %sto join the queue.", CLR_HEADER, CLR_NOTIFY, CLR_DEFAULT, CLR_NOTIFY,
  313.             CLR_DEFAULT, CLR_NOTIFY);
  314.     }
  315.     return Plugin_Stop;
  316.  
  317. }
  318.  
  319. // Is there a better way to block this?
  320. public Action OnJoinTeamCommand(int client, char[] command, int argc) {
  321.     PrintToChat(client, "%s%sYou cannot change teams! Type %s/queue %sto join the queue.", CLR_HEADER, CLR_ERROR, CLR_DEFAULT, CLR_ERROR);
  322.     return Plugin_Handled;
  323. }
  324.  
  325. public Action Command_NotReady(int client, int args) {
  326.     if (client) {
  327.         int queueIndex = queue.FindValue(client);
  328.         if (queueIndex != -1) {
  329.             if (readyQueue.FindValue(client) != -1) {
  330.                 readyQueue.Erase(readyQueue.FindValue(client));
  331.                 PrintToChat(client, "%s%sYou have been removed from ready status!", CLR_HEADER, CLR_ERROR);
  332.             } else {
  333.                 PrintToChat(client, "%s%sYou aren't even ready! Type %s/ready%s.", CLR_HEADER, CLR_ERROR, CLR_DEFAULT, CLR_ERROR);
  334.             }
  335.         } else {
  336.             PrintToChat(client, "%s%sYou aren't even queued! Type %s/queue%s.", CLR_HEADER, CLR_ERROR, CLR_DEFAULT, CLR_ERROR);
  337.         }
  338.     }
  339.     return Plugin_Handled;
  340. }
  341.  
  342. public Action Command_Ready(int client, int args) {
  343.     if (client) {
  344.         int queueIndex = queue.FindValue(client);
  345.         if (queueIndex != -1) {
  346.             if (queue.Length < MIN_PLAYERS) {
  347.                 PrintToChat(client, "%s%sYou can't ready yet, there aren't enough players!", CLR_HEADER, CLR_ERROR);
  348.                 return Plugin_Handled;
  349.             }
  350.             if (runningGame == true) {
  351.                 PrintToChat(client, "%s%sYou can't ready yet, there is currently a game going on!", CLR_HEADER, CLR_ERROR);
  352.                 return Plugin_Handled;
  353.             }
  354.             if (readyQueue.FindValue(client) == -1) {
  355.                 readyQueue.Push(client);
  356.                 PrintToChat(client, "%s%sReady! There are %d out of %d players ready.", CLR_HEADER, CLR_NOTIFY, readyQueue.Length, GetQueuedPlayers());
  357.             } else {
  358.                 PrintToChat(client, "%s%sThere are %d out of %d players ready.", CLR_HEADER, CLR_NOTIFY, readyQueue.Length, GetQueuedPlayers());
  359.             }
  360.             if (readyQueue.Length == GetQueuedPlayers()) {
  361.                 StartGame();
  362.             }
  363.         } else {
  364.             PrintToChat(client, "%s%sYou must use %s/queue %sto join the queue first!", CLR_HEADER, CLR_ERROR, CLR_DEFAULT, CLR_ERROR);
  365.         }
  366.         return Plugin_Handled; 
  367.     }
  368.     return Plugin_Continue;
  369. }
  370.  
  371. public int GetQueuedPlayers() {
  372.     int queuedPlayers = queue.Length;
  373.     if (queue.Length > MAX_PLAYERS) {
  374.         queuedPlayers = MAX_PLAYERS;
  375.     }
  376.     return queuedPlayers;
  377. }
  378.  
  379. public Action Command_Queue(int client, int args) {
  380.     if (client) {
  381.         int queueIndex = queue.FindValue(client);
  382.         if (ct.FindValue(client) != -1 || t.FindValue(client) != -1) {
  383.             PrintToChat(client, "%s%sYou cannot join the queue, you're already in game!", CLR_HEADER, CLR_ERROR);
  384.             return Plugin_Handled;
  385.         }
  386.         if (queueIndex == -1) {
  387.             queue.Push(client);
  388.             // Time to check if there are enough players to play!
  389.             PrintToChat(client, "%s%sYou have been added to the queue! Type %s/queue %sagain to check the queue and %s/leave %sto leave the queue!",
  390.                 CLR_HEADER, CLR_SUCCESS, CLR_DEFAULT, CLR_SUCCESS, CLR_DEFAULT, CLR_SUCCESS);
  391.             CheckStart();
  392.         } else {
  393.             PrintToChat(client, "%s%sYou are %s#%d %sin the queue!", CLR_HEADER, CLR_NOTIFY, CLR_DEFAULT, queueIndex + 1, CLR_NOTIFY);
  394.         }
  395.         return Plugin_Handled;
  396.     }
  397.     return Plugin_Continue;
  398. }
  399.  
  400. public Action Command_Leave(int client, int args) {
  401.     if (client) {
  402.         int queueIndex = queue.FindValue(client);
  403.         if (queueIndex != -1) {
  404.             queue.Erase(queueIndex);
  405.             PrintToChat(client, "%s%sYou have been removed from the queue!", CLR_HEADER, CLR_SUCCESS);
  406.         } else {
  407.             PrintToChat(client, "%s%sLmao that didn't do anything.", CLR_HEADER, CLR_ERROR);
  408.         }
  409.         return Plugin_Handled;
  410.     }
  411.     return Plugin_Continue;
  412. }
  413.  
  414. public bool CheckStart() {
  415.     if (queue.Length >= MIN_PLAYERS) {
  416.         PrintToChatAll("%s%sThe game will start when all players type %s/ready%s.", CLR_HEADER, CLR_NOTIFY, CLR_DEFAULT, CLR_NOTIFY);
  417.         return true;
  418.     }
  419.     return false;
  420. }
  421.  
  422. public void ClearGlobals() {
  423.     roundCount = 0;
  424.     gameState = "";
  425.     runningGame = false;
  426.     hacker = 0;
  427.     hackerTeam = 0;
  428.     prevHacker = 0;
  429.     prevHackerTeam = 0;
  430.     tHasPerk = true;
  431.     ctHasPerk = true;
  432.     ghost = 0;
  433. }
  434.  
  435. public void ClearHalf() {
  436.     hacker = 0;
  437.     hackerTeam = 0;
  438.     prevHacker = 0;
  439.     prevHackerTeam = 0;
  440.     tHasPerk = true;
  441.     ctHasPerk = true;
  442.     ghost = 0;
  443. }
  444.  
  445. public void EndGame() {
  446.     ClearGlobals();
  447.     for (int i = 0; i < ct.Length; i++) {
  448.         int client = ct.Get(i);
  449.         ChangeClientTeam(client, 1);
  450.     }
  451.     for (int i = 0; i < t.Length; i++) {
  452.         int client = t.Get(i);
  453.         ChangeClientTeam(client, 1);
  454.     }
  455.     t.Clear();
  456.     ct.Clear();
  457.     playerList.Clear();
  458. }
  459.  
  460. public void StartGame() {
  461.     PrintToChatAll("%s%s>> Game is live! <<", CLR_HEADER, CLR_GOLD);
  462.     runningGame = true;
  463.     t.Clear();
  464.     readyQueue.Clear();
  465.     int queuedPlayers = GetQueuedPlayers();
  466.  
  467.     // Get players into playerList
  468.     for (int i = 0; i < queuedPlayers; i++) {
  469.         playerList.Push(queue.Get(i));
  470.     }
  471.  
  472.     // Remove players in playerList from queue and add to teams
  473.     for (int i = 0; i < playerList.Length; i++) {
  474.         int client = playerList.Get(i);
  475.         queue.Erase(queue.FindValue(client));
  476.         if (ct.Length == t.Length) {
  477.             ChangeClientTeam(client, 2);
  478.             ct.Push(client);
  479.         } else if (ct.Length > t.Length) {
  480.             ChangeClientTeam(client, 3);
  481.             t.Push(client);
  482.             PrintToServer("Client %d added to team 3", client);
  483.         } else if (t.Length > ct.Length) {
  484.             ChangeClientTeam(client, 2);
  485.             ct.Push(client);
  486.             PrintToServer("Client %d added to team 2", client);
  487.         }
  488.     }
  489. }
  490.  
  491. public Action Menu_PerkVote(int[] clients, int size, int dur) {
  492.  
  493.     // This is called after hacker team changes
  494.     Menu menu = new Menu(MenuHandler_PerkVote);
  495.     menu.SetTitle("Choose a perk to fight the hacker!");
  496.     menu.AddItem("Gamble", "Gamble");
  497.     menu.AddItem("Money Hog", "Money Hog");
  498.     menu.ExitButton = false;
  499.     menu.DisplayVote(clients, size, dur);
  500.  
  501.     return Plugin_Handled;
  502.  
  503. }
  504.  
  505. public int MenuHandler_PerkVote(Menu menu, MenuAction action, int param1, int param2) {
  506.  
  507.     // This comes after hackerTeam switch so use prevHacker
  508.     if (action == MenuAction_End) {
  509.         delete menu;
  510.     } else if (action == MenuAction_VoteEnd) {
  511.         // Random Money
  512.         if (param1 == 0) {
  513.             if (prevHackerTeam == 2) {
  514.                 for (int i = 0; i < ct.Length; i++) {
  515.                     int randomAmt = GetRandomInt(2000, 8000);
  516.                     SetEntProp(ct.Get(i), Prop_Send, "m_iAccount", randomAmt);
  517.                     PrintToChat(ct.Get(i), "%s%sYour team gambled and you ended up with %s%d%s!", CLR_HEADER, CLR_NOTIFY, CLR_DEFAULT, randomAmt, CLR_NOTIFY);
  518.                 }
  519.             } else if (prevHackerTeam == 3) {
  520.                 for (int i = 0; i < t.Length; i++) {
  521.                     int randomAmt = GetRandomInt(2000, 8000);
  522.                     SetEntProp(t.Get(i), Prop_Send, "m_iAccount", randomAmt);
  523.                     PrintToChat(t.Get(i), "%s%sYour team gambled and you ended up with %s%d%s!", CLR_HEADER, CLR_NOTIFY, CLR_DEFAULT, randomAmt, CLR_NOTIFY);
  524.                 }
  525.             }
  526.         } else if (param1 == 1) {
  527.             if (prevHackerTeam == 2) {
  528.                 int client = ct.Get(GetRandomInt(0, ct.Length - 1));
  529.                 SetEntProp(client, Prop_Send, "m_iAccount", 8000);
  530.                 PrintToChat(client, "%s%sYou got all the money, money hog!", CLR_HEADER, CLR_NOTIFY);
  531.             } else if (prevHackerTeam == 3) {
  532.                 int client = t.Get(GetRandomInt(0, t.Length - 1))
  533.                 SetEntProp(client, Prop_Send, "m_iAccount", 8000);
  534.                 PrintToChat(client, "%s%sYou got all the money, money hog!", CLR_HEADER, CLR_NOTIFY);
  535.             }
  536.         }
  537.     }
  538. }
  539.  
  540. public Action Menu_HackerVote(int[] clients, int size, int dur) {
  541.    
  542.     // Vote comes before hacker team changes so it's all gucci to use hackerTeam here
  543.     Menu menu = new Menu(MenuHandler_HackerVote);
  544.     menu.SetTitle("Who was the hacker last round?");
  545.     if (hackerTeam == 2) {
  546.         for (int i = 0; i < ct.Length; i++) {
  547.             char name[255];
  548.             GetClientName(ct.Get(i), name, 255);
  549.             menu.AddItem(name, name);
  550.         }
  551.     } else if (hackerTeam == 3) {
  552.         for (int i = 0; i < t.Length; i++) {
  553.             char name[255];
  554.             GetClientName(t.Get(i), name, 255);
  555.             menu.AddItem(name, name);
  556.         }
  557.     }
  558.     menu.ExitButton = false;
  559.     menu.DisplayVote(clients, size, dur);
  560.  
  561.     return Plugin_Handled;
  562. }
  563.  
  564. public int MenuHandler_HackerVote(Menu menu, MenuAction action, int param1, int param2) {
  565.     if (action == MenuAction_End) {
  566.         delete menu;
  567.     } else if (action == MenuAction_VoteEnd) {
  568.         // Chosen index is param1 - so assuming that items were added in the right order it is the same as teamIndex for respective arraylist
  569.         // This happens after hackerTeam switch and after hacker is chosen so use prevHacker and prevHackerTeam
  570.         int teamIndex = param1;
  571.         char selectionName[255];
  572.         int prevHackerClient;
  573.         if (prevHackerTeam == 2) {
  574.             prevHackerClient = ct.Get(teamIndex);
  575.             GetClientName(prevHackerClient, selectionName, 255);
  576.         } else if (prevHackerTeam == 3) {
  577.             prevHackerClient = t.Get(teamIndex);
  578.             GetClientName(prevHackerClient, selectionName, 255);
  579.         }
  580.         PrintToServer("prevHackerClient = %d, prevHacker = %d", prevHackerClient, prevHacker);
  581.         if (prevHackerClient == prevHacker) {
  582.             // hacker selected!
  583.             if (prevHackerTeam == 2) {
  584.                 PrintToChatAll("%s%s%s %swas the hacker! %sTs %sdon't get a perk this round!", CLR_HEADER, CLR_DEFAULT, selectionName,
  585.                     CLR_NOTIFY, CLR_DEFAULT, CLR_NOTIFY);
  586.                 tHasPerk = false;
  587.             } else if (prevHackerTeam == 3) {
  588.                 PrintToChatAll("%s%s%s %swas the hacker! %sCTs %sdon't get a perk this round!", CLR_HEADER, CLR_DEFAULT, selectionName,
  589.                     CLR_NOTIFY, CLR_DEFAULT, CLR_NOTIFY);
  590.                 ctHasPerk = false;
  591.             }
  592.         } else {
  593.             // hacker not selected!
  594.             PrintToChatAll("%s%s%s%s was not the hacker!", CLR_HEADER, CLR_DEFAULT, selectionName, CLR_NOTIFY);
  595.             SendPerkVote();
  596.         }
  597.     }
  598. }
  599.  
  600. public void SendPerkVote() {
  601.     // Set the nonhacker perk
  602.     PrintToServer("Nonhacker perk vote");
  603.     if (hackerTeam == 2 && tHasPerk) {
  604.         // nonhackerTeam = 3
  605.         new voters[t.Length];
  606.         for (int i = 0; i < t.Length; i++) {
  607.             voters[i] = t.Get(i);
  608.         }
  609.         Menu_PerkVote(voters, t.Length, HACKER_VOTE_DUR);
  610.     } else if (hackerTeam == 3 && ctHasPerk) {
  611.         // nonhackerTeam = 3
  612.         new voters[ct.Length];
  613.         for (int i = 0; i < ct.Length; i++) {
  614.             voters[i] = ct.Get(i);
  615.         }
  616.         Menu_PerkVote(voters, ct.Length, HACKER_VOTE_DUR);
  617.     }
  618. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement