-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFreezeTag.sp
260 lines (223 loc) · 5.84 KB
/
FreezeTag.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
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
258
259
260
#include <sourcemod>
#include <sdktools>
#include <colors_codes>
#define IN_USE (1 << 5)
#define MAX_BUTTONS 25
new g_LastButtons[MAXPLAYERS+1];
bool isFrozen[MAXPLAYERS + 1];
int cts;
int ts;
int ctLeft;
int tLeft;
int counter;
Handle CVAR_Dist;
Handle timer1;
public Plugin myinfo =
{
name = "FreezeTag",
author = "AfricanSpaceJesus",
description = "FreezeTag gamemode",
version = "0.5",
url = "https://forums.alliedmods.net/member.php?u=275905"
};
public void OnPluginStart()
{
AddCommandListener(checkFreeze, "+attack");
AddCommandListener(checkFreeze, "+attack2");
AddCommandListener(attemptUnFreeze, "+use");
HookEvent("player_death", setFreeze, EventHookMode_Pre);
HookEvent("player_team", changeTeamInt, EventHookMode_Post);
CVAR_Dist = CreateConVar("sm_afr_distance", "10", "Minimum distance needed to unfreeze teammate");
}
public void OnClientDisconnect(int client)
{
isFrozen[client] = false;
}
public OnClientDisconnect_Post(client)
{
g_LastButtons[client] = 0;
}
//Command Listeners
public Action checkFreeze(int client, const char[] command, int argc)
{
if(isFrozen[client]==true)
return Plugin_Handled;
return Plugin_Continue;
}
public Action attemptUnFreeze(int client, const char[] command, int argc)
{
int r=closestFrozenTeam(client);
if(r==-1)
return;
timer1 = CreateTimer(5.0, unFreeze, r);
}
//Hook Events
public Action setFreeze(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientUserId(GetEventInt(event, "userid"));
isFrozen[client] = true;
char nameClient [64];
GetClientName(client, nameClient, sizeof(nameClient));
SetEntityHealth(client, 100);
SetEntityMoveType(client, MOVETYPE_NONE);
SetEntityRenderColor(client, 0, 0, 255, 255);
if(GetClientTeam(client)==3)
{
ctLeft--;
CPrintToChatAll("{blue} %s has been frozen. %i ct's remain of %i total", nameClient, ctLeft, cts);
}
else if (GetClientTeam(client)==2)
{
tLeft--;
CPrintToChatAll("{red} %s has been frozen. %i t's remain of %i total", nameClient, tLeft, ts);
}
return Plugin_Handled;
}
public Action changeTeamInt(Event event, const char[] name, bool dontBroadcast)
{
//switch from t to ct and not a disconnect
if (GetEventInt(event, "team")==3 && GetEventBool(event, "disconnect")==false && GetEventInt(event, "oldteam")==2)
{
ts--;
tLeft--;
cts++;
ctLeft++;
}
//switch from ct to t and not a disconnect
else if (GetEventInt(event, "team")==2 && GetEventBool(event, "disconnect")==false && GetEventInt(event, "oldteam")==3)
{
cts--;
ctLeft--;
ts++;
tLeft++;
}
//switches from spectate to ct and not a disconnect
else if (GetEventInt(event, "team")==3 && GetEventBool(event, "disconnect")==false && GetEventInt(event, "oldteam")==1)
{
cts++;
ctLeft++;
}
//switch from spectate to t and not a disconnect
else if (GetEventInt(event, "team")==2 && GetEventBool(event, "disconnect")==false && GetEventInt(event, "oldteam")==1)
{
ts++;
tLeft++;
}
//player disconnect, was t
else if (GetEventInt(event, "oldteam")==2 && GetEventBool(event, "disconnect"))
{
ts--;
tLeft--;
}
//player disconnect, was ct
else if (GetEventInt(event, "oldteam")==3 && GetEventBool(event, "disconnect"))
{
cts--;
ctLeft--;
}
}
//Timer Callbacks
public Action unFreeze(Handle timer, int r)
{
SetEntityMoveType(r, MOVETYPE_ISOMETRIC);
//Set to old color? SetEntityRenderColor(
}
public Action addTime(Handle timer, int counter)
{
counter++;
}
//Useful Functions
public int closestFrozenTeam(int client)
{
float cli [3];
float targ [3];
float dist;
int teamMate;
GetClientAbsOrigin(client, cli);
for (int i = 1; i < MaxClients && i != client; i++)
{
GetClientAbsOrigin(i, targ);
dist = GetVectorDistance(cli, targ);
if(dist<=GetConVarInt(CVAR_Dist) && GetClientTeam(client)== GetClientTeam(i) && isFrozen[i] && !isFrozen[client])
teamMate = i;
}
if(teamMate==0)
return -1;
return teamMate;
}
public Action OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon)
{
for (new i = 0; i < MAX_BUTTONS; i++)
{
new button = (1 << i);
if ((buttons & button))
{
if (!(g_LastButtons[client] & button))
{
OnButtonPress(client, button);
}
}
else if ((g_LastButtons[client] & button))
{
OnButtonRelease(client, button);
}
}
g_LastButtons[client] = buttons;
return Plugin_Continue;
}
OnButtonPress(int client, IN_USE)
{
int r=closestFrozenTeam(client);
if(r==-1)
return;
while(counter !=5)
timer1 = CreateTimer(1.0, addTime, counter);
if(counter==5)
{
SetEntityMoveType(r, MOVETYPE_ISOMETRIC);
SetEntityRenderColor(r, 0, 0, 0, 0);
isFrozen[r] = false;
if(GetClientTeam(r)==2)
{
char nameClient [64];
GetClientName(client, nameClient, sizeof(nameClient));
tLeft++;
CPrintToChatAll("{red} %s has been unfrozen. %i t's remain of %i total", nameClient, tLeft, ts);
}
if(GetClientTeam(r)==3)
{
char nameClient [64];
GetClientName(client, nameClient, sizeof(nameClient));
ctLeft++;
CPrintToChatAll("{blue} %s has been unfrozen. %i ct's remain of %i total", nameClient, ctLeft, cts);
}
}
}
OnButtonRelease(int client, IN_USE)
{
int r=closestFrozenTeam(client);
if(r==-1)
return;
if(counter!=5)
counter = 0;
else if(counter==5)
{
SetEntityMoveType(r, MOVETYPE_ISOMETRIC);
SetEntityRenderColor(r, 0, 0, 0, 0);
isFrozen[r] = false;
if(GetClientTeam(r)==2)
{
char nameClient [64];
GetClientName(client, nameClient, sizeof(nameClient));
tLeft++;
CPrintToChatAll("{red} %s has been unfrozen. %i t's remain of %i total", nameClient, tLeft, ts);
}
if(GetClientTeam(r)==3)
{
char nameClient [64];
GetClientName(client, nameClient, sizeof(nameClient));
ctLeft++;
CPrintToChatAll("{blue} %s has been unfrozen. %i ct's remain of %i total", nameClient, ctLeft, cts);
}
}
}