Advertisement
Guest User

toggle

a guest
Jul 20th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. #include <sourcemod>
  2.  
  3. new g_iTimeLimit;
  4. ConVar g_Cvar_Timelimit;
  5. int g_iTeamsReady;
  6. bool g_bTimerSetBack; //i.e have we already changed the var to its default
  7.  
  8. public Plugin myinfo =
  9. {
  10. name = "TimeLimit Toggle",
  11. author = "tevo",
  12. description = "toggles the command mp_timelimit between 0 and the set server time limit",
  13. version = "0.1",
  14. url = "http://www.sourcemod.net/"
  15. };
  16.  
  17. public void OnPluginStart()
  18. {
  19. g_Cvar_Timelimit = FindConVar("mp_timelimit");
  20. RegAdminCmd("sm_timeon", Command_TimeOn, ADMFLAG_GENERIC);
  21. RegAdminCmd("sm_timeoff", Command_TimeOff, ADMFLAG_GENERIC);
  22. HookEvent("teamplay_round_start", Event_RoundStart);
  23. HookEvent("tournament_stateupdate", Event_StateUpdate);
  24. }
  25.  
  26. public void OnConfigsExecuted()
  27. {
  28. g_bTimerSetBack = false;
  29. g_iTeamsReady = 0;
  30. g_iTimeLimit = g_Cvar_Timelimit.IntValue; //stores the timelimit value as loaded in server.cfg file.
  31. g_Cvar_Timelimit.SetInt(0); //disables timelimit
  32. }
  33.  
  34. public Action Command_TimeOn(int client, int args)
  35. {
  36. PrintToServer("Timeon");
  37. g_Cvar_Timelimit.SetInt(g_iTimeLimit);
  38. return Plugin_Handled;
  39. }
  40.  
  41. public Action Command_TimeOff(int client, int args)
  42. {
  43. PrintToServer("Timeoff");
  44. g_Cvar_Timelimit.SetInt(0);
  45. return Plugin_Handled;
  46. }
  47.  
  48. public void Event_StateUpdate(Event event, const char[] name, bool dontBroadcast)
  49. {
  50. new iStateUpdate = event.GetBool("readystate");
  51. if (iStateUpdate == 1)
  52. {
  53. g_iTeamsReady++;
  54. }
  55. else
  56. {
  57. g_iTeamsReady--;
  58. }
  59. PrintToServer("TEAMS READY: %d", g_iTeamsReady);
  60. }
  61.  
  62. public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
  63. {
  64. if ((g_bTimerSetBack == false) && (g_iTeamsReady == 2))
  65. {
  66. g_Cvar_Timelimit.SetInt(g_Cvar_Timelimit);
  67. g_bTimerSetBack = true;
  68. }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement