This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
roundtimer.sp
187 lines (159 loc) · 5.7 KB
/
roundtimer.sp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#pragma semicolon 1
// ====[ INCLUDES ]============================================================
#include <sourcemod>
#include <sdktools>
// ====[ DEFINES ]=============================================================
#define PLUGIN_VERSION "1.4.1"
// ====[ HANDLES | CVARS ]=====================================================
new Handle:g_hCvarEnabled;
new Handle:g_hCvarTime;
new Handle:g_hCvarCommands;
new Handle:g_hCvarHud;
new Handle:g_hCvarCenter;
new Handle:g_hCvarHudX;
new Handle:g_hCvarHudY;
new Handle:g_hTimer;
new Handle:g_hHud;
// ====[ CVAR VARIABLES ]======================================================
new g_iTime;
new bool:g_bEnabled;
new bool:g_bHud;
new bool:g_bCenter;
new Float:g_iHudX;
new Float:g_iHudY;
new String:g_strCommands[255];
// ====[ VARIABLES ]===========================================================
new g_iRemaining;
new bool:g_bArena;
// ====[ PLUGIN ]==============================================================
public Plugin:myinfo =
{
name = "Round Timer Redux",
author = "ReFlexPoison, updated by Frenzoid",
description = "Creates a round timer that executes commands on end.",
version = PLUGIN_VERSION,
url = "http://www.sourcemod.net",
}
// ====[ FUNCTIONS ]===========================================================
public OnPluginStart()
{
CreateConVar("sm_roundtimer_version", PLUGIN_VERSION, "Round Timer Version", FCVAR_PLUGIN | FCVAR_SPONLY | FCVAR_DONTRECORD | FCVAR_NOTIFY);
g_hCvarEnabled = CreateConVar("sm_roundtimer_enabled", "1", "Enable Round Timer\n0 = Disabled\n1 = Enabled", _, true, 0.0, true, 1.0);
g_bEnabled = GetConVarBool(g_hCvarEnabled);
HookConVarChange(g_hCvarEnabled, OnConVarChange);
g_hCvarTime = CreateConVar("sm_roundtimer_time", "600", "Round timer time", _, true, 30.0);
g_iTime = GetConVarInt(g_hCvarTime);
HookConVarChange(g_hCvarTime, OnConVarChange);
g_hCvarHud = CreateConVar("sm_roundtimer_hud", "1", "Enable displaying timer in hud\n0 = Disabled\n1 = Enabled", _, true, 0.0, true, 1.0);
g_bHud = GetConVarBool(g_hCvarHud);
HookConVarChange(g_hCvarHud, OnConVarChange);
g_hCvarCenter = CreateConVar("sm_roundtimer_center", "0", "Enable displaying timer in center text\n0 = Disabled\n1 = Enabled", _, true, 0.0, true, 1.0);
g_bCenter = GetConVarBool(g_hCvarCenter);
HookConVarChange(g_hCvarCenter, OnConVarChange);
g_hCvarHudX = CreateConVar("sm_roundtimer_xhud", "-1", "X hud position\n-1 = Center", _, true, -1.0, true, 1.0);
g_iHudX = GetConVarFloat(g_hCvarHudX);
HookConVarChange(g_hCvarHudX, OnConVarChange);
g_hCvarHudY = CreateConVar("sm_roundtimer_yhud", "0.15", "Y hud position\n-1 = Center", _, true, -1.0, true, 1.0);
g_iHudY = GetConVarFloat(g_hCvarHudY);
HookConVarChange(g_hCvarHudY, OnConVarChange);
g_hCvarCommands = CreateConVar("sm_roundtimer_commands", "sm_say The round time has ended!;sm_slay @red", "Commands to run once the timer ends");
GetConVarString(g_hCvarCommands, g_strCommands, sizeof(g_strCommands));
HookConVarChange(g_hCvarCommands, OnConVarChange);
HookEvent("round_start", OnRoundStart);
HookEventEx("teamplay_round_start", OnRoundStart);
HookEventEx("arena_round_start", OnArenaStart);
HookEvent("round_end", OnRoundEnd);
HookEventEx("teamplay_round_win", OnRoundEnd);
g_hHud = CreateHudSynchronizer();
}
public OnConVarChange(Handle:hConvar, const String:strOldValue[], const String:strNewValue[])
{
if(hConvar == g_hCvarEnabled)
{
g_bEnabled = GetConVarBool(g_hCvarEnabled);
if(!g_bEnabled)
delete g_hTimer;
}
if(hConvar == g_hCvarTime)
{
g_iTime = GetConVarInt(g_hCvarTime);
if(g_hTimer != INVALID_HANDLE && g_iTime > 0)
g_iRemaining = g_iTime;
}
if(hConvar == g_hCvarCommands)
GetConVarString(g_hCvarCommands, g_strCommands, sizeof(g_strCommands));
if(hConvar == g_hCvarHud)
g_bHud = GetConVarBool(g_hCvarHud);
if(hConvar == g_hCvarCenter)
g_bCenter = GetConVarBool(g_hCvarCenter);
if(hConvar == g_hCvarHudX)
g_iHudX = GetConVarFloat(hConvar);
if(hConvar == g_hCvarHudY)
g_iHudY = GetConVarFloat(hConvar);
}
public OnMapStart()
{
delete g_hTimer;
g_bArena = false;
if(FindEntityByClassname(-1, "tf_logic_arena") != -1)
g_bArena = true;
}
public Action:OnRoundStart(Handle:hEvent, const String:strName[], bool:bDontBroadcast)
{
if(!g_bEnabled || g_bArena)
return Plugin_Continue;
delete g_hTimer;
if(g_iTime > 0)
{
g_iRemaining = g_iTime;
g_hTimer = CreateTimer(1.0, Timer_Round, _, TIMER_REPEAT);
}
return Plugin_Continue;
}
public Action:OnArenaStart(Handle:hEvent, const String:strName[], bool:bDontBroadcast)
{
if(!g_bEnabled || !g_bArena)
return Plugin_Continue;
delete g_hTimer;
if(g_iTime > 0)
{
g_iRemaining = g_iTime;
g_hTimer = CreateTimer(1.0, Timer_Round, _, TIMER_REPEAT);
}
return Plugin_Continue;
}
public Action:OnRoundEnd(Handle:hEvent, const String:strName[], bool:bDontBroadcast)
{
delete g_hTimer;
}
// ====[ TIMERS ]==============================================================
public Action:Timer_Round(Handle:hTimer)
{
g_iRemaining--;
if(g_bHud && g_hHud != INVALID_HANDLE)
{
SetHudTextParams(g_iHudX, g_iHudY, 1.1, 255, 255, 255, 255);
for(new i = 1; i <= MaxClients; i++) if(IsValidClient(i))
{
if(!IsFakeClient(i))
ShowSyncHudText(i, g_hHud, "%02d:%02d", g_iRemaining / 60, g_iRemaining % 60);
}
}
if(g_bCenter)
PrintCenterTextAll("%02d:%02d", g_iRemaining / 60, g_iRemaining % 60);
if(g_iRemaining <= 0)
{
ServerCommand("%s", g_strCommands);
delete g_hTimer;
}
return Plugin_Continue;
}
// ====[ STOCKS ]==============================================================
stock IsValidClient(iClient, bool:bReplay = true)
{
if(iClient <= 0 || iClient > MaxClients || !IsClientInGame(iClient))
return false;
if(bReplay && (IsClientSourceTV(iClient) || IsClientReplay(iClient)))
return false;
return true;
}