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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
|
static bool paused[MAXPLAYERS + 1];
static bool pausedOnLadder[MAXPLAYERS + 1];
static float lastPauseTime[MAXPLAYERS + 1];
static bool hasPausedInThisRun[MAXPLAYERS + 1];
static float lastResumeTime[MAXPLAYERS + 1];
static bool hasResumedInThisRun[MAXPLAYERS + 1];
static float lastDuckValue[MAXPLAYERS + 1];
static float lastStaminaValue[MAXPLAYERS + 1];
// =====[ PUBLIC ]=====
bool GetPaused(int client)
{
return paused[client];
}
void SetPausedOnLadder(int client, bool onLadder)
{
pausedOnLadder[client] = onLadder;
}
void Pause(int client)
{
if (!CanPause(client, true))
{
return;
}
// Call Pre Forward
Action result;
Call_GOKZ_OnPause(client, result);
if (result != Plugin_Continue)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Pause (Generic)");
GOKZ_PlayErrorSound(client);
return;
}
// Pause
paused[client] = true;
pausedOnLadder[client] = Movement_GetMovetype(client) == MOVETYPE_LADDER;
lastDuckValue[client] = Movement_GetDuckSpeed(client);
lastStaminaValue[client] = GetEntPropFloat(client, Prop_Send, "m_flStamina");
Movement_SetVelocity(client, view_as<float>( { 0.0, 0.0, 0.0 } ));
Movement_SetMovetype(client, MOVETYPE_NONE);
if (GetTimerRunning(client))
{
hasPausedInThisRun[client] = true;
lastPauseTime[client] = GetEngineTime();
}
// Call Post Forward
Call_GOKZ_OnPause_Post(client);
}
bool CanPause(int client, bool showError = false)
{
if (paused[client])
{
return false;
}
if (GetTimerRunning(client))
{
if (hasResumedInThisRun[client]
&& GetEngineTime() - lastResumeTime[client] < GOKZ_PAUSE_COOLDOWN)
{
if (showError)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Pause (Just Resumed)");
GOKZ_PlayErrorSound(client);
}
return false;
}
else if (!Movement_GetOnGround(client)
&& !(Movement_GetSpeed(client) == 0 && Movement_GetVerticalVelocity(client) == 0))
{
if (showError)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Pause (Midair)");
GOKZ_PlayErrorSound(client);
}
return false;
}
else if (BhopTriggersJustTouched(client))
{
if (showError)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Pause (Just Landed)");
GOKZ_PlayErrorSound(client);
}
return false;
}
else if (AntiPauseTriggerIsTouched(client))
{
if (showError)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Pause (Anti Pause Area)");
GOKZ_PlayErrorSound(client);
}
return false;
}
}
return true;
}
void Resume(int client, bool force = false)
{
if (!paused[client])
{
return;
}
if (!force && !CanResume(client, true))
{
return;
}
// Call Pre Forward
Action result;
Call_GOKZ_OnResume(client, result);
if (result != Plugin_Continue)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Resume (Generic)");
GOKZ_PlayErrorSound(client);
return;
}
// Resume
if (pausedOnLadder[client])
{
Movement_SetMovetype(client, MOVETYPE_LADDER);
}
else
{
Movement_SetMovetype(client, MOVETYPE_WALK);
}
// Prevent noclip exploit
SetEntProp(client, Prop_Send, "m_CollisionGroup", GOKZ_COLLISION_GROUP_STANDARD);
paused[client] = false;
if (GetTimerRunning(client))
{
hasResumedInThisRun[client] = true;
lastResumeTime[client] = GetEngineTime();
}
Movement_SetDuckSpeed(client, lastDuckValue[client]);
SetEntPropFloat(client, Prop_Send, "m_flStamina", lastStaminaValue[client]);
// Call Post Forward
Call_GOKZ_OnResume_Post(client);
}
bool CanResume(int client, bool showError = false)
{
if (GetTimerRunning(client) && hasPausedInThisRun[client]
&& GetEngineTime() - lastPauseTime[client] < GOKZ_PAUSE_COOLDOWN)
{
if (showError)
{
GOKZ_PrintToChat(client, true, "%t", "Can't Resume (Just Paused)");
GOKZ_PlayErrorSound(client);
}
return false;
}
return true;
}
void TogglePause(int client)
{
if (paused[client])
{
Resume(client);
}
else
{
Pause(client);
}
}
// =====[ EVENTS ]=====
void OnClientPutInServer_Pause(int client)
{
paused[client] = false;
}
void OnTimerStart_Pause(int client)
{
hasPausedInThisRun[client] = false;
hasResumedInThisRun[client] = false;
Resume(client, true);
}
void OnChangeMovetype_Pause(int client, MoveType newMovetype)
{
// Check if player has escaped MOVETYPE_NONE
if (!paused[client] || newMovetype == MOVETYPE_NONE)
{
return;
}
// Player has escaped MOVETYPE_NONE, so resume
paused[client] = false;
if (GetTimerRunning(client))
{
hasResumedInThisRun[client] = true;
lastResumeTime[client] = GetEngineTime();
}
// Call Post Forward
Call_GOKZ_OnResume_Post(client);
}
void OnPlayerSpawn_Pause(int client)
{
if (!paused[client])
{
return;
}
// Player has left paused state by spawning in, so resume
paused[client] = false;
if (GetTimerRunning(client))
{
hasResumedInThisRun[client] = true;
lastResumeTime[client] = GetEngineTime();
}
Movement_SetDuckSpeed(client, lastDuckValue[client]);
SetEntPropFloat(client, Prop_Send, "m_flStamina", lastStaminaValue[client]);
// Call Post Forward
Call_GOKZ_OnResume_Post(client);
}
void OnJoinTeam_Pause(int client, int team)
{
// Only handle joining spectators. Joining other teams is handled by OnPlayerSpawn.
if (team == CS_TEAM_SPECTATOR)
{
paused[client] = true;
if (GetTimerRunning(client))
{
hasPausedInThisRun[client] = true;
lastPauseTime[client] = GetEngineTime();
}
// Call Post Forward
Call_GOKZ_OnPause_Post(client);
}
}
|