Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2020
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.69 KB | None | 0 0
  1. #pragma semicolon 1
  2. #include <sourcemod>
  3. #include <sdktools>
  4. #include <cstrike>
  5.  
  6. #define PLUGIN_VERSION "1.0.11"
  7. #define MAX_FILE_LEN 80
  8.  
  9. public Plugin:myinfo =
  10. {
  11. name = "Halftime teamswitch",
  12. author = "[30+]Gemeni",
  13. description = "Moves all players to the opposite team at halftime",
  14. version = PLUGIN_VERSION,
  15. url = "http://30plus.ownit.se/"
  16. };
  17.  
  18. // Global variables
  19. new mapTime;
  20. new g_maxrounds;
  21. new g_winlimit;
  22. new g_roundCount;
  23. new bool:halftime;
  24. new Handle:g_CvarSoundName = INVALID_HANDLE;
  25. new bool:g_soundEnabled;
  26. new Handle:g_h_moneyReset = INVALID_HANDLE;
  27. new Handle:g_h_mp_startmoney = INVALID_HANDLE;
  28. new Handle:g_h_mp_maxrounds = INVALID_HANDLE;
  29. new Handle:g_h_mp_winlimit = INVALID_HANDLE;
  30. new g_mp_startmoney;
  31. new bool:g_resetMoney;
  32. new bool:g_halftime_do_resetMoney = false;
  33. new Handle:g_CvarHalfTimeType = INVALID_HANDLE;
  34. new String:g_HalfTimeType[MAX_FILE_LEN];
  35. new String:g_soundName[MAX_FILE_LEN];
  36. new g_CtScore, g_TScore;
  37.  
  38. /* forwards */
  39. new Handle:g_f_on_ht = INVALID_HANDLE;
  40.  
  41. // Offsets
  42. new g_iAccount = -1;
  43.  
  44.  
  45. // Setting halftime to false
  46. public OnMapStart(){
  47. //LogToGame(">>>>>Setting halftime to false, OnMapStart<<<<<");
  48. halftime = false;
  49. g_roundCount = 0;
  50.  
  51. GetConVarString(g_CvarHalfTimeType, g_HalfTimeType, MAX_FILE_LEN);
  52. GetConVarString(g_CvarSoundName, g_soundName, MAX_FILE_LEN);
  53.  
  54. if (StrEqual(g_soundName, "")) {
  55. g_soundEnabled = false;
  56. }
  57. else {
  58. g_soundEnabled = true;
  59. }
  60.  
  61. if (g_soundEnabled) {
  62. decl String:buffer[MAX_FILE_LEN];
  63. PrecacheSound(g_soundName, true);
  64. Format(buffer, sizeof(buffer), "sound/%s", g_soundName);
  65. AddFileToDownloadsTable(buffer);
  66. }
  67.  
  68. new tmp;
  69. tmp = GetConVarInt(g_h_moneyReset);
  70. if (tmp == 1) {
  71. g_resetMoney = true;
  72. }
  73. else {
  74. g_resetMoney = false;
  75. }
  76.  
  77. g_mp_startmoney = GetConVarInt(g_h_mp_startmoney);
  78. g_maxrounds = GetConVarInt(g_h_mp_maxrounds);
  79. g_winlimit = GetConVarInt(g_h_mp_winlimit);
  80.  
  81.  
  82. }
  83.  
  84. public OnConfigsExecuted(){
  85. //LogToGame(">>>>>Setting halftime to false, OnConfigsExecuted<<<<<");
  86. halftime = false;
  87. }
  88.  
  89. // Hooking events at plugin start
  90. public OnPluginStart(){
  91. CreateConVar("sm_halftime_teamswitch_version", PLUGIN_VERSION, "Halftime teamswitch version", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY);
  92. HookEvent("round_start", Event_RoundStart);
  93. HookEvent("round_end", Event_RoundEnd);
  94.  
  95. g_CvarSoundName = CreateConVar("sm_halftime_sound", "gem_sounds/teamswitch.mp3", "The sound to play");
  96. g_h_moneyReset = CreateConVar("sm_halftime_money_reset", "1", "If weapons should be removed and money reset to mp_startmoney");
  97. g_h_mp_startmoney = FindConVar("mp_startmoney");
  98. g_h_mp_maxrounds = FindConVar("mp_maxrounds");
  99. g_h_mp_winlimit = FindConVar("mp_winlimit");
  100.  
  101. g_CvarHalfTimeType = CreateConVar("sm_halftime_teamswitch_type", "timelimit", "timelimit|maxrounds|winlimit to determin what critera halftime should be based on");
  102.  
  103. g_f_on_ht = CreateGlobalForward("gemHalftime", ET_Ignore);
  104.  
  105. // Finding offset for CS cash
  106. g_iAccount = FindSendPropOffs("CCSPlayer", "m_iAccount");
  107. if (g_iAccount == -1)
  108. SetFailState("m_iAccount offset not found");
  109.  
  110. }
  111.  
  112. // RoundStart gets the maptime
  113. // Checks to see if halftime has passed, if not then make sure halftime is 0
  114. // Setting halftime false here as well since in some occasions when extending map
  115. // team switch can occur again.
  116. public Event_RoundStart (Handle:event, const String:name[], bool:dontBroadcast)
  117. {
  118. new wepIdx;
  119. new playerTeam;
  120.  
  121. g_roundCount++;
  122. //LogMessage(">>> Increasing roundCount %d<<<", g_roundCount);
  123.  
  124. GetMapTimeLimit(mapTime);
  125. mapTime=mapTime*60;
  126.  
  127. // new mapTimeLeft;
  128. // GetMapTimeLeft(mapTimeLeft);
  129. // if(mapTimeLeft>mapTime/2) {
  130. // halftime = false;
  131. // LogToGame(">>>>>Setting halftime to false, RoundStart<<<<<");
  132. // }
  133.  
  134. if (g_resetMoney && g_halftime_do_resetMoney) {
  135. for (new client=1; client<=GetMaxClients(); client++)
  136. {
  137. if (IsClientInGame (client) && IsClientConnected(client) && !IsFakeClient(client)) {
  138. for (new w = 0; w < 6; w++)
  139. {
  140. if (w != 2 && w != 4 )
  141. while((wepIdx = GetPlayerWeaponSlot(client, w)) != -1)
  142. RemovePlayerItem(client, wepIdx);
  143. }
  144. playerTeam = GetClientTeam(client);
  145. if (playerTeam == CS_TEAM_T) {
  146. GivePlayerItem(client, "weapon_glock");
  147. }
  148. else if (playerTeam == CS_TEAM_CT) {
  149. GivePlayerItem(client, "weapon_usp");
  150. if ((wepIdx = GetPlayerWeaponSlot(client, 6)) != -1)
  151. RemovePlayerItem(client, wepIdx);
  152. }
  153. SetEntProp(client, Prop_Send, "m_ArmorValue", 0, 1);
  154. SetEntProp(client, Prop_Send, "m_bHasHelmet", 0, 1);
  155.  
  156. SetEntData(client, g_iAccount, g_mp_startmoney, 4, true);
  157. }
  158. }
  159. }
  160. g_halftime_do_resetMoney = false;
  161. }
  162.  
  163. // At Round end we check if time left of the map is passed halftime.
  164. // If so and we have not already switched teams before, switch teams and then set halftime to 1
  165. public Event_RoundEnd (Handle:event, const String:name[], bool:dontBroadcast)
  166. {
  167. new mapTimeLeft;
  168. new bool:doSwap = false;
  169. // new CTScore, TScore;
  170. new reason = GetEventInt(event, "reason");
  171. new winner = GetEventInt(event, "winner");
  172.  
  173. // Make sure that we have a normal round end
  174. // reason 16 is game commencing
  175. // other reasons are real round ends
  176. if(reason == 15) {
  177. g_CtScore = 0;
  178. g_TScore = 0;
  179. g_roundCount = 0;
  180. return;
  181. }
  182.  
  183. //LogMessage(">>> winner %d CT:%d T:%d<<<",winner, CS_TEAM_CT, CS_TEAM_T);
  184.  
  185. if (winner==CS_TEAM_T)
  186. g_TScore++;
  187. if (winner==CS_TEAM_CT)
  188. g_CtScore++;
  189.  
  190. GetMapTimeLeft(mapTimeLeft);
  191.  
  192. if ((mapTimeLeft<=mapTime/2) && StrEqual("timelimit", g_HalfTimeType)) {
  193. //LogMessage(">>> Halftime, Swap timelimit<<<");
  194. doSwap = true;
  195. }
  196. else if ((g_roundCount>=g_maxrounds/2) && StrEqual("maxrounds", g_HalfTimeType)) {
  197. //LogMessage(">>> Halftime, Swap maxrounds %d %d<<<", g_roundCount, g_maxrounds);
  198. doSwap = true;
  199. }
  200. else if ((g_roundCount>=g_winlimit/2) && StrEqual("winlimit", g_HalfTimeType)) {
  201. //LogMessage(">>> Halftime, Swap winlimit %d %d<<<", g_roundCount, g_maxrounds);
  202. doSwap = true;
  203. }
  204. else {
  205. //LogMessage(">>> Halftime, No swap <<<");
  206. doSwap = false;
  207. }
  208.  
  209. if(doSwap && (halftime == false)) {
  210. new playerTeam;
  211.  
  212. Call_StartForward(g_f_on_ht);
  213. Call_Finish();
  214.  
  215. PrintToChatAll(">>> Halftime, switching players to oposite team <<<");
  216. PrintToChatAll(">>> Removing weapons and resetting money <<<");
  217.  
  218. //LogMessage(">>> Halftime, switching players to oposite team <<<");
  219.  
  220. //LogToGame(">>>>>Setting halftime to true<<<<<");
  221. halftime = true;
  222.  
  223. //Loop through all players and see if they are in game and that they are on a team
  224. //LogMessage("Players to switch: %d", GetMaxClients());
  225. for (new i=1; i<=GetMaxClients(); i++)
  226. {
  227. if (IsClientInGame (i) && IsClientConnected(i)) {
  228.  
  229. if (IsClientInGame (i) && IsClientConnected(i) && IsFakeClient(i)) {
  230. ForcePlayerSuicide(i);
  231. }
  232.  
  233. g_halftime_do_resetMoney = true;
  234.  
  235. //LogMessage("Player %d is InGame", i);
  236. playerTeam = GetClientTeam(i);
  237. if (playerTeam == CS_TEAM_T) {
  238. //LogMessage("Before switch of %d to CT", i);
  239. CS_SwitchTeam(i, CS_TEAM_CT);
  240. if (g_soundEnabled) {
  241. EmitSoundToClient(i,g_soundName);
  242. }
  243. //LogMessage("After switch of %d to CT", i);
  244. }
  245. else if (playerTeam == CS_TEAM_CT) {
  246. //LogMessage("Before switch of %d to T", i);
  247. CS_SwitchTeam(i, CS_TEAM_T);
  248. if (g_soundEnabled) {
  249. EmitSoundToClient(i,g_soundName);
  250. }
  251. //LogMessage("After switch of %d to T", i);
  252. }
  253. else {
  254. //LogMessage("No switch, not CT not T");
  255. }
  256. }
  257. else {
  258. //LogMessage("Player %d is *NOT* InGame", i);
  259. }
  260. }
  261. //CTScore = GetTeamScore(CS_TEAM_CT);
  262. //TScore = GetTeamScore(CS_TEAM_T);
  263. //SetTeamScore(CS_TEAM_CT, TScore);
  264. //SetTeamScore(CS_TEAM_T, CTScore);
  265. new tmp;
  266. tmp = g_CtScore;
  267. g_CtScore = g_TScore;
  268. g_TScore = tmp;
  269.  
  270. //LogMessage(">>>>>halftime switch completed<<<<<");
  271. }
  272. // Else just advertise that teamswitch will occur at half time
  273. else if ((mapTimeLeft>mapTime/2) && (halftime == false)) {
  274. PrintToChatAll(">>> Players will switch teams at halftime <<<");
  275. }
  276. SetTeamScore(CS_TEAM_CT, g_CtScore);
  277. SetTeamScore(CS_TEAM_T, g_TScore);
  278. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement