Nothing sets flashblend, so remove it.
[divverent/nexuiz.git] / data / qcsrc / server / miscfunctions.qc
1 void() info_player_deathmatch; // needed for the other spawnpoints
2 string ColoredTeamName(float t);
3
4 float DistributeEvenly_amount;
5 float DistributeEvenly_totalweight;
6 void DistributeEvenly_Init(float amount, float totalweight)
7 {
8         if(DistributeEvenly_amount)
9         {
10                 dprint("DistributeEvenly_Init: UNFINISHED DISTRIBUTION (", ftos(DistributeEvenly_amount), " for ");
11                 dprint(ftos(DistributeEvenly_totalweight), " left!)\n");
12         }
13         if(totalweight == 0)
14                 DistributeEvenly_amount = 0;
15         else
16                 DistributeEvenly_amount = amount;
17         DistributeEvenly_totalweight = totalweight;
18 }
19 float DistributeEvenly_Get(float weight)
20 {
21         float f;
22         if(weight <= 0)
23                 return 0;
24         f = floor(0.5 + DistributeEvenly_amount * weight / DistributeEvenly_totalweight);
25         DistributeEvenly_totalweight -= weight;
26         DistributeEvenly_amount -= f;
27         return f;
28 }
29
30 void move_out_of_solid_expand(entity e, vector by)
31 {
32         float eps = 0.0625;
33         tracebox(e.origin, e.mins - '1 1 1' * eps, e.maxs + '1 1 1' * eps, e.origin + by, MOVE_WORLDONLY, e);
34         if(trace_startsolid)
35                 return;
36         if(trace_fraction < 1)
37         {
38                 // hit something
39                 // adjust origin in the other direction...
40                 e.origin = e.origin - by * (1 - trace_fraction);
41         }
42 }
43
44 void move_out_of_solid(entity e)
45 {
46         vector o, m0, m1;
47
48         o = e.origin;
49         traceline(o, o, MOVE_WORLDONLY, e);
50         if(trace_startsolid)
51         {
52                 dprint("origin is in solid too! (", vtos(o), ")");
53                 return;
54         }
55
56         tracebox(o, e.mins, e.maxs, o, MOVE_WORLDONLY, e);
57         if(!trace_startsolid)
58                 return;
59
60         m0 = e.mins;
61         m1 = e.maxs;
62         e.mins = '0 0 0';
63         e.maxs = '0 0 0';
64         move_out_of_solid_expand(e, '1 0 0' * m0_x); e.mins_x = m0_x;
65         move_out_of_solid_expand(e, '1 0 0' * m1_x); e.maxs_x = m1_x;
66         move_out_of_solid_expand(e, '0 1 0' * m0_y); e.mins_y = m0_y;
67         move_out_of_solid_expand(e, '0 1 0' * m1_y); e.maxs_y = m1_y;
68         move_out_of_solid_expand(e, '0 0 1' * m0_z); e.mins_z = m0_z;
69         move_out_of_solid_expand(e, '0 0 1' * m1_z); e.maxs_z = m1_z;
70         setorigin(e, e.origin);
71
72         tracebox(e.origin, e.mins, e.maxs, e.origin, MOVE_WORLDONLY, e);
73         if(trace_startsolid)
74         {
75                 dprint("could not get out of solid (", vtos(o), ")\n");
76                 return;
77         }
78 }
79
80 #define FOR_EACH_CLIENT(v) for(v = world; (v = findflags(v, flags, FL_CLIENT)) != world; )
81 #define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if(clienttype(v) == CLIENTTYPE_REAL)
82 string STR_PLAYER = "player";
83 #define FOR_EACH_PLAYER(v) for(v = world; (v = find(v, classname, STR_PLAYER)) != world; )
84 #define FOR_EACH_REALPLAYER(v) FOR_EACH_PLAYER(v) if(clienttype(v) == CLIENTTYPE_REAL)
85
86 // change that to actually calling strcat when running on an engine without
87 // unlimited tempstrings:
88 // string strcat1(string s) = #115; // FRIK_FILE
89 #define strcat1(s) (s)
90
91 float logfile_open;
92 float logfile;
93
94 void(string s) bcenterprint
95 {
96         // TODO replace by MSG_ALL (would show it to spectators too, though)?
97         entity head;
98         FOR_EACH_PLAYER(head)
99                 if(clienttype(head) == CLIENTTYPE_REAL)
100                         centerprint(head, s);
101 }
102
103 void(string s, float check_dangerous) ServerConsoleEcho =
104 {
105         local string ch;
106         if (checkextension("DP_SV_PRINT"))
107                 print(s, "\n");
108         else
109         {
110                 localcmd("echo \"");
111                 if(check_dangerous)
112                 {
113                         while(strlen(s))
114                         {
115                                 ch = substring(s, 0, 1);
116                                 if(ch != "\"" && ch != "\r" && ch != "\n")
117                                         localcmd(ch);
118                                 s = substring(s, 1, strlen(s) - 1);
119                         }
120                 }
121                 else
122                 {
123                         localcmd(s);
124                 }
125                 localcmd("\"\n");
126         }
127 }
128
129 void(string s, float check_dangerous) GameLogEcho =
130 {
131         string fn;
132         float matches;
133
134         if(cvar("sv_eventlog_files"))
135         {
136                 if(!logfile_open)
137                 {
138                         logfile_open = TRUE;
139                         matches = cvar("sv_eventlog_files_counter") + 1;
140                         cvar_set("sv_eventlog_files_counter", ftos(matches));
141                         fn = ftos(matches);
142                         if(strlen(fn) < 8)
143                                 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
144                         fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
145                         logfile = fopen(fn, FILE_APPEND);
146                 }
147                 if(logfile >= 0)
148                         fputs(logfile, strcat(s, "\n"));
149         }
150         if(cvar("sv_eventlog_console"))
151         {
152                 ServerConsoleEcho(s, check_dangerous);
153         }
154 }
155
156 void() GameLogInit =
157 {
158         logfile_open = 0;
159         // will be opened later
160 }
161
162 void() GameLogClose =
163 {
164         if(logfile_open && logfile >= 0)
165         {
166                 fclose(logfile);
167                 logfile = -1;
168         }
169 }
170
171 float math_mod(float a, float b)
172 {
173         return a - (floor(a / b) * b);
174 }
175
176 void relocate_spawnpoint()
177 {
178         // nudge off the floor
179         setorigin(self, self.origin + '0 0 1');
180
181         tracebox(self.origin, PL_MIN, PL_MAX, self.origin, TRUE, self);
182         if (trace_startsolid)
183         {
184                 objerror("player spawn point in solid, mapper sucks!\n");
185                 return;
186         }
187
188         if(cvar("g_spawnpoints_autodrop"))
189         {
190                 setsize(self, PL_MIN, PL_MAX);
191                 droptofloor();
192         }
193 }
194
195 #define strstr strstrofs
196 /*
197 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
198 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
199 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
200 // BE CONSTANT OR strzoneD!
201 float(string haystack, string needle, float offset) strstr =
202 {
203         float len, endpos;
204         string found;
205         len = strlen(needle);
206         endpos = strlen(haystack) - len;
207         while(offset <= endpos)
208         {
209                 found = substring(haystack, offset, len);
210                 if(found == needle)
211                         return offset;
212                 offset = offset + 1;
213         }
214         return -1;
215 }
216 */
217
218 float NUM_NEAREST_ENTITIES = 4;
219 entity nearest_entity[NUM_NEAREST_ENTITIES];
220 float nearest_length[NUM_NEAREST_ENTITIES];
221 entity(vector point, .string field, string value, vector axismod) findnearest =
222 {
223         entity localhead;
224         float i;
225         float j;
226         float len;
227         vector dist;
228
229         float num_nearest;
230         num_nearest = 0;
231
232         localhead = find(world, field, value);
233         while(localhead)
234         {
235                 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
236                         dist = localhead.oldorigin;
237                 else
238                         dist = localhead.origin;
239                 dist = dist - point;
240                 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
241                 len = vlen(dist);
242
243                 for(i = 0; i < num_nearest; ++i)
244                 {
245                         if(len < nearest_length[i])
246                                 break;
247                 }
248
249                 // now i tells us where to insert at
250                 //   INSERTION SORT! YOU'VE SEEN IT! RUN!
251                 if(i < NUM_NEAREST_ENTITIES)
252                 {
253                         for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
254                         {
255                                 nearest_length[j + 1] = nearest_length[j];
256                                 nearest_entity[j + 1] = nearest_entity[j];
257                         }
258                         nearest_length[i] = len;
259                         nearest_entity[i] = localhead;
260                         if(num_nearest < NUM_NEAREST_ENTITIES)
261                                 num_nearest = num_nearest + 1;
262                 }
263
264                 localhead = find(localhead, field, value);
265         }
266
267         // now use the first one from our list that we can see
268         for(i = 0; i < num_nearest; ++i)
269         {
270                 traceline(point, nearest_entity[i].origin, TRUE, world);
271                 if(trace_fraction == 1)
272                 {
273                         if(i != 0)
274                         {
275                                 dprint("Nearest point (");
276                                 dprint(nearest_entity[0].netname);
277                                 dprint(") is not visible, using a visible one.\n");
278                         }
279                         return nearest_entity[i];
280                 }
281         }
282
283         if(num_nearest == 0)
284                 return world;
285
286         dprint("Not seeing any location point, using nearest as fallback.\n");
287         /* DEBUGGING CODE:
288         dprint("Candidates were: ");
289         for(j = 0; j < num_nearest; ++j)
290         {
291                 if(j != 0)
292                         dprint(", ");
293                 dprint(nearest_entity[j].netname);
294         }
295         dprint("\n");
296         */
297
298         return nearest_entity[0];
299 }
300
301 void() target_location =
302 {
303         self.classname = "target_location";
304         // location name in netname
305         // eventually support: count, teamgame selectors, line of sight?
306 };
307
308 void() info_location =
309 {
310         self.classname = "target_location";
311         self.message = self.netname;
312 };
313
314 string NearestLocation(vector p)
315 {
316         entity loc;
317         string ret;
318         ret = "somewhere";
319         loc = findnearest(p, classname, "target_location", '1 1 1');
320         if(loc)
321         {
322                 ret = loc.message;
323         }
324         else
325         {
326                 loc = findnearest(p, target, "###item###", '1 1 4');
327                 if(loc)
328                         ret = loc.netname;
329         }
330         return ret;
331 }
332
333 string(string msg) formatmessage =
334 {
335         float p;
336         float n;
337         string msg_save;
338         string escape;
339         string replacement;
340         msg_save = strzone(msg);
341         p = 0;
342         n = 7;
343         while(1)
344         {
345                 if(n < 1)
346                         break; // too many replacements
347                 n = n - 1;
348                 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
349                 if(p < 0)
350                         break;
351                 replacement = substring(msg_save, p, 2);
352                 escape = substring(msg_save, p + 1, 1);
353                 if(escape == "%")
354                         replacement = "%";
355                 else if(escape == "a")
356                         replacement = ftos(floor(self.armorvalue));
357                 else if(escape == "h")
358                         replacement = ftos(floor(self.health));
359                 else if(escape == "l")
360                         replacement = NearestLocation(self.origin);
361                 else if(escape == "y")
362                         replacement = NearestLocation(self.cursor_trace_endpos);
363                 else if(escape == "d")
364                         replacement = NearestLocation(self.death_origin);
365                 else if(escape == "w")
366                 {
367                         float wep;
368                         wep = self.weapon;
369                         if(!wep)
370                                 wep = self.switchweapon;
371                         if(!wep)
372                                 wep = self.cnt;
373                         replacement = W_Name(wep);
374                 }
375                 else if(escape == "W")
376                 {
377                         if(self.items & IT_SHELLS) replacement = "shells";
378                         else if(self.items & IT_NAILS) replacement = "bullets";
379                         else if(self.items & IT_ROCKETS) replacement = "rockets";
380                         else if(self.items & IT_CELLS) replacement = "cells";
381                         else replacement = "batteries"; // ;)
382                 }
383                 else if(escape == "x")
384                 {
385                         replacement = self.cursor_trace_ent.netname;
386                         if(!replacement || !self.cursor_trace_ent)
387                                 replacement = "nothing";
388                 }
389                 else if(escape == "p")
390                 {
391                         if(self.last_selected_player)
392                                 replacement = self.last_selected_player.netname;
393                         else
394                                 replacement = "(nobody)";
395                 }
396                 msg = strcat(substring(msg_save, 0, p), replacement);
397                 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
398                 strunzone(msg_save);
399                 msg_save = strzone(msg);
400                 p = p + 2;
401         }
402         msg = strcat(msg_save, "");
403         strunzone(msg_save);
404         return msg;
405 }
406
407 /*
408 =============
409 GetCvars
410 =============
411 Called with:
412   0:  sends the request
413   >0: receives a cvar from name=argv(f) value=argv(f+1)
414 */
415 void GetCvars_handleString(float f, .string field, string name)
416 {
417         if(f < 0)
418         {
419                 if(self.field)
420                         strunzone(self.field);
421         }
422         else if(f > 0)
423         {
424                 if(argv(f) == name)
425                 {
426                         if(self.field)
427                                 strunzone(self.field);
428                         self.field = strzone(argv(f + 1));
429                 }
430         }
431         else
432                 stuffcmd(self, strcat("sendcvar ", name, "\n"));
433 }
434 void GetCvars_handleFloat(float f, .float field, string name)
435 {
436         if(f < 0)
437         {
438         }
439         else if(f > 0)
440         {
441                 if(argv(f) == name)
442                         self.field = stof(argv(f + 1));
443         }
444         else
445                 stuffcmd(self, strcat("sendcvar ", name, "\n"));
446 }
447 void GetCvars(float f)
448 {
449         GetCvars_handleFloat(f, autoswitch, "cl_autoswitch");
450         GetCvars_handleFloat(f, cvar_cl_hidewaypoints, "cl_hidewaypoints");
451         GetCvars_handleFloat(f, cvar_cl_zoomfactor, "cl_zoomfactor");
452         GetCvars_handleFloat(f, cvar_cl_zoomspeed, "cl_zoomspeed");
453         GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
454         GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
455         GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
456         GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
457         GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
458         GetCvars_handleFloat(f, cvar_cl_handicap, "cl_handicap");
459 }
460
461 float fexists(string f)
462 {
463         float fh;
464         fh = fopen(f, FILE_READ);
465         if(fh < 0)
466                 return FALSE;
467         fclose(fh);
468         return TRUE;
469 }
470
471 void backtrace(string msg)
472 {
473         float dev;
474         dev = cvar("developer");
475         cvar_set("developer", "1");
476         dprint("\n");
477         dprint("--- CUT HERE ---\nWARNING: ");
478         dprint(msg);
479         dprint("\n");
480         remove(world); // isn't there any better way to cause a backtrace?
481         dprint("\n--- CUT UNTIL HERE ---\n");
482         cvar_set("developer", ftos(dev));
483 }
484
485 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
486 {
487         float nTeam;
488         entity head;
489         float f;
490
491         if(!teams_matter)
492                 return;
493
494         //if(p.frags < 0)
495         //{
496         //      p.frags = 0; // do not harm the new team!
497         //      return; // won't distribute negative scores
498         //}
499
500         if(p.frags == -666)
501                 return;
502
503         f = ceil(factor * p.frags);
504         p.frags = p.frags - f;
505
506         nTeam = 0;
507         FOR_EACH_PLAYER(head)
508                 if(head != p)
509                         if(head.team == targetteam)
510                                 nTeam = nTeam + 1;
511
512         if(nTeam == 0)
513                 return;
514
515         DistributeEvenly_Init(f, nTeam);
516
517         FOR_EACH_PLAYER(head)
518                 if(head != p)
519                         if(head.team == targetteam)
520                                 head.frags = head.frags + DistributeEvenly_Get(1);
521 }
522
523 string Team_ColorCode(float teamid)
524 {
525         if(teamid == COLOR_TEAM1)
526                 return "^1";
527         else if(teamid == COLOR_TEAM2)
528                 return "^4";
529         else if(teamid == COLOR_TEAM3)
530                 return "^3";
531         else if(teamid == COLOR_TEAM4)
532                 return "^6";
533         else
534                 return "^7";
535 }
536
537 /*
538 string decolorize(string s)
539 {
540         string out;
541         out = "";
542         while(s != "")
543         {
544                 float n;
545                 string ch1, ch2;
546                 n = 1;
547                 ch1 = substring(s, 0, 1);
548                 ch2 = substring(s, 1, 1);
549                 if(ch1 == "^")
550                 {
551                         n = 2;
552                         if(ch2 == "^")
553                                 out = strcat(out, "^^");
554                         else if(ch2 == "0")
555                                 out = strcat1(out);
556                         else if(ch2 == "1")
557                                 out = strcat1(out);
558                         else if(ch2 == "2")
559                                 out = strcat1(out);
560                         else if(ch2 == "3")
561                                 out = strcat1(out);
562                         else if(ch2 == "4")
563                                 out = strcat1(out);
564                         else if(ch2 == "5")
565                                 out = strcat1(out);
566                         else if(ch2 == "6")
567                                 out = strcat1(out);
568                         else if(ch2 == "7")
569                                 out = strcat1(out);
570                         else if(ch2 == "8")
571                                 out = strcat1(out);
572                         else if(ch2 == "9")
573                                 out = strcat1(out);
574                         else
575                         {
576                                 n = 1;
577                                 out = strcat(out, "^^");
578                         }
579                         s = substring(s, n, strlen(s) - n);
580                 }
581                 else
582                 {
583                         s = substring(s, 1, strlen(s) - 1);
584                         out = strcat(out, ch1);
585                 }
586         }
587         return out;
588 }
589 #define strdecolorize(s) decolorize(s)
590 #define strlennocol(s) strlen(decolorize(s))
591 */
592
593 #define CENTERPRIO_POINT 1
594 #define CENTERPRIO_SPAM 2
595 #define CENTERPRIO_REBALANCE 2
596 #define CENTERPRIO_VOTE 4
597 #define CENTERPRIO_NORMAL 5
598 #define CENTERPRIO_MAPVOTE 9
599 #define CENTERPRIO_ADMIN 99
600 .float centerprint_priority;
601 .float centerprint_expires;
602 void centerprint_atprio(entity e, float prio, string s)
603 {
604         if(intermission_running)
605                 if(prio < CENTERPRIO_MAPVOTE)
606                         return;
607         if(time > e.centerprint_expires)
608                 e.centerprint_priority = 0;
609         if(prio >= e.centerprint_priority)
610         {
611                 e.centerprint_priority = prio;
612                 e.centerprint_expires = time + e.cvar_scr_centertime;
613                 centerprint_builtin(e, s);
614         }
615 }
616 void centerprint_expire(entity e, float prio)
617 {
618         if(prio == e.centerprint_priority)
619         {
620                 e.centerprint_priority = 0;
621                 centerprint_builtin(e, "");
622         }
623 }
624 void centerprint(entity e, string s)
625 {
626         centerprint_atprio(e, CENTERPRIO_NORMAL, s);
627 }
628
629 void VoteNag();
630
631 // decolorizes and team colors the player name when needed
632 string playername(entity p)
633 {
634         string t;
635         if(teams_matter && !intermission_running && p.classname == "player")
636         {
637                 t = Team_ColorCode(p.team);
638                 return strcat(t, strdecolorize(p.netname));
639         }
640         else
641                 return p.netname;
642 }
643
644 vector(vector m1, vector m2) randompos =
645 {
646         local vector v;
647         m2 = m2 - m1;
648         v_x = m2_x * random() + m1_x;
649         v_y = m2_y * random() + m1_y;
650         v_z = m2_z * random() + m1_z;
651         return  v;
652 };
653
654 // requires that m2>m1 in all coordinates, and that m4>m3
655 float(vector m1, vector m2, vector m3, vector m4) boxesoverlap = {return m2_x >= m3_x && m1_x <= m4_x && m2_y >= m3_y && m1_y <= m4_y && m2_z >= m3_z && m1_z <= m4_z;};
656
657 // requires the same, but is a stronger condition
658 float(vector smins, vector smaxs, vector bmins, vector bmaxs) boxinsidebox = {return smins_x >= bmins_x && smaxs_x <= bmaxs_x && smins_y >= bmins_y && smaxs_y <= bmaxs_y && smins_z >= bmins_z && smaxs_z <= bmaxs_z;};
659
660 float g_pickup_shells;
661 float g_pickup_shells_max;
662 float g_pickup_nails;
663 float g_pickup_nails_max;
664 float g_pickup_rockets;
665 float g_pickup_rockets_max;
666 float g_pickup_cells;
667 float g_pickup_cells_max;
668 float g_pickup_armorshard;
669 float g_pickup_armorshard_max;
670 float g_pickup_armor;
671 float g_pickup_armor_max;
672 float g_pickup_healthshard;
673 float g_pickup_healthshard_max;
674 float g_pickup_health;
675 float g_pickup_health_max;
676 float g_pickup_healthmega;
677 float g_pickup_healthmega_max;
678
679 float start_items;
680 float start_switchweapon;
681 float start_ammo_shells;
682 float start_ammo_nails;
683 float start_ammo_rockets;
684 float start_ammo_cells;
685 float start_health;
686 float start_armorvalue;
687
688 void readlevelcvars(void)
689 {
690         g_pickup_shells                    = cvar("g_pickup_shells");
691         g_pickup_shells_max                = cvar("g_pickup_shells_max");
692         g_pickup_nails                     = cvar("g_pickup_nails");
693         g_pickup_nails_max                 = cvar("g_pickup_nails_max");
694         g_pickup_rockets                   = cvar("g_pickup_rockets");
695         g_pickup_rockets_max               = cvar("g_pickup_rockets_max");
696         g_pickup_cells                     = cvar("g_pickup_cells");
697         g_pickup_cells_max                 = cvar("g_pickup_cells_max");
698         g_pickup_armorshard                = cvar("g_pickup_armorshard");
699         g_pickup_armorshard_max            = cvar("g_pickup_armorshard_max");
700         g_pickup_armor                     = cvar("g_pickup_armor");
701         g_pickup_armor_max                 = cvar("g_pickup_armor_max");
702         g_pickup_healthshard               = cvar("g_pickup_healthshard");
703         g_pickup_healthshard_max           = cvar("g_pickup_healthshard_max");
704         g_pickup_health                    = cvar("g_pickup_health");
705         g_pickup_health_max                = cvar("g_pickup_health_max");
706         g_pickup_healthmega                = cvar("g_pickup_healthmega");
707         g_pickup_healthmega_max            = cvar("g_pickup_healthmega_max");
708
709         // initialize starting values for players
710         start_items = 0;
711         start_switchweapon = 0;
712         start_ammo_shells = 0;
713         start_ammo_nails = 0;
714         start_ammo_rockets = 0;
715         start_ammo_cells = 0;
716         start_health = cvar("g_balance_health_start");
717         start_armorvalue = cvar("g_balance_armor_start");
718
719         if(cvar("g_instagib"))
720         {
721                 start_items = IT_NEX;
722                 start_switchweapon = WEP_NEX;
723                 weapon_action(start_switchweapon, WR_PRECACHE);
724                 start_ammo_cells = 999;
725         }
726         else if(cvar("g_rocketarena"))
727         {
728                 start_items = IT_ROCKET_LAUNCHER;
729                 start_switchweapon = WEP_ROCKET_LAUNCHER;
730                 weapon_action(start_switchweapon, WR_PRECACHE);
731                 start_ammo_rockets = 999;
732         }
733         else if(cvar("g_nixnex"))
734         {
735                 start_items = 0;
736                 // will be done later
737         }
738         else if(cvar("g_minstagib"))
739         {
740                 start_health = 100;
741                 start_armorvalue = 0;
742                 start_items = IT_NEX;
743                 start_switchweapon = WEP_NEX;
744                 weapon_action(start_switchweapon, WR_PRECACHE);
745                 start_ammo_cells = cvar("g_minstagib_ammo_start");
746         }
747         else
748         {
749                 if(cvar("g_lms"))
750                 {
751                         start_ammo_shells = cvar("g_lms_start_ammo_shells");
752                         start_ammo_nails = cvar("g_lms_start_ammo_nails");
753                         start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
754                         start_ammo_cells = cvar("g_lms_start_ammo_cells");
755                         start_health = cvar("g_lms_start_health");
756                         start_armorvalue = cvar("g_lms_start_armor");
757                 }
758                 else if (cvar("g_use_ammunition")) {
759                         start_ammo_shells = cvar("g_start_ammo_shells");
760                         start_ammo_nails = cvar("g_start_ammo_nails");
761                         start_ammo_rockets = cvar("g_start_ammo_rockets");
762                         start_ammo_cells = cvar("g_start_ammo_cells");
763                 } else {
764                         start_ammo_shells = cvar("g_pickup_shells_max");
765                         start_ammo_nails = cvar("g_pickup_nails_max");
766                         start_ammo_rockets = cvar("g_pickup_rockets_max");
767                         start_ammo_cells = cvar("g_pickup_cells_max");
768                 }
769
770                 if (cvar("g_start_weapon_laser") || cvar("g_lms"))
771                 {
772                         start_items = start_items | IT_LASER;
773                         start_switchweapon = WEP_LASER;
774                         weapon_action(start_switchweapon, WR_PRECACHE);
775                 }
776                 if (cvar("g_start_weapon_shotgun") || cvar("g_lms"))
777                 {
778                         start_items = start_items | IT_SHOTGUN;
779                         start_switchweapon = WEP_SHOTGUN;
780                         weapon_action(start_switchweapon, WR_PRECACHE);
781                 }
782                 if (cvar("g_start_weapon_uzi") || cvar("g_lms"))
783                 {
784                         start_items = start_items | IT_UZI;
785                         start_switchweapon = WEP_UZI;
786                         weapon_action(start_switchweapon, WR_PRECACHE);
787                 }
788                 if (cvar("g_start_weapon_grenadelauncher") || cvar("g_lms"))
789                 {
790                         start_items = start_items | IT_GRENADE_LAUNCHER;
791                         start_switchweapon = WEP_GRENADE_LAUNCHER;
792                         weapon_action(start_switchweapon, WR_PRECACHE);
793                 }
794                 if (cvar("g_start_weapon_electro") || cvar("g_lms"))
795                 {
796                         start_items = start_items | IT_ELECTRO;
797                         start_switchweapon = WEP_ELECTRO;
798                         weapon_action(start_switchweapon, WR_PRECACHE);
799                 }
800                 if (cvar("g_start_weapon_crylink") || cvar("g_lms"))
801                 {
802                         start_items = start_items | IT_CRYLINK;
803                         start_switchweapon = WEP_CRYLINK;
804                         weapon_action(start_switchweapon, WR_PRECACHE);
805                 }
806                 if (cvar("g_start_weapon_nex") || cvar("g_lms"))
807                 {
808                         start_items = start_items | IT_NEX;
809                         start_switchweapon = WEP_NEX;
810                         weapon_action(start_switchweapon, WR_PRECACHE);
811                 }
812                 if (cvar("g_start_weapon_hagar") || cvar("g_lms"))
813                 {
814                         start_items = start_items | IT_HAGAR;
815                         start_switchweapon = WEP_HAGAR;
816                         weapon_action(start_switchweapon, WR_PRECACHE);
817                 }
818                 if (cvar("g_start_weapon_rocketlauncher") || cvar("g_lms"))
819                 {
820                         start_items = start_items | IT_ROCKET_LAUNCHER;
821                         start_switchweapon = WEP_ROCKET_LAUNCHER;
822                         weapon_action(start_switchweapon, WR_PRECACHE);
823                 }
824         }
825 }
826
827 /*
828 // TODO sound pack system
829 string soundpack;
830
831 string precache_sound_builtin (string s) = #19;
832 void(entity e, float chan, string samp, float vol, float atten) sound_builtin = #8;
833 string precache_sound(string s)
834 {
835         return precache_sound_builtin(strcat(soundpack, s));
836 }
837 void play2(entity e, string filename)
838 {
839         stuffcmd(e, strcat("play2 ", soundpack, filename, "\n"));
840 }
841 void sound(entity e, float chan, string samp, float vol, float atten)
842 {
843         sound_builtin(e, chan, strcat(soundpack, samp), vol, atten);
844 }
845 */
846
847 string precache_sound (string s) = #19;
848 void(entity e, float chan, string samp, float vol, float atten) sound = #8;
849 void play2(entity e, string filename)
850 {
851         stuffcmd(e, strcat("play2 ", filename, "\n"));
852 }
853
854 void play2team(float t, string filename)
855 {
856         local entity head;
857         FOR_EACH_REALPLAYER(head)
858         {
859                 if (head.team == t)
860                         play2(head, filename);
861         }
862 }