Guest User

Untitled

a guest
Dec 8th, 2019
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <sourcemod>
  2. #include <sdkhooks>
  3. #include <sdktools>
  4. #include <readyup>
  5. #include <colors>
  6. #include <l4d2_direct>
  7.  
  8. #define IS_VALID_CLIENT(%1) (%1 > 0 && %1 <= MaxClients)
  9. #define IS_VALID_INGAME(%1) (IS_VALID_CLIENT(%1) && IsClientInGame(%1) && !IsFakeClient(%1))
  10. #define IS_INFECTED(%1) (GetClientTeam(%1) == 3)
  11.  
  12. bool alltalk = false;
  13. bool scores_fixed = false;
  14. new Handle:gConf = INVALID_HANDLE;
  15. new Handle:fSetCampaignScores = INVALID_HANDLE;
  16.  
  17. Menu g_hVoteMenu = null;
  18.  
  19. public APLRes:AskPluginLoad2(Handle:myself, bool:late, String:error[], err_max) {
  20. MarkNativeAsOptional("IsInReady");
  21. return APLRes_Success;
  22. }
  23.  
  24. public OnPluginStart() {
  25.  
  26. gConf = LoadGameConfigFile("left4downtown.l4d2");
  27. if(gConf == INVALID_HANDLE)
  28. {
  29. LogError("Could not load gamedata/left4downtown.l4d2.txt");
  30. }
  31.  
  32. StartPrepSDKCall(SDKCall_GameRules);
  33. if(PrepSDKCall_SetFromConf(gConf, SDKConf_Signature, "SetCampaignScores")) {
  34. PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
  35. PrepSDKCall_AddParameter(SDKType_PlainOldData, SDKPass_Plain);
  36. fSetCampaignScores = EndPrepSDKCall();
  37. if(fSetCampaignScores == INVALID_HANDLE)
  38. {
  39. LogError("Function 'SetCampaignScores' found, but something went wrong.");
  40. }
  41. }
  42. else
  43. {
  44. LogError("Function 'SetCampaignScores' not found.");
  45. }
  46.  
  47. CreateTimer(1.0, Timer_Check, _, TIMER_REPEAT);
  48. HookEvent("player_left_start_area", EventHook:PlayerLeftStartArea_Event, EventHookMode_PostNoCopy);
  49. }
  50.  
  51. public OnMapStart() {
  52. scores_fixed = false;
  53. }
  54.  
  55. public PlayerLeftStartArea_Event(Handle:event, const String:name[], bool:dontBroadcast) {
  56.  
  57. // show tank vote menu
  58. //if(IsFirstMap())
  59. if(IsInReady())
  60. {
  61. ShowVote();
  62. }
  63.  
  64. }
  65.  
  66. bool InFirstRound() {
  67. return (GameRules_GetProp("m_bInSecondHalfOfRound") == 0);
  68. }
  69.  
  70. public Action:Timer_Check(Handle:timer) {
  71. // fix scores
  72. if(IsFirstMap() && IsInReady() && InFirstRound() && !scores_fixed) {
  73. scores_fixed = true;
  74.  
  75. //Determine which teams are which
  76. new SurvivorTeamIndex = GameRules_GetProp("m_bAreTeamsFlipped") ? 1 : 0;
  77. new InfectedTeamIndex = GameRules_GetProp("m_bAreTeamsFlipped") ? 0 : 1;
  78.  
  79. //Set the scores
  80. SDKCall(fSetCampaignScores, 0, 0); //visible scores
  81. L4D2Direct_SetVSCampaignScore(SurvivorTeamIndex, 0); //real scores
  82. L4D2Direct_SetVSCampaignScore(InfectedTeamIndex, 0);
  83. }
  84.  
  85. // turn all talk on
  86. if(IsFirstMap() && IsInReady() && InFirstRound() && !alltalk) {
  87. alltalk = true;
  88. ServerCommand("sm_cvar sv_alltalk 1");
  89. CPrintToChatAll("{blue}[{default}ALLTALK{blue}]{default} ON!");
  90. }
  91.  
  92. // turn all talk off
  93. if(IsFirstMap() && !IsInReady() && InFirstRound() && alltalk) {
  94. alltalk = false;
  95. ServerCommand("sm_cvar sv_alltalk 0");
  96. CPrintToChatAll("{red}[{default}ALLTALK{red}]{default} OFF!");
  97. }
  98.  
  99. return Plugin_Continue;
  100. }
  101.  
  102.  
  103.  
  104. int GetAdmin() {
  105. int admin_client = -1;
  106. for (new i = 1; i <= MaxClients; i++) {
  107. if(IS_VALID_INGAME(i)) {
  108. new AdminId:id = GetUserAdmin(i);
  109. if(id != INVALID_ADMIN_ID) {
  110. admin_client = i;
  111. break;
  112. }
  113. }
  114. }
  115. return admin_client;
  116. }
  117.  
  118. bool IsFirstMap() {
  119. bool is_first_map = false;
  120. char map[64];
  121. GetCurrentMap(map, 64);
  122. if(StrContains(map, "m1") != -1) {
  123. is_first_map = true;
  124. }
  125. return is_first_map;
  126. }
  127.  
  128. ShowVote() {
  129.  
  130. g_hVoteMenu = new Menu(Handler_VoteCallback, MENU_ACTIONS_ALL);
  131. g_hVoteMenu.SetTitle("⮞⮞⮞ Vote to choose the first tank");
  132.  
  133. int[] iClients = new int[MaxClients];
  134. int iCount = 0;
  135. char client_name[64];
  136.  
  137. for (new i = 1; i <= MaxClients; i++) {
  138. if(IS_VALID_INGAME(i) && IS_INFECTED(i)) {
  139. iClients[iCount++] = i;
  140. GetClientName(i, client_name, 64);
  141. char client_id[5];
  142. IntToString(i, client_id, sizeof(client_id));
  143. g_hVoteMenu.AddItem(client_id, client_name);
  144. }
  145. }
  146. PrintToServer("First tank vote initialized.");
  147. g_hVoteMenu.ExitButton = false;
  148. g_hVoteMenu.DisplayVote(iClients, iCount, 30);
  149.  
  150. }
  151.  
  152. public int Handler_VoteCallback(Menu menu, MenuAction action, param1, param2) {
  153. if (action == MenuAction_VoteEnd) {
  154.  
  155. char item[64], display[64];
  156. int votes, totalVotes;
  157. int admin_id = GetAdmin();
  158.  
  159. GetMenuVoteInfo(param2, votes, totalVotes);
  160.  
  161. if(totalVotes == 0) {
  162. if(admin_id != -1) {
  163. ClientCommand(admin_id, "sm_tankshuffle");
  164. char msg[128];
  165. msg = "\x04[TANK VOTE]\x01 None vote taken. The firt tank will be choose randomly.";
  166. PrintToInfected(msg);
  167. } else {
  168. PrintToChatAll("\x04[TANK VOTE]\x01 First tank vote not working this time.");
  169. }
  170. } else {
  171. menu.GetItem(param1, item, sizeof(item), _, display, sizeof(display));
  172. char client_name[64];
  173. int id = StringToInt(item);
  174. GetClientName(id, client_name, sizeof(client_name));
  175. if(admin_id != -1) {
  176. ClientCommand(admin_id, "sm_givetank %s", client_name);
  177. char buff[128];
  178. Format(buff, 128, "\x04[TANK VOTE]\x01 \x03%s\x01 will be the first tank with \x03%d votes\x01.", client_name, votes);
  179. PrintToInfected(buff);
  180. } else {
  181. PrintToChatAll("\x04[TANK VOTE]\x01 First tank vote not working this time.");
  182. }
  183. }
  184.  
  185. } else if (action == MenuAction_End) {
  186. VoteMenuClose();
  187. }
  188. return 0;
  189. }
  190.  
  191. PrintToInfected(char message[128]) {
  192. for (new i = 1; i <= MaxClients; i++) {
  193. if(IS_VALID_INGAME(i) && IS_INFECTED(i)) {
  194. PrintToChat(i, message);
  195. }
  196. }
  197. }
  198.  
  199. void VoteMenuClose() {
  200. delete g_hVoteMenu;
  201. }
RAW Paste Data