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