]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamecommand.qc
sv_cmd defer_clear <id> and sv_cmd defer_clear_all
[divverent/nexuiz.git] / data / qcsrc / server / gamecommand.qc
1 string GotoMap(string m);
2
3 float FullTraceFraction(vector a, vector mi, vector ma, vector b)
4 {
5         vector c;
6         float white, black;
7
8         white = 0.001;
9         black = 0.001;
10
11         c = a;
12
13         float n, m;
14         n = m = 0;
15
16         while(vlen(c - b) > 1)
17         {
18                 ++m;
19
20                 tracebox(c, mi, ma, b, MOVE_WORLDONLY, world);
21                 ++n;
22
23                 if(!trace_startsolid)
24                 {
25                         black += vlen(trace_endpos - c);
26                         c = trace_endpos;
27                 }
28
29                 n += tracebox_inverted(c, mi, ma, b, MOVE_WORLDONLY, world);
30
31                 white += vlen(trace_endpos - c);
32                 c = trace_endpos;
33         }
34
35         if(n > 200)
36                 dprint("HOLY SHIT! FullTraceFraction: ", ftos(n), " total traces, ", ftos(m), " iterations\n");
37
38         return white / (black + white);
39 }
40
41 float RadarMapAtPoint_Trace(float x, float y, float w, float h, float zmin, float zsize, float q)
42 {
43         vector a, b, mi, ma;
44
45         mi = '0 0 0';
46         ma = '1 0 0' * w + '0 1 0' * h;
47         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
48         b = '1 0 0' * x + '0 1 0' * y + '0 0 1' * (zsize + zmin);
49
50         return FullTraceFraction(a, mi, ma, b);
51 }
52 float RadarMapAtPoint_LineBlock(float x, float y, float w, float h, float zmin, float zsize, float q)
53 {
54         vector o, mi, ma;
55         float i, r;
56         vector dz;
57
58         q = 256 * q - 1;
59         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
60
61         mi = '0 0 0';
62         dz = (zsize / q) * '0 0 1';
63         ma = '1 0 0' * w + '0 1 0' * h + dz;
64         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
65
66         if(x < world.absmin_x - w)
67                 return 0;
68         if(y < world.absmin_y - h)
69                 return 0;
70         if(x > world.absmax_x)
71                 return 0;
72         if(y > world.absmax_y)
73                 return 0;
74
75         r = 0;
76         for(i = 0; i < q; ++i)
77         {
78                 vector v1, v2;
79                 v1 = v2 = o + dz * i + mi;
80                 v1_x += random() * (ma_x - mi_x);
81                 v1_y += random() * (ma_y - mi_y);
82                 v1_z += random() * (ma_z - mi_z);
83                 v2_x += random() * (ma_x - mi_x);
84                 v2_y += random() * (ma_y - mi_y);
85                 v2_z += random() * (ma_z - mi_z);
86                 traceline(v1, v2, MOVE_WORLDONLY, world);
87                 if(trace_startsolid || trace_fraction < 1)
88                         ++r;
89         }
90         return r / q;
91 }
92 float RadarMapAtPoint_Block(float x, float y, float w, float h, float zmin, float zsize, float q)
93 {
94         vector o, mi, ma;
95         float i, r;
96         vector dz;
97
98         q = 256 * q - 1;
99         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
100
101         mi = '0 0 0';
102         dz = (zsize / q) * '0 0 1';
103         ma = '1 0 0' * w + '0 1 0' * h + dz;
104         o = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
105
106         if(x < world.absmin_x - w)
107                 return 0;
108         if(y < world.absmin_y - h)
109                 return 0;
110         if(x > world.absmax_x)
111                 return 0;
112         if(y > world.absmax_y)
113                 return 0;
114
115         r = 0;
116         for(i = 0; i < q; ++i)
117         {
118                 tracebox(o + dz * i, mi, ma, o + dz * i, MOVE_WORLDONLY, world);
119                 if(trace_startsolid)
120                         ++r;
121         }
122         return r / q;
123 }
124 float RadarMapAtPoint_Sample(float x, float y, float w, float h, float zmin, float zsize, float q)
125 {
126         vector a, b, mi, ma;
127
128         q *= 4; // choose q so it matches the regular algorithm in speed
129
130         q = 256 * q - 1;
131         // 256q-1 is the ideal sample count to map equal amount of sample values to one pixel value
132
133         mi = '0 0 0';
134         ma = '1 0 0' * w + '0 1 0' * h;
135         a = '1 0 0' * x + '0 1 0' * y + '0 0 1' * zmin;
136         b = '1 0 0' * w + '0 1 0' * h + '0 0 1' * zsize;
137
138         float c, i;
139         c = 0;
140
141         for(i = 0; i < q; ++i)
142         {
143                 vector v;
144                 v_x = a_x + random() * b_x;
145                 v_y = a_y + random() * b_y;
146                 v_z = a_z + random() * b_z;
147                 traceline(v, v, MOVE_WORLDONLY, world);
148                 if(trace_startsolid)
149                         ++c;
150         }
151
152         return c / q;
153 }
154
155 // FF is contained twice, to map 256 to FF too
156 // removes the need to bound()
157 string doublehex = "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F202122232425262728292A2B2C2D2E2F303132333435363738393A3B3C3D3E3F404142434445464748494A4B4C4D4E4F505152535455565758595A5B5C5D5E5F606162636465666768696A6B6C6D6E6F707172737475767778797A7B7C7D7E7F808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8D9DADBDCDDDEDFE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFFFF";
158
159 float RADAR_WIDTH_MAX = 2048;
160 float RADAR_HEIGHT_MAX = 2048;
161 float sharpen_buffer[RADAR_WIDTH_MAX * 3];
162
163 void sharpen_set(float x, float v)
164 {
165         sharpen_buffer[x + 2 * RADAR_WIDTH_MAX] = v;
166 }
167
168 float sharpen_getpixel(float x, float y)
169 {
170         if(x < 0)
171                 return 0;
172         if(x >= RADAR_WIDTH_MAX)
173                 return 0;
174         if(y < 0)
175                 return 0;
176         if(y > 2)
177                 return 0;
178         return sharpen_buffer[x + y * RADAR_WIDTH_MAX];
179 }
180
181 float sharpen_get(float x, float a)
182 {
183         float sum;
184         sum = sharpen_getpixel(x, 1);
185         if(a == 0)
186                 return sum;
187         sum *= (8 + 1/a);
188         sum -= sharpen_getpixel(x - 1, 0);
189         sum -= sharpen_getpixel(x - 1, 1);
190         sum -= sharpen_getpixel(x - 1, 2);
191         sum -= sharpen_getpixel(x + 1, 0);
192         sum -= sharpen_getpixel(x + 1, 1);
193         sum -= sharpen_getpixel(x + 1, 2);
194         sum -= sharpen_getpixel(x, 0);
195         sum -= sharpen_getpixel(x, 2);
196         return bound(0, sum * a, 1);
197 }
198
199 void sharpen_shift(float w)
200 {
201         float i;
202         for(i = 0; i < w; ++i)
203         {
204                 sharpen_buffer[i] = sharpen_buffer[i + RADAR_WIDTH_MAX];
205                 sharpen_buffer[i + RADAR_WIDTH_MAX] = sharpen_buffer[i + 2 * RADAR_WIDTH_MAX];
206                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
207         }
208 }
209
210 void sharpen_init(float w)
211 {
212         float i;
213         for(i = 0; i < w; ++i)
214         {
215                 sharpen_buffer[i] = 0;
216                 sharpen_buffer[i + RADAR_WIDTH_MAX] = 0;
217                 sharpen_buffer[i + 2 * RADAR_WIDTH_MAX] = 0;
218         }
219 }
220
221 entity radarmapper;
222 void RadarMap_Next()
223 {
224         if(radarmapper.count & 4)
225         {
226                 localcmd("quit\n");
227         }
228         else if(radarmapper.count & 2)
229         {
230                 localcmd(strcat("defer 1 \"sv_cmd radarmap --flags ", ftos(radarmapper.count), strcat(" --res ", ftos(radarmapper.size_x), " ", ftos(radarmapper.size_y), " --sharpen ", ftos(radarmapper.ltime), " --qual ", ftos(radarmapper.size_z)), "\"\n"));
231                 GotoNextMap();
232         }
233         remove(radarmapper);
234         radarmapper = world;
235 }
236
237 // rough map entity
238 //   cnt: current line
239 //   size: pixel width/height
240 //   maxs: cell width/height
241 //   frame: counter
242 void RadarMap_Think()
243 {
244         float i, x, l;
245         string si;
246
247         if(self.frame == 0)
248         {
249                 // initialize
250                 get_mi_min_max_texcoords(1);
251                 self.mins = mi_picmin;
252                 self.maxs_x = (mi_picmax_x - mi_picmin_x) / self.size_x;
253                 self.maxs_y = (mi_picmax_y - mi_picmin_y) / self.size_y;
254                 self.maxs_z = mi_max_z - mi_min_z;
255                 print("Picture mins/maxs: ", ftos(self.maxs_x), " and ", ftos(self.maxs_y), " should match\n");
256                 self.netname = strzone(strcat("gfx/", mi_shortname, "_radar.xpm"));
257                 if(!(self.count & 1))
258                 {
259                         self.cnt = fopen(self.netname, FILE_READ);
260                         if(self.cnt < 0)
261                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.tga"), FILE_READ);
262                         if(self.cnt < 0)
263                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.png"), FILE_READ);
264                         if(self.cnt < 0)
265                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_radar.jpg"), FILE_READ);
266                         if(self.cnt < 0)
267                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.tga"), FILE_READ);
268                         if(self.cnt < 0)
269                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.png"), FILE_READ);
270                         if(self.cnt < 0)
271                                 self.cnt = fopen(strcat("gfx/", mi_shortname, "_mini.jpg"), FILE_READ);
272                         if(self.cnt >= 0)
273                         {
274                                 fclose(self.cnt);
275
276                                 print(self.netname, " already exists, aborting (you may want to specify --force)\n");
277                                 RadarMap_Next();
278                                 return;
279                         }
280                 }
281                 self.cnt = fopen(self.netname, FILE_WRITE);
282                 if(self.cnt < 0)
283                 {
284                         print("Error writing ", self.netname, "\n");
285                         remove(self);
286                         radarmapper = world;
287                         return;
288                 }
289                 print("Writing to ", self.netname, "...\n");
290                 fputs(self.cnt, "/* XPM */\n");
291                 fputs(self.cnt, "static char *RadarMap[] = {\n");
292                 fputs(self.cnt, "/* columns rows colors chars-per-pixel */\n");
293                 fputs(self.cnt, strcat("\"", ftos(self.size_x), " ", ftos(self.size_y), " 256 2\",\n"));
294                 for(i = 0; i < 256; ++i)
295                 {
296                         si = substring(doublehex, i*2, 2);
297                         fputs(self.cnt, strcat("\"", si, " c #", si, si, si, "\",\n"));
298                 }
299                 self.frame += 1;
300                 self.nextthink = time;
301                 sharpen_init(self.size_x);
302         }
303         else if(self.frame <= self.size_y)
304         {
305                 // fill the sharpen buffer with this line
306                 sharpen_shift(self.size_x);
307                 i = self.count & 24;
308
309                 switch(i)
310                 {
311                         case 0:
312                         default:
313                                 for(x = 0; x < self.size_x; ++x)
314                                 {
315                                         l = RadarMapAtPoint_Block(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
316                                         sharpen_set(x, l);
317                                 }
318                                 break;
319                         case 8:
320                                 for(x = 0; x < self.size_x; ++x)
321                                 {
322                                         l = RadarMapAtPoint_Trace(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
323                                         sharpen_set(x, l);
324                                 }
325                                 break;
326                         case 16:
327                                 for(x = 0; x < self.size_x; ++x)
328                                 {
329                                         l = RadarMapAtPoint_Sample(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
330                                         sharpen_set(x, l);
331                                 }
332                                 break;
333                         case 24:
334                                 for(x = 0; x < self.size_x; ++x)
335                                 {
336                                         l = RadarMapAtPoint_LineBlock(self.mins_x + x * self.maxs_x, self.mins_y + (self.size_y - self.frame) * self.maxs_y, self.maxs_x, self.maxs_y, self.mins_z, self.maxs_z, self.size_z);
337                                         sharpen_set(x, l);
338                                 }
339                                 break;
340                 }
341
342                 // do we have enough lines?
343                 if(self.frame >= 2)
344                 {
345                         // write a pixel line
346                         fputs(self.cnt, "\"");
347                         for(x = 0; x < self.size_x; ++x)
348                         {
349                                 l = sharpen_get(x, self.ltime);
350                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
351                         }
352                         if(self.frame == self.size_y)
353                                 fputs(self.cnt, "\"\n");
354                         else
355                         {
356                                 fputs(self.cnt, "\",\n");
357                                 print(ftos(self.size_y - self.frame), " lines left\n");
358                         }
359                 }
360
361                 // is this the last line? then write back the missing line
362                 if(self.frame == self.size_y)
363                 {
364                         sharpen_shift(self.size_x);
365                         // write a pixel line
366                         fputs(self.cnt, "\"");
367                         for(x = 0; x < self.size_x; ++x)
368                         {
369                                 l = sharpen_get(x, self.ltime);
370                                 fputs(self.cnt, substring(doublehex, 2 * floor(l * 256.0), 2));
371                         }
372                         if(self.frame == self.size_y)
373                                 fputs(self.cnt, "\"\n");
374                         else
375                         {
376                                 fputs(self.cnt, "\",\n");
377                                 print(ftos(self.size_y - self.frame), " lines left\n");
378                         }
379                 }
380
381                 self.frame += 1;
382                 self.nextthink = time;
383         }
384         else
385         {
386                 // close the file
387                 fputs(self.cnt, "};\n");
388                 fclose(self.cnt);
389                 print("Finished. Please edit data/", self.netname, " with an image editing application and place it in the TGA format in the gfx folder.\n");
390                 RadarMap_Next();
391         }
392 }
393
394 void RadarMap(float argc)
395 {
396         if(radarmapper)
397                 return;
398         float i;
399         radarmapper = spawn();
400         radarmapper.classname = "radarmapper";
401         radarmapper.think = RadarMap_Think;
402         radarmapper.nextthink = time;
403         radarmapper.count = 8; // default to the --trace method, as it is faster now
404         radarmapper.ltime = 1;
405         radarmapper.size_x = 512;
406         radarmapper.size_y = 512;
407         radarmapper.size_z = 1;
408
409         for(i = 1; i < argc; ++i)
410         {
411                 if(argv(i) == "--force")
412                         radarmapper.count |= 1;
413                 else if(argv(i) == "--loop")
414                         radarmapper.count |= 2;
415                 else if(argv(i) == "--quit")
416                         radarmapper.count |= 4;
417                 else if(argv(i) == "--block")
418                 {
419                         radarmapper.count &~= 24;
420                 }
421                 else if(argv(i) == "--trace")
422                 {
423                         radarmapper.count &~= 24;
424                         radarmapper.count |= 8;
425                 }
426                 else if(argv(i) == "--sample")
427                 {
428                         radarmapper.count &~= 24;
429                         radarmapper.count |= 16;
430                 }
431                 else if(argv(i) == "--lineblock")
432                 {
433                         radarmapper.count |= 24;
434                 }
435                 else if(argv(i) == "--flags") // for the recursive call
436                 {
437                         ++i;
438                         radarmapper.count = stof(argv(i));
439                 }
440                 else if(argv(i) == "--sharpen") // for the recursive call
441                 {
442                         ++i;
443                         radarmapper.ltime = stof(argv(i));
444                 }
445                 else if(argv(i) == "--res") // resolution
446                 {
447                         ++i;
448                         radarmapper.size_x = stof(argv(i));
449                         ++i;
450                         radarmapper.size_y = stof(argv(i));
451                 }
452                 else if(argv(i) == "--qual") // quality multiplier
453                 {
454                         ++i;
455                         radarmapper.size_z = stof(argv(i));
456                 }
457                 else
458                 {
459                         remove(radarmapper);
460                         radarmapper = world;
461                         print("Usage: sv_cmd radarmap [--force] [--loop] [--quit] [--block | --trace | --sample | --lineblock] [--sharpen N] [--res W H] [--qual Q]\n");
462                         print("The quality factor Q is roughly proportional to the time taken.\n");
463                         print("--trace supports no quality factor; its result should look like --block with infinite quality factor.\n");
464                         print("--block \n");
465                         return;
466                 }
467         }
468
469         print("Radarmap entity spawned.\n");
470 }
471
472 void BBox()
473 {
474         print("Original size: ", ftos(world.absmin_x), " ", ftos(world.absmin_y), " ", ftos(world.absmin_z));
475         print(" ", ftos(world.absmax_x), " ", ftos(world.absmax_y), " ", ftos(world.absmax_z), "\n");
476         print("Currently set size: ", ftos(world.mins_x), " ", ftos(world.mins_y), " ", ftos(world.mins_z));
477         print(" ", ftos(world.maxs_x), " ", ftos(world.maxs_y), " ", ftos(world.maxs_z), "\n");
478         print("Solid bounding box size:");
479
480         tracebox('1 0 0' * world.absmin_x,
481                  '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
482                  '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
483                  '1 0 0' * world.absmax_x,
484                          MOVE_WORLDONLY,
485                          world);
486         if(trace_startsolid)
487                 print(" ", ftos(world.absmin_x));
488         else
489                 print(" ", ftos(trace_endpos_x));
490
491         tracebox('0 1 0' * world.absmin_y,
492                  '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
493                  '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
494                  '0 1 0' * world.absmax_y,
495                          MOVE_WORLDONLY,
496                          world);
497         if(trace_startsolid)
498                 print(" ", ftos(world.absmin_y));
499         else
500                 print(" ", ftos(trace_endpos_y));
501
502         tracebox('0 0 1' * world.absmin_z,
503                  '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
504                  '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
505                  '0 0 1' * world.absmax_z,
506                          MOVE_WORLDONLY,
507                          world);
508         if(trace_startsolid)
509                 print(" ", ftos(world.absmin_z));
510         else
511                 print(" ", ftos(trace_endpos_z));
512
513         tracebox('1 0 0' * world.absmax_x,
514                  '0 1 0' * world.absmin_y + '0 0 1' * world.absmin_z,
515                  '0 1 0' * world.absmax_y + '0 0 1' * world.absmax_z,
516                  '1 0 0' * world.absmin_x,
517                          MOVE_WORLDONLY,
518                          world);
519         if(trace_startsolid)
520                 print(" ", ftos(world.absmax_x));
521         else
522                 print(" ", ftos(trace_endpos_x));
523
524         tracebox('0 1 0' * world.absmax_y,
525                  '1 0 0' * world.absmin_x + '0 0 1' * world.absmin_z,
526                  '1 0 0' * world.absmax_x + '0 0 1' * world.absmax_z,
527                  '0 1 0' * world.absmin_y,
528                          MOVE_WORLDONLY,
529                          world);
530         if(trace_startsolid)
531                 print(" ", ftos(world.absmax_y));
532         else
533                 print(" ", ftos(trace_endpos_y));
534
535         tracebox('0 0 1' * world.absmax_z,
536                  '1 0 0' * world.absmin_x + '0 1 0' * world.absmin_y,
537                  '1 0 0' * world.absmax_x + '0 1 0' * world.absmax_y,
538                  '0 0 1' * world.absmin_z,
539                          MOVE_WORLDONLY,
540                          world);
541         if(trace_startsolid)
542                 print(" ", ftos(world.absmax_z));
543         else
544                 print(" ", ftos(trace_endpos_z));
545
546         print("\n");
547 }
548
549 void EffectIndexDump()
550 {
551         float d;
552         float fh;
553         string s;
554
555         d = db_create();
556
557         print("begin of effects list\n");
558         db_put(d, "TE_GUNSHOT", "1"); print("effect TE_GUNSHOT is ", ftos(particleeffectnum("TE_GUNSHOT")), "\n");
559         db_put(d, "TE_GUNSHOTQUAD", "1"); print("effect TE_GUNSHOTQUAD is ", ftos(particleeffectnum("TE_GUNSHOTQUAD")), "\n");
560         db_put(d, "TE_SPIKE", "1"); print("effect TE_SPIKE is ", ftos(particleeffectnum("TE_SPIKE")), "\n");
561         db_put(d, "TE_SPIKEQUAD", "1"); print("effect TE_SPIKEQUAD is ", ftos(particleeffectnum("TE_SPIKEQUAD")), "\n");
562         db_put(d, "TE_SUPERSPIKE", "1"); print("effect TE_SUPERSPIKE is ", ftos(particleeffectnum("TE_SUPERSPIKE")), "\n");
563         db_put(d, "TE_SUPERSPIKEQUAD", "1"); print("effect TE_SUPERSPIKEQUAD is ", ftos(particleeffectnum("TE_SUPERSPIKEQUAD")), "\n");
564         db_put(d, "TE_WIZSPIKE", "1"); print("effect TE_WIZSPIKE is ", ftos(particleeffectnum("TE_WIZSPIKE")), "\n");
565         db_put(d, "TE_KNIGHTSPIKE", "1"); print("effect TE_KNIGHTSPIKE is ", ftos(particleeffectnum("TE_KNIGHTSPIKE")), "\n");
566         db_put(d, "TE_EXPLOSION", "1"); print("effect TE_EXPLOSION is ", ftos(particleeffectnum("TE_EXPLOSION")), "\n");
567         db_put(d, "TE_EXPLOSIONQUAD", "1"); print("effect TE_EXPLOSIONQUAD is ", ftos(particleeffectnum("TE_EXPLOSIONQUAD")), "\n");
568         db_put(d, "TE_TAREXPLOSION", "1"); print("effect TE_TAREXPLOSION is ", ftos(particleeffectnum("TE_TAREXPLOSION")), "\n");
569         db_put(d, "TE_TELEPORT", "1"); print("effect TE_TELEPORT is ", ftos(particleeffectnum("TE_TELEPORT")), "\n");
570         db_put(d, "TE_LAVASPLASH", "1"); print("effect TE_LAVASPLASH is ", ftos(particleeffectnum("TE_LAVASPLASH")), "\n");
571         db_put(d, "TE_SMALLFLASH", "1"); print("effect TE_SMALLFLASH is ", ftos(particleeffectnum("TE_SMALLFLASH")), "\n");
572         db_put(d, "TE_FLAMEJET", "1"); print("effect TE_FLAMEJET is ", ftos(particleeffectnum("TE_FLAMEJET")), "\n");
573         db_put(d, "EF_FLAME", "1"); print("effect EF_FLAME is ", ftos(particleeffectnum("EF_FLAME")), "\n");
574         db_put(d, "TE_BLOOD", "1"); print("effect TE_BLOOD is ", ftos(particleeffectnum("TE_BLOOD")), "\n");
575         db_put(d, "TE_SPARK", "1"); print("effect TE_SPARK is ", ftos(particleeffectnum("TE_SPARK")), "\n");
576         db_put(d, "TE_PLASMABURN", "1"); print("effect TE_PLASMABURN is ", ftos(particleeffectnum("TE_PLASMABURN")), "\n");
577         db_put(d, "TE_TEI_G3", "1"); print("effect TE_TEI_G3 is ", ftos(particleeffectnum("TE_TEI_G3")), "\n");
578         db_put(d, "TE_TEI_SMOKE", "1"); print("effect TE_TEI_SMOKE is ", ftos(particleeffectnum("TE_TEI_SMOKE")), "\n");
579         db_put(d, "TE_TEI_BIGEXPLOSION", "1"); print("effect TE_TEI_BIGEXPLOSION is ", ftos(particleeffectnum("TE_TEI_BIGEXPLOSION")), "\n");
580         db_put(d, "TE_TEI_PLASMAHIT", "1"); print("effect TE_TEI_PLASMAHIT is ", ftos(particleeffectnum("TE_TEI_PLASMAHIT")), "\n");
581         db_put(d, "EF_STARDUST", "1"); print("effect EF_STARDUST is ", ftos(particleeffectnum("EF_STARDUST")), "\n");
582         db_put(d, "TR_ROCKET", "1"); print("effect TR_ROCKET is ", ftos(particleeffectnum("TR_ROCKET")), "\n");
583         db_put(d, "TR_GRENADE", "1"); print("effect TR_GRENADE is ", ftos(particleeffectnum("TR_GRENADE")), "\n");
584         db_put(d, "TR_BLOOD", "1"); print("effect TR_BLOOD is ", ftos(particleeffectnum("TR_BLOOD")), "\n");
585         db_put(d, "TR_WIZSPIKE", "1"); print("effect TR_WIZSPIKE is ", ftos(particleeffectnum("TR_WIZSPIKE")), "\n");
586         db_put(d, "TR_SLIGHTBLOOD", "1"); print("effect TR_SLIGHTBLOOD is ", ftos(particleeffectnum("TR_SLIGHTBLOOD")), "\n");
587         db_put(d, "TR_KNIGHTSPIKE", "1"); print("effect TR_KNIGHTSPIKE is ", ftos(particleeffectnum("TR_KNIGHTSPIKE")), "\n");
588         db_put(d, "TR_VORESPIKE", "1"); print("effect TR_VORESPIKE is ", ftos(particleeffectnum("TR_VORESPIKE")), "\n");
589         db_put(d, "TR_NEHAHRASMOKE", "1"); print("effect TR_NEHAHRASMOKE is ", ftos(particleeffectnum("TR_NEHAHRASMOKE")), "\n");
590         db_put(d, "TR_NEXUIZPLASMA", "1"); print("effect TR_NEXUIZPLASMA is ", ftos(particleeffectnum("TR_NEXUIZPLASMA")), "\n");
591         db_put(d, "TR_GLOWTRAIL", "1"); print("effect TR_GLOWTRAIL is ", ftos(particleeffectnum("TR_GLOWTRAIL")), "\n");
592         db_put(d, "SVC_PARTICLE", "1"); print("effect SVC_PARTICLE is ", ftos(particleeffectnum("SVC_PARTICLE")), "\n");
593
594         fh = fopen("effectinfo.txt", FILE_READ);
595         while((s = fgets(fh)))
596         {
597                 tokenize(s); // tokenize_console would hit the loop counter :(
598                 if(argv(0) == "effect")
599                 {
600                         if(db_get(d, argv(1)) != "1")
601                         {
602                                 if(particleeffectnum(argv(1)) >= 0)
603                                         print("effect ", argv(1), " is ", ftos(particleeffectnum(argv(1))), "\n");
604                                 db_put(d, argv(1), "1");
605                         }
606                 }
607         }
608         print("end of effects list\n");
609
610         db_close(d);
611 }
612
613 void make_mapinfo_Think()
614 {
615         if(MapInfo_FilterGametype(MAPINFO_TYPE_ALL, 0, 0, 0, 1))
616         {
617                 print("Done rebuiling mapinfos.\n");
618                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
619                 remove(self);
620         }
621         else
622         {
623                 self.think = make_mapinfo_Think;
624                 self.nextthink = time;
625         }
626 }
627
628 void GameCommand(string command)
629 {
630         float argc;
631         entity client, e;
632         vector v;
633         float entno, i, n;
634         string s;
635         argc = tokenize_console(command);
636
637         if(argv(0) == "help" || argc == 0)
638         {
639                 print("Usage: sv_cmd COMMAND..., where possible commands are:\n");
640                 print("  adminmsg clientnumber \"message\"\n");
641                 print("  teamstatus\n");
642                 print("  printstats\n");
643                 print("  make_mapinfo\n");
644                 print("  gametype dm|ctf|...\n");
645                 print("  savedb filename\n");
646                 print("  dumpdb filename\n");
647                 print("  loaddb filename\n");
648                 print("  allready\n");
649                 print("  effectindexdump\n");
650                 print("  radarmap [--force] [--quit | --loop] [sharpness]\n");
651                 print("  bbox\n");
652                 print("  cvar_changes\n");
653                 print("  find classname\n");
654                 GameCommand_Vote("help", world);
655                 GameCommand_Ban("help");
656                 GameCommand_Generic("help");
657                 return;
658         }
659
660         if(GameCommand_Vote(command, world))
661                 return;
662
663         if(GameCommand_Ban(command))
664                 return;
665
666         if(GameCommand_Generic(command))
667                 return;
668
669         if(argv(0) == "printstats")
670         {
671                 DumpStats(FALSE);
672                 return;
673         }
674
675         if(argv(0) == "make_mapinfo")
676         {
677                 e = spawn();
678                 e.classname = "make_mapinfo";
679                 e.think = make_mapinfo_Think;
680                 e.nextthink = time;
681                 MapInfo_Enumerate();
682                 return;
683         }
684
685         if(argv(0) == "warp") if(argc == 2) if(cvar("g_campaign"))
686         {
687                 CampaignLevelWarp(stof(argv(1)));
688                 return;
689         }
690
691         if(argv(0) == "gotomap") if(argc == 2)
692         {
693                 print(GotoMap(argv(1)), "\n");
694                 return;
695         }
696
697         if(argv(0) == "gametype") if(argc == 2)
698         {
699                 float t, tsave;
700                 s = argv(1);
701                 t = MapInfo_Type_FromString(s);
702                 tsave = MapInfo_CurrentGametype();
703                 if(t)
704                 {
705                         MapInfo_SwitchGameType(t);
706                         MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
707                         if(MapInfo_count > 0)
708                         {
709                                 bprint("Game type successfully switched to ", s, "\n");
710                         }
711                         else
712                         {
713                                 bprint("Cannot use this game type: no map for it found\n");
714                                 MapInfo_SwitchGameType(tsave);
715                                 MapInfo_FilterGametype(MapInfo_CurrentGametype(), MapInfo_CurrentFeatures(), MapInfo_RequiredFlags(), MapInfo_ForbiddenFlags(), 0);
716                         }
717                 }
718                 else
719                         bprint("Game type switch to ", s, " failed: this type does not exist!\n");
720                 return;
721         }
722
723         if(argv(0) == "adminmsg")
724         if(argc == 3)
725         {
726                 entno = stof(argv(1));
727
728                 if((entno < 1) | (entno > maxclients)) {
729                         print("Player ", argv(1), " doesn't exist\n");
730                         return;
731                 }
732
733                 client = edict_num(entno);
734
735                 if(client.flags & FL_CLIENT)
736                 {
737                         centerprint_atprio(client, CENTERPRIO_ADMIN, strcat("^3", admin_name(), ":\n\n^7", argv(2)));
738                         sprint(client, strcat("\{1}\{13}^3", admin_name(), "^7: ", argv(2), "\n"));
739                         print("Message sent to ", client.netname, "\n");
740                 }
741                 else
742                         print("Client not found\n");
743
744                 return;
745         }
746
747         if(argv(0) == "savedb") if(argc == 2)
748         {
749                 db_save(ServerProgsDB, argv(1));
750                 print("DB saved.\n");
751                 return;
752         }
753
754         if(argv(0) == "dumpdb") if(argc == 2)
755         {
756                 db_dump(ServerProgsDB, argv(1));
757                 print("DB dumped.\n");
758                 return;
759         }
760
761         if(argv(0) == "loaddb") if(argc == 2)
762         {
763                 db_close(ServerProgsDB);
764                 ServerProgsDB = db_load(argv(1));
765                 print("DB loaded.\n");
766                 return;
767         }
768
769         if (argv(0) == "nospectators")
770         {
771                 blockSpectators = 1;
772                 local entity plr;
773                 FOR_EACH_CLIENT(plr) //give every spectator <g_maxplayers_spectator_blocktime> seconds time to become a player
774                 {
775                         if(plr.classname == "spectator" || plr.classname == "observer")
776                         {
777                                 plr.spectatortime = time;
778                                 sprint(plr, strcat("^7You have to become a player within the next ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds, otherwise you will be kicked, because spectators aren't allowed at this time!\n"));
779                         }
780                 }
781                 bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(cvar("g_maxplayers_spectator_blocktime")), " seconds!\n"));
782                 return;
783         }
784
785         if (argv(0) == "lockteams")
786         {
787                 if(teams_matter)
788                 {
789                         lockteams = 1;
790                         bprint("^1The teams are now locked.\n");
791                 }
792                 else
793                         bprint("That command can only be used in a team-based gamemode.\n");
794                 return;
795         }
796
797         if (argv(0) == "unlockteams")
798         {
799                 if(teams_matter)
800                 {
801                         lockteams = 0;
802                         bprint("^1The teams are now unlocked.\n");
803                 }
804                 else
805                         bprint("That command can only be used in a team-based gamemode.\n");
806                 return;
807         }
808         if(argv(0) == "movetoteam")
809         if(argc == 3 || argc == 4) {
810 //      sv_cmd movetoteam  player_id  team_colour
811 //      sv_cmd movetoteam  player_id  team_colour  type_of_move
812
813 //      type of move
814 //      0 (00) automove centerprint, admin message
815 //      1 (01) automove centerprint, no admin message
816 //      2 (10) no centerprint, admin message
817 //      3 (11) no centerprint, no admin message
818
819                 if(!teams_matter) {  // death match
820                         print("Currently not playing a team game\n");
821                         return;
822                 }
823
824                 entno = stof(argv(1));
825
826                 // player_id is out of range
827                 if((entno < 1) | (entno > maxclients)) {
828                         print("Player ", argv(1), " doesn't exist\n");
829                         return;
830                 }
831
832                         client = edict_num(entno);
833
834                 // player entity is not a client
835                 if not(client.flags & FL_CLIENT) {
836                         print("Player ", argv(1), " doesn't exist\n");
837                         return;
838                 }
839
840                 // find the team to move the player to
841                 float team_colour;
842
843                 team_colour = ColourToNumber(argv(2));
844
845                 if(team_colour == client.team) {  // player already on the team
846                         print("Player ", argv(1), " (", client.netname, ") is already on the ", ColoredTeamName(client.team), "\n");
847                         return;
848                 } else if(team_colour == 0)  // auto team
849                         team_colour = NumberToTeamNumber(FindSmallestTeam(client, FALSE));
850
851                 switch(team_colour) {
852                         case COLOR_TEAM1:
853                                 if(c1 == -1) {
854                                         print("Sorry, there isn't a red team\n");
855                                         return;
856                 }
857                         break;
858
859                         case COLOR_TEAM2:
860                                 if(c2 == -1) {
861                                         print("Sorry, there isn't a blue team\n");
862                 return;
863         }
864                         break;
865
866                         case COLOR_TEAM3:
867                                 if(c3 == -1) {
868                                         print("Sorry, there isn't a yellow team\n");
869                                         return;
870                                 }
871                         break;
872
873                         case COLOR_TEAM4:
874                                 if(c4 == -1) {
875                                         print("Sorry, there isn't a pink team\n");
876                                         return;
877                                 }
878                         break;
879
880                         default:
881                                 print("Sorry, team ", argv(2), " doesn't exist\n");
882                                 return;
883                 }
884
885                 MoveToTeam(client, team_colour, 6, stof(argv(3)));
886                 print("Player ", argv(1), " (", client.netname, ") has been moved to the ", ColoredTeamName(team_colour), "\n");
887
888                 return;
889         }
890         if (argv(0) == "teamstatus")
891         {
892                 Score_NicePrint(world);
893                 return;
894         }
895         if (argv(0) == "allready")
896         {
897                 ReadyRestart();
898                 return;
899         }
900         if (argv(0) == "effectindexdump")
901         {
902                 EffectIndexDump();
903                 return;
904         }
905         if (argv(0) == "radarmap")
906         {
907                 RadarMap(argc);
908                 return;
909         }
910         if (argv(0) == "bbox")
911         {
912                 BBox();
913                 return;
914         }
915         if (argv(0) == "cvar_changes")
916         {
917                 print(cvar_changes);
918                 return;
919         }
920         if (argv(0) == "find") if(argc == 2)
921         {
922                 for(client = world; (client = find(client, classname, argv(1))); )
923                         print(etos(client), "\n");
924                 return;
925         }
926         if (argv(0) == "records")
927         {
928                 strunzone(records_reply);
929                 records_reply = strzone(getrecords());
930                 print(records_reply);
931                 return;
932         }
933
934         if(argv(0) == "cointoss")
935         {
936                 bprint("^3Throwing coin... Result: ");
937                 if (random() > 0.5)
938                         bprint("^1heads ^3!\n");
939                 else
940                         bprint("^1tails ^3!\n");
941                 return;
942         }
943
944         if(argv(0) == "__FORCE_READY_RESTART")
945         {
946                 reset_map(FALSE);
947                 return;
948         }
949
950         if(argv(0) == "debug_shotorg")
951         {
952                 debug_shotorg = stov(argv(1));
953                 return;
954         }
955
956         if(argv(0) == "gettaginfo") if(argc >= 4)
957         {
958                 e = spawn();
959                 if(argv(1) == "w")
960                         setmodel(e, (nextent(world)).weaponentity.model);
961                 else
962                         setmodel(e, argv(1));
963                 e.frame = stof(argv(2));
964                 i = gettagindex(e, argv(3));
965                 if(i)
966                 {
967                         v = gettaginfo(e, i);
968                         print("model ", e.model, " frame ", ftos(e.frame), " tag ", argv(3));
969                         print(" index = ", ftos(i));
970                         print(" vector = ", ftos(v_x), " ", ftos(v_y), " ", ftos(v_z), "\n");
971                         if(argc >= 6)
972                         {
973                                 v_y = -v_y;
974                                 localcmd(strcat(argv(4), vtos(v), argv(5), "\n"));
975                         }
976                 }
977                 else
978                         print("bone not found\n");
979                 remove(e);
980                 return;
981         }
982
983         if(argv(0) == "time")
984         {
985                 print("time = ", ftos(time), "\n");
986                 print("frame start = ", ftos(gettime(GETTIME_FRAMESTART)), "\n");
987                 print("realtime = ", ftos(gettime(GETTIME_REALTIME)), "\n");
988                 print("hires = ", ftos(gettime(GETTIME_HIRES)), "\n");
989                 print("uptime = ", ftos(gettime(GETTIME_UPTIME)), "\n");
990                 print("localtime = ", strftime(TRUE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
991                 print("gmtime = ", strftime(FALSE, "%a %b %e %H:%M:%S %Z %Y"), "\n");
992                 return;
993         }
994
995         if(argv(0) == "tracebug")
996         {
997                 print("TEST CASE. If this returns the runaway loop counter error, possibly everything is oaky.\n");
998                 for(;;)
999                 {
1000                         vector org, delta, start, end, p, q, q0, pos;
1001                         float safe, unsafe, dq, dqf;
1002
1003                         org = world.mins;
1004                         delta = world.maxs - world.mins;
1005
1006                         start_x = org_x + random() * delta_x;
1007                         start_y = org_y + random() * delta_y;
1008                         start_z = org_z + random() * delta_z;
1009
1010                         end_x = org_x + random() * delta_x;
1011                         end_y = org_y + random() * delta_y;
1012                         end_z = org_z + random() * delta_z;
1013
1014                         start = stov(vtos(start));
1015                         end = stov(vtos(end));
1016
1017                         tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1018                         if(!trace_startsolid)
1019                         {
1020                                 p = trace_endpos;
1021                                 tracebox(p, PL_MIN, PL_MAX, p, MOVE_NOMONSTERS, world);
1022                                 if(trace_startsolid || trace_fraction == 1)
1023                                 {
1024                                         rint(42); // do an engine breakpoint on VM_rint so you can get the trace that errnoeously returns startsolid
1025                                         tracebox(start, PL_MIN, PL_MAX, end, MOVE_NOMONSTERS, world);
1026                                         tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1027
1028                                         if(trace_startsolid)
1029                                         {
1030                                                 // how much do we need to back off?
1031                                                 safe = 1;
1032                                                 unsafe = 0;
1033                                                 for(;;)
1034                                                 {
1035                                                         pos = p * (1 - (safe + unsafe) * 0.5) + start * ((safe + unsafe) * 0.5);
1036                                                         tracebox(pos, PL_MIN, PL_MAX, pos, MOVE_NOMONSTERS, world);
1037                                                         if(trace_startsolid)
1038                                                         {
1039                                                                 if((safe + unsafe) * 0.5 == unsafe)
1040                                                                         break;
1041                                                                 unsafe = (safe + unsafe) * 0.5;
1042                                                         }
1043                                                         else
1044                                                         {
1045                                                                 if((safe + unsafe) * 0.5 == safe)
1046                                                                         break;
1047                                                                 safe = (safe + unsafe) * 0.5;
1048                                                         }
1049                                                 }
1050
1051                                                 print("safe distance to back off: ", ftos(safe * vlen(p - start)), "qu\n");
1052                                                 print("unsafe distance to back off: ", ftos(unsafe * vlen(p - start)), "qu\n");
1053
1054                                                 tracebox(p, PL_MIN + '0.1 0.1 0.1', PL_MAX - '0.1 0.1 0.1', p, MOVE_NOMONSTERS, world);
1055                                                 if(trace_startsolid)
1056                                                         print("trace_endpos much in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1057                                                 else
1058                                                         print("trace_endpos just in solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1059                                                 break;
1060                                         }
1061
1062                                         q0 = p;
1063                                         dq = 0;
1064                                         dqf = 1;
1065                                         for(;;)
1066                                         {
1067                                                 q = p + normalize(end - p) * (dq + dqf);
1068                                                 if(q == q0)
1069                                                         break;
1070                                                 tracebox(p, PL_MIN, PL_MAX, q, MOVE_NOMONSTERS, world);
1071                                                 if(trace_startsolid)
1072                                                         error("THIS ONE cannot happen");
1073                                                 if(trace_fraction > 0)
1074                                                         dq += dqf * trace_fraction;
1075                                                 dqf *= 0.5;
1076                                                 q0 = q;
1077                                         }
1078                                         if(dq > 0)
1079                                         {
1080                                                 print("trace_endpos still before solid when tracing from ", vtos(start), " to ", vtos(end), " endpos ", vtos(p), "\n");
1081                                                 print("could go ", ftos(dq), " units further to ", vtos(q), "\n");
1082                                                 break;
1083                                         }
1084                                 }
1085                         }
1086                 }
1087         }
1088
1089         if(argv(0) == "tracebug2")
1090         {
1091                 e = nextent(world);
1092                 float f;
1093                 vector vv, dv;
1094                 tracebox(e.origin + '0 0 32', e.mins, e.maxs, e.origin + '0 0 -1024', MOVE_NORMAL, e);
1095                 vv = trace_endpos;
1096                 if(trace_fraction == 1)
1097                 {
1098                         print("not above ground, aborting\n");
1099                         return;
1100                 }
1101                 f = 0;
1102                 for(i = 0; i < 100000; ++i)
1103                 {
1104                         dv = randomvec();
1105                         if(dv_z > 0)
1106                                 dv = -1 * dv;
1107                         tracebox(vv, e.mins, e.maxs, vv + dv, MOVE_NORMAL, e);
1108                         if(trace_startsolid)
1109                                 print("bug 1\n");
1110                         if(trace_fraction == 1)
1111                         if(dv_z < f)
1112                         {
1113                                 print("bug 2: ", ftos(dv_x), " ", ftos(dv_y), " ", ftos(dv_z));
1114                                 print(" (", ftos(asin(dv_z / vlen(dv)) * 180 / M_PI), " degrees)\n");
1115                                 f = dv_z;
1116                         }
1117                 }
1118                 print("highest possible dist: ", ftos(f), "\n");
1119                 return;
1120         }
1121
1122         if(argv(0) == "tracewalk")
1123         {
1124                 e = nextent(world);
1125                 if(tracewalk(e, stov(argv(1)), e.mins, e.maxs, stov(argv(2)), MOVE_NORMAL))
1126                         print("can walk\n");
1127                 else
1128                         print("cannot walk\n");
1129                 return;
1130         }
1131
1132         if(argv(0) == "onslaught_updatelinks")
1133         {
1134                 onslaught_updatelinks();
1135                 print("ONS links updated\n");
1136                 return;
1137         }
1138
1139         if(argv(0) == "bot_cmd")
1140         {
1141                 local entity bot;
1142
1143                 if(argv(1) == "help")
1144                 {
1145                         if(argc==2)
1146                         {
1147                                 bot_list_commands();
1148                                 print("\nsv_cmd bot_cmd reset          #Clear the cmd queues of all bots\n");
1149                                 print("sv_cmd bot_cmd load <file>    #Load script file\n");
1150                                 print("\nUse sv_cmd bot_cmd help <command> for more\n\n");
1151                                 return;
1152                         }
1153
1154                         bot_cmdhelp(argv(2));
1155                         return;
1156                 }
1157
1158                 // Clear all bot queues
1159                 if(argv(1) == "reset")
1160                 {
1161                         bot_resetqueues();
1162                         return;
1163                 }
1164
1165                 // Load cmds from file
1166                 if(argv(1) == "load" && argc == 3)
1167                 {
1168                         float fh;
1169                         fh = fopen(argv(2), FILE_READ);
1170                         if(fh < 0)
1171                         {
1172                                 print("cannot open the file\n");
1173                                 return;
1174                         }
1175
1176                         i = 0;
1177                         while((s = fgets(fh)))
1178                         {
1179                                 argc = tokenize_console(s);
1180
1181                                 if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
1182                                 {
1183                                         // let's start at token 2 so we can skip sv_cmd bot_cmd
1184                                         bot = find_bot_by_number(stof(argv(2)));
1185                                         if(bot == world)
1186                                                 bot = find_bot_by_name(argv(2));
1187                                         if(bot)
1188                                                 bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
1189                                 }
1190                                 else
1191                                         localcmd(strcat(s, "\n"));
1192
1193                                 ++i;
1194                         }
1195
1196                         print(ftos(i), " commands read\n");
1197
1198                         fclose(fh);
1199
1200                         return;
1201                 }
1202
1203                 if(argc < 3)
1204                 {
1205                         print("Usage: sv_cmd bot_cmd <bot name or number> <command> [argument]\n");
1206                         print("Examples: bot_cmd <id> cc \"say something\"\n");
1207                         print("          bot_cmd <id> presskey jump\n");
1208                         print("          .. or sv_cmd bot_cmd help <command> for more\n");
1209                         return;
1210                 }
1211
1212                 bot = find_bot_by_number(stof(argv(1)));
1213                 if(bot == world)
1214                         bot = find_bot_by_name(argv(1));
1215
1216                 if(bot)
1217                         bot_queuecommand(bot, strcat(argv(2), " ", argv(3)));
1218                 else
1219                         print(strcat("Error: Unable to find a bot with the name or number '",argv(1),"'\n"));
1220
1221                 return;
1222         }
1223
1224         if(argv(0) == "playerdemo")
1225         {
1226                 if(argv(1) == "read")
1227                 {
1228                         entno = stof(argv(2));
1229                         if((entno < 1) | (entno > maxclients)) {
1230                                 print("Player ", argv(2), " doesn't exist\n");
1231                                 return;
1232                         }
1233                         client = edict_num(entno);
1234                         if(clienttype(client) != CLIENTTYPE_BOT) {
1235                                 print("Player ", client.netname, " is not a bot\n");
1236                                 return;
1237                         }
1238                         self = client;
1239                         playerdemo_open_read(argv(3));
1240                         return;
1241                 }
1242                 else if(argv(1) == "write")
1243                 {
1244                         entno = stof(argv(2));
1245                         if((entno < 1) | (entno > maxclients)) {
1246                                 print("Player ", argv(2), " doesn't exist\n");
1247                                 return;
1248                         }
1249                         client = edict_num(entno);
1250                         self = client;
1251                         playerdemo_open_write(argv(3));
1252                         return;
1253                 }
1254                 else if(argv(1) == "auto_read_and_write")
1255                 {
1256                         s = argv(2);
1257                         n = stof(argv(3));
1258                         cvar_set("bot_number", ftos(n));
1259                         localcmd("wait; wait; wait\n");
1260                         for(i = 0; i < n; ++i)
1261                                 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1262                         localcmd("sv_cmd playerdemo write 1 ", ftos(n+1), "\n");
1263                         return;
1264                 }
1265                 else if(argv(1) == "auto_read")
1266                 {
1267                         s = argv(2);
1268                         n = stof(argv(3));
1269                         cvar_set("bot_number", ftos(n));
1270                         localcmd("wait; wait; wait\n");
1271                         for(i = 0; i < n; ++i)
1272                                 localcmd("sv_cmd playerdemo read ", ftos(i+2), " ", s, ftos(i+1), "\n");
1273                         return;
1274                 }
1275         }
1276
1277         if(argv(0) == "anticheat")
1278         {
1279                 entno = stof(argv(1));
1280                 if((entno < 1) | (entno > maxclients)) {
1281                         print("Player ", argv(1), " doesn't exist\n");
1282                         return;
1283                 }
1284                 client = edict_num(entno);
1285                 if(clienttype(client) != CLIENTTYPE_REAL && clienttype(client) != CLIENTTYPE_BOT) {
1286                         print("Player ", client.netname, " is not active\n");
1287                         return;
1288                 }
1289                 self = client;
1290                 anticheat_report();
1291                 return;
1292         }
1293
1294         if(argv(0) == "defer_clear")
1295         if(argc == 2)
1296         {
1297                 entno = stof(argv(1));
1298
1299                 // player_id is out of range
1300                 if((entno < 1) | (entno > maxclients)) {
1301                         print("Player ", argv(1), " doesn't exist\n");
1302                         return;
1303                 }
1304
1305                 client = edict_num(entno);
1306
1307                 if not(client.flags & FL_CLIENT) {
1308                         print("Player ", argv(1), " doesn't exist\n");
1309                         return;
1310                 }
1311
1312                 if(clienttype(client) == CLIENTTYPE_BOT) {
1313                         print("Player ", argv(1), " (", client.netname, ") is a bot\n");
1314                         return;
1315                 }
1316
1317                 stuffcmd(client, "defer clear\n");
1318                 print("defer clear stuffed to ", argv(1), " (", client.netname, ")\n");
1319                 return;
1320         }
1321
1322         if(argv(0) == "defer_clear_all")
1323         {
1324                 FOR_EACH_CLIENTSLOT(client)
1325                         GameCommand(strcat("defer_clear ", ftos(num_for_edict(client))));       
1326
1327                 return;
1328         }
1329
1330         print("Invalid command. For a list of supported commands, try sv_cmd help.\n");
1331 }
1332