Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.89 KB | None | 0 0
  1. #pragma semicolon 1
  2.  
  3. #define DEBUG
  4.  
  5. #define PLUGIN_AUTHOR "Diam0ndzx"
  6. #define PLUGIN_VERSION "1.0"
  7.  
  8. #include <sourcemod>
  9. #include <sdktools>
  10. #include <cstrike>
  11.  
  12. #pragma newdecls required
  13.  
  14. EngineVersion g_Game;
  15.  
  16. #define PREFIX " \x01 [\x0CDeathrun\x01]\x07"
  17.  
  18. ConVar autoHopping;
  19.  
  20. int currentTRound = 0;
  21.  
  22. bool isFreerun = false;
  23.  
  24. public Plugin myinfo =
  25. {
  26. name = "Deathrun",
  27. author = PLUGIN_AUTHOR,
  28. description = "The base Deathrun plugin",
  29. version = PLUGIN_VERSION,
  30. url = "https://steamcommunity.com/id/Diam0ndz/"
  31. };
  32.  
  33. public void OnPluginStart()
  34. {
  35. g_Game = GetEngineVersion();
  36. if(g_Game != Engine_CSGO && g_Game != Engine_CSS)
  37. {
  38. SetFailState("This plugin is for CSGO/CSS only.");
  39. }
  40. autoHopping = FindConVar("sv_autobunnyhopping");
  41. autoHopping.IntValue = 1;
  42.  
  43. AddCommandListener(Command_JoinTeam, "jointeam");
  44.  
  45. HookEvent("round_poststart", OnRoundPostStart);
  46. HookEvent("round_end", OnRoundEnd);
  47.  
  48. RegConsoleCmd("sm_freerun", Command_Freerun, "If you are a T, calls a freerun.");
  49. }
  50.  
  51. public void OnMapStart()
  52. {
  53. CreateTimer(90.0, Timer_CheckTPlayers, _, TIMER_REPEAT | TIMER_FLAG_NO_MAPCHANGE); //Create timer that checks every 90 seconds to force player on T if there isn't already
  54. }
  55.  
  56. public Action OnRoundPostStart(Event event, const char[] name, bool dontBroadcast)
  57. {
  58. if(GetTeamClientCount(CS_TEAM_T) >= 1)
  59. {
  60. currentTRound++;
  61. }else
  62. {
  63. PrintToChatAll("%s \x07 There are currently no Terrorists!", PREFIX);
  64. }
  65. }
  66.  
  67. public Action OnRoundEnd(Event event, const char[] name, bool dontBroadcast)
  68. {
  69. if(GetTeamClientCount(CS_TEAM_T) >= 1)
  70. {
  71. if(currentTRound >= 3)
  72. {
  73. for (int i = 1; i <= MaxClients; i++)
  74. {
  75. if(IsValidClient(i) && GetClientTeam(i) == CS_TEAM_T)
  76. {
  77. int randomPlayer = GetRandomPlayerFromTeam(CS_TEAM_CT);
  78. CS_SwitchTeam(randomPlayer, CS_TEAM_T);
  79.  
  80. ChangeTeam(i, CS_TEAM_CT);
  81. currentTRound = 0;
  82.  
  83. char currentT[] = "";
  84. GetClientName(i, currentT, sizeof(currentT));
  85.  
  86. char goingToBeT[] = "";
  87. GetClientName(i, goingToBeT, sizeof(goingToBeT));
  88.  
  89. PrintToChatAll("%s \x07 Rotating %s out for %s.", PREFIX, currentT, goingToBeT);
  90. }
  91. }
  92. }
  93. }else
  94. {
  95. PrintToChatAll("%s \x07 There are currently no Terrorists!", PREFIX);
  96. }
  97. isFreerun = false;
  98. BalanceTeams();
  99. }
  100.  
  101. public Action Timer_CheckTPlayers(Handle timer)
  102. {
  103. if(GetClientCount() >= 3) //Check if there are at least 3 players
  104. {
  105. if(GetTeamClientCount(CS_TEAM_T) < 1) //Check if there is no one on T
  106. {
  107. CS_SwitchTeam(GetRandomPlayerFromTeam(CS_TEAM_CT), CS_TEAM_T); //Switch a random player on CT to T
  108. CS_TerminateRound(0.5, CSRoundEnd_Draw, true);
  109. PrintToChatAll("%s \x07 Force switching a random player to T!", PREFIX);
  110. }else
  111. {
  112. PrintToServer("%s \x07 There is already a player on T!", PREFIX);
  113. }
  114. }else
  115. {
  116. PrintToServer("%s \x07 There aren't at least three players", PREFIX);
  117. }
  118. }
  119.  
  120. public Action Command_Freerun(int client, int args)
  121. {
  122. if(GetClientTeam(client) != CS_TEAM_T)
  123. {
  124. PrintToChat(client, "%s \x07 You must be a T in order to call a freerun!", PREFIX);
  125. return Plugin_Handled;
  126. }
  127. if(isFreerun)
  128. {
  129. PrintToChat(client, "%s \x07 There is already a freerun.", PREFIX);
  130. return Plugin_Handled;
  131. }
  132. isFreerun = true;
  133. return Plugin_Handled;
  134. }
  135.  
  136. public Action Command_JoinTeam(int client, const char[] command, int argc)
  137. {
  138. if(IsValidClient(client))
  139. {
  140. if(GetClientTeam(client) == CS_TEAM_T)
  141. {
  142. PrintToChat(client, "%s \x07 Switching off of T is forbidden!", PREFIX);
  143. return Plugin_Stop;
  144. }
  145. }
  146. return Plugin_Continue;
  147. }
  148.  
  149. public void BalanceTeams()
  150. {
  151. if(GetClientCount(true) < 15)
  152. {
  153. if(GetPlayerTeamCount(CS_TEAM_T) > 1)
  154. {
  155. for (int i = 1; i <= MaxClients - 1; i++)
  156. {
  157. ChangeTeam(i, CS_TEAM_CT);
  158. }
  159. PrintToChatAll("%s \x07 Teams have been balanced!", PREFIX);
  160. }
  161. }else if(GetClientCount(true) >= 15)
  162. {
  163. if(GetPlayerTeamCount(CS_TEAM_T) > 2)
  164. {
  165. for (int i = 1; i <= MaxClients - 2; i++)
  166. {
  167. ChangeTeam(i, CS_TEAM_CT);
  168. }
  169. PrintToChatAll("%s \x07 Teams have been balanced!", PREFIX);
  170. }
  171. }
  172. }
  173.  
  174. public void ChangeTeam(int client, int team)
  175. {
  176. if(GetClientTeam(client) == team)
  177. {
  178. PrintToChat(client, "%s \x07 Can't switch player to a team they are already on!", PREFIX);
  179. }
  180. CS_SwitchTeam(client, team);
  181. }
  182.  
  183. stock int GetRandomPlayerFromTeam(int team) //Get a random player from a specific team
  184. {
  185. int[] clients = new int[MaxClients + 1];
  186. int clientCount;
  187. for (int i = 1; i <= MaxClients; i++)
  188. if (IsClientInGame(i) && (GetClientTeam(i) == team))
  189. clients[clientCount++] = i;
  190. return (clientCount == 0) ? -1 : clients[GetRandomInt(0, clientCount - 1)];
  191. }
  192.  
  193. stock int GetPlayerTeamCount(int team)
  194. {
  195. int players = 0;
  196. for (int i = 1; i <= MaxClients; i++)
  197. {
  198. if(GetClientTeam(i) == team)
  199. players++;
  200. }
  201. return players;
  202. }
  203.  
  204. stock bool IsValidClient(int client)
  205. {
  206. if(client <= 0 ) return false;
  207. if(client > MaxClients) return false;
  208. if(!IsClientConnected(client)) return false;
  209. return IsClientInGame(client);
  210. }
  211.  
  212. public int HandleFreerunMenu(Menu menu, MenuAction action, int param1, int param2)
  213. {
  214. switch(action)
  215. {
  216. case MenuAction_Select:
  217. {
  218. char info[32];
  219. menu.GetItem(param2, info, sizeof(info));
  220. if(StrEqual(info, "yes"))
  221. {
  222. for (int i = 1; i <= 5; i++)
  223. {
  224. PrintToChatAll("%s \x07 Freerun Activated!", PREFIX);
  225. }
  226. isFreerun = true;
  227. }
  228. else
  229. {
  230. PrintToChat(param1, "%s \x07 Freerun confirmation canceled.", PREFIX);
  231. isFreerun = false;
  232. }
  233. }
  234. }
  235. }
  236.  
  237. public Action Menu_Freerun(int client, int args)
  238. {
  239. Menu freerunMenu = new Menu(HandleFreerunMenu, MENU_ACTIONS_DEFAULT);
  240. freerunMenu.SetTitle("Freerun?");
  241. freerunMenu.AddItem("yes", "Yes");
  242. freerunMenu.AddItem("no", "No");
  243. freerunMenu.ExitButton = false;
  244. freerunMenu.Display(client, 20);
  245. return Plugin_Handled;
  246. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement