michaelrw

sm_forcetimelimit_rx

Oct 23rd, 2017
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 2.64 KB | None | 0 0
  1. /**
  2.  * This program is free software; you can redistribute it and/or modify it under
  3.  * the terms of the GNU General Public License, version 3.0, as published by the
  4.  * Free Software Foundation.
  5.  *
  6.  * This program is distributed in the hope that it will be useful, but WITHOUT
  7.  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8.  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  9.  * details.
  10.  *
  11.  * You should have received a copy of the GNU General Public License along with
  12.  * this program. If not, see <http://www.gnu.org/licenses/>.
  13.  */
  14.  
  15. #define PLUGIN_VERSION "1.0x"
  16. #include <sourcemod>
  17. #include <sdktools>
  18.  
  19. new Handle:g_hTimeLimitEnforcer = INVALID_HANDLE;
  20. new g_iTimeLimit = 0;
  21. new Handle:g_enable = INVALID_HANDLE;
  22.  
  23. public Plugin:myinfo =
  24. {
  25.     name = "Time Limit Enforcer rx",
  26.     author = "St00ne",
  27.     description = "Forces a map to end when the timelimit has been reached.",
  28.     version = PLUGIN_VERSION,
  29.     url = "http://www.esc90.fr/"
  30. };
  31.  
  32. public OnPluginStart()
  33. {
  34.     CreateConVar("sm_forcetimelimit_version", PLUGIN_VERSION, "Time limit enforcer plugin version.", FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_REPLICATED|FCVAR_NOTIFY|FCVAR_DONTRECORD);
  35.     g_enable = CreateConVar("sm_forcetimelimit_enable", "0", "Enables/disables Time limit enforcer.", FCVAR_PLUGIN, true, 0.0, true, 1.0);
  36.     new Handle:hTimeLimit = FindConVar("mp_timelimit");
  37.     HookConVarChange(hTimeLimit, ConVar_TimeLimitChanged);
  38.     g_iTimeLimit = GetConVarInt(hTimeLimit)*60;
  39. }
  40.  
  41. public OnMapStart()
  42. {
  43.     //Creating repeated timer
  44.     g_hTimeLimitEnforcer = CreateTimer(30.0, Timer_CheckTimeLimit, GetTime(), TIMER_FLAG_NO_MAPCHANGE|TIMER_REPEAT);
  45. }
  46.  
  47. public OnMapEnd()
  48. {
  49.     if(g_hTimeLimitEnforcer != INVALID_HANDLE)
  50.     {
  51.         KillTimer(g_hTimeLimitEnforcer);
  52.         g_hTimeLimitEnforcer = INVALID_HANDLE;
  53.     }
  54. }
  55.  
  56. public Action:Timer_CheckTimeLimit(Handle:timer, any:time)
  57. {
  58.     if(g_iTimeLimit != 0 && (GetTime() - time) >= g_iTimeLimit)
  59.     {
  60.         if (GetConVarInt(g_enable) == 1)
  61.         {
  62.             new iGameEnd  = FindEntityByClassname(-1, "game_end");
  63.             if (iGameEnd == -1 && (iGameEnd = CreateEntityByName("game_end")) == -1)
  64.             {
  65.                 LogError("Unable to create entity \"game_end\"!");
  66.             }
  67.             else
  68.             {
  69.                 g_hTimeLimitEnforcer = INVALID_HANDLE;
  70.                 AcceptEntityInput(iGameEnd, "EndGame");
  71.                 return Plugin_Stop;
  72.             }
  73.         }
  74.     }
  75.     return Plugin_Continue;
  76. }
  77.  
  78. public ConVar_TimeLimitChanged(Handle:convar, const String:oldValue[], const String:newValue[])
  79. {
  80.     if(!StrEqual(oldValue, newValue))
  81.     {
  82.         g_iTimeLimit = StringToInt(newValue)*60;
  83.     }
  84. }
  85.  
  86. //***Thanks to Jannik 'Peace-Maker' Hartung, strontiumdog aka <eva>dog, and Bacardi.***//
  87.  
  88. //***END***//
Advertisement
Add Comment
Please, Sign In to add comment