-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectate.qc
302 lines (258 loc) · 9.01 KB
/
spectate.qc
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
spectate.qc
spectator functions
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to:
Free Software Foundation, Inc.
59 Temple Place - Suite 330
Boston, MA 02111-1307, USA
*/
/*
===========
SpectatorConnect
called when a spectator connects to the server
============
*/
void() SpectatorConnect =
{
bprint("Spectator ");
bprint(self.netname);
bprint(" entered the server\n");
self.goalentity = world;
};
/*
===========
SpectatorDisconnect
called when a spectator disconnects from the server
============
*/
void() SpectatorDisconnect =
{
self.goalentity = world; // used for player entity tracking
self.spectator = self.spectator - (self.spectator & (SPEC_FREEMOVE|SPEC_EYECAM));
self.flags = (self.flags - (self.flags & FL_NOTARGET));
};
//Use this when going out of spec mode and joining the game
void() SpectatorEnd =
{
self.goalentity = world;
self.spectator = self.spectator - (self.spectator & (SPEC_FREEMOVE|SPEC_EYECAM));
self.flags = (self.flags - (self.flags & FL_NOTARGET));//coop
//reset the viewport
msg_entity = self;
WriteByte(MSG_ONE, SVC_SETVIEWPORT);
WriteEntity(MSG_ONE, self);
PutClientInServer ();
};
void() SpectatorImpulseCommand =
{
switch (self.impulse)
{
case IMPULSE_SPECTATOREND:
SpectatorEnd();
break;
}
self.impulse = 0;//this must always be here!
};
void() SpectatorFreeMoveSetup =
{
//reset the viewport
msg_entity = self;
WriteByte(MSG_ONE, SVC_SETVIEWPORT);
WriteEntity(MSG_ONE, self);
//reset the hud
self.health = 1000;
self.items = self.items - (self.items & (IT_AXE | IT_SHOTGUN | IT_SUPER_SHOTGUN | IT_NAILGUN | IT_SUPER_NAILGUN | IT_GRENADE_LAUNCHER | IT_ROCKET_LAUNCHER | IT_LIGHTNING | IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3));
self.armorvalue = 0;
self.ammo_shells = 0;
self.ammo_nails = 0;
self.ammo_rockets = 0;
self.ammo_cells = 0;
self.currentammo = 0;
self.movetype = MOVETYPE_NOCLIP;
self.weaponmodel = string_null;
self.spectator = self.spectator - (self.spectator & SPEC_EYECAM);
self.spectator = (self.spectator | SPEC_FREEMOVE);
sprint(self,"Freecam mode.\n");
//should we reset self.goalentity to world??
};
entity(entity p) SpectatorFindPlayer =
{
local entity newguy;
if ((p.classname != "player") || (p.classname == "spectator")) //they disconnected or went into spectator mode.
{
p = world;
}
newguy = find(p, classname, "player"); //start looking from p (goalentity) for the next player.
//Find an entity, starting at our current position on the link list; loops back around to world(0) then stops.
while (((newguy == p) && (newguy != world)) || (p.classname == "spectator"))
newguy = find(newguy, classname, "player");
return newguy;
};
void() SpectatorUpdateEyeCam =
{
msg_entity = self;
WriteByte(MSG_ONE, SVC_SETVIEWPORT);
WriteEntity(MSG_ONE, self.goalentity);
self.weaponmodel = self.goalentity.weaponmodel;
self.weaponframe = self.goalentity.weaponframe;
//R00k: Let's update the HUD
self.health = self.goalentity.health;
self.items = self.goalentity.items;
self.armorvalue = self.goalentity.armorvalue;
self.ammo_shells = self.goalentity.ammo_shells;
self.ammo_nails = self.goalentity.ammo_nails;
self.ammo_rockets = self.goalentity.ammo_rockets;
self.ammo_cells = self.goalentity.ammo_cells;
self.currentammo = self.goalentity.currentammo;
setorigin(self, self.goalentity.origin);
self.view_ofs = self.goalentity.view_ofs;
self.v_angle = self.angles = self.goalentity.v_angle;
self.fixangle = TRUE;
};
void() SpectatorEyeCamSetup =
{
if ((self.goalentity == world) || (self.goalentity.classname == "spectator"))
{
self.goalentity = SpectatorFindPlayer(self.goalentity);
if (self.goalentity == world)
{
SpectatorFreeMoveSetup();
return;
}
}
sprint(self, "Eyecam mode.\n");
self.view_ofs = '0 0 22';
setmodel(self, "progs/eyes.mdl");//todo create a null sprite and use that instead
setsize(self, VEC_HULL_MIN, VEC_HULL_MAX);
//self.alpha = 1;
self.model = string_null;
self.mdl = string_null;
self.movetype = MOVETYPE_FLY;
self.spectator = self.spectator - (self.spectator & SPEC_FREEMOVE);
self.spectator = (self.spectator | SPEC_EYECAM);
centerprint(self, self.goalentity.netname);
};
/*
================
SpectatorThink
Called every frame after physics are run
================
*/
void() SpectatorThink =
{
if (self.spectator & SPEC_EYECAM)
{
if (self.button2) //Use JUMP to switch between players
{
if (self.flags & FL_JUMPRELEASED)
{
self.flags = self.flags - (self.flags & FL_JUMPRELEASED);
self.goalentity = SpectatorFindPlayer(self.goalentity);
if (self.goalentity != world)
centerprint(self, self.goalentity.netname);
if (self.goalentity == world)
{
self.flags = (self.flags | FL_JUMPRELEASED);
return;
}
}
}
else
{
self.flags = (self.flags | FL_JUMPRELEASED);
}
if (self.goalentity != world)
{
SpectatorUpdateEyeCam();
}
}
//Use the fire button to switch between freemove and eyecam
if ((self.button0) && (time > self.attack_finished))
{
if (self.spectator & SPEC_FREEMOVE)
{
SpectatorEyeCamSetup();
}
else
{
SpectatorFreeMoveSetup();
}
self.button0 = FALSE;
self.attack_finished = time + 0.8;
}
//TODO add a condition for intermission
}
/*
ItsLonelyOutHere
Check if all CoOp players are dead; if so then restart the map.
*/
void(void) ItsLonelyOutHere =
{
local entity anyonehome;
anyonehome = find(world, classname, "player"); // start at world and go thru all entities to find the 1st player
while (anyonehome != world) // if we found a player then...
{
if ((anyonehome.classname != "spectator") && (anyonehome.health > 0)) // check to see if they are not a spectator, and alive
return; // if they are then go back to StartFrame and update the last_client_check
else // otherwise
anyonehome = find(anyonehome, classname, "player"); // look for any more players, then go back thru the loop ^^^
}
// if we didnt find any more players, anyonehome looped back to world..
bprint("\nRestarting Map...Please Wait.\n");//R00k // Notify all players...
changelevel(mapname); // Restart the current map; but keep our weapons/stats
};
/*
===========
SpectatorStart
Initializes the player spectator mode.
===========
*/
void () SpectatorStart =
{
self.spectator = (self.spectator | SPEC_FREEMOVE); // Default
self.goalentity = world; // used for player entity tracking
self.takedamage = DAMAGE_NO; // cannot be hurt
self.classname = "spectator";
self.solid = SOLID_NOT; // no collision with the map and objects
self.effects = 0; // no glowing from powerups etc.
self.flags = (self.flags | FL_NOTARGET); // in coop we dont want monsters attacking spectators.
self.flags = self.flags - (self.flags & FL_ONGROUND); // no bobbing.
self.movetype = MOVETYPE_NOCLIP;
self.view_ofs = '0 0 22'; // position our pov at eye-level.
self.health = 1000; //the hud only has 3 digits for health so, specators will see 000 by default.
self.items = self.items - (self.items & (IT_AXE | IT_SHOTGUN | IT_SUPER_SHOTGUN | IT_NAILGUN | IT_SUPER_NAILGUN | IT_GRENADE_LAUNCHER | IT_ROCKET_LAUNCHER | IT_LIGHTNING | IT_ARMOR1 | IT_ARMOR2 | IT_ARMOR3));
self.armorvalue = 0;
self.ammo_shells = 0;
self.ammo_nails = 0;
self.ammo_rockets = 0;
self.ammo_cells = 0;
self.currentammo = 0;
self.show_hostile = 0;
self.waterlevel = 0;
//The server needs to assign our entity a model or else we won't be updated on the server-side.
setmodel(self, "progs/spike.mdl");//testing: giving the specator a valid model to make sure the server doesnt skip us on updated packets...
setsize (self, VEC_HULL_MIN, VEC_HULL_MAX);
//But, send the other clients a null model so they can't see us.
self.model = "progs/spike.mdl";
self.mdl = "progs/spike.mdl";
//self.alpha = 1;//just barely visible
self.nextthink = -1;
self.think = SUB_Null;
//self.modelindex = self.modelindex;
self.weaponmodel = string_null;
self.weapon = 0;
self.flags = self.flags - (self.flags & FL_INWATER);
self.wait = time + 1;
self.delay = 0;
if (coop)
ItsLonelyOutHere();//check if we need to restart the map
};