1 string W_Name(float weaponid);
2 float(float index) weapon_translateindextoflag;
7 void(string s) bcenterprint
10 head = find(world, classname, "player");
13 if(clienttype(head) == CLIENTTYPE_REAL)
15 head = find(head, classname, "player");
19 void(string s, float check_dangerous) ServerConsoleEcho =
27 ch = substring(s, 0, 1);
28 if(ch != "\"" && ch != "\r" && ch != "\n")
30 s = substring(s, 1, strlen(s) - 1);
40 void(string s, float check_dangerous) GameLogEcho =
45 if(cvar("sv_eventlog_files"))
50 matches = cvar("sv_eventlog_files_counter") + 1;
51 cvar_set("sv_eventlog_files_counter", ftos(matches));
54 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
55 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
56 logfile = fopen(fn, FILE_APPEND);
59 fputs(logfile, strcat(s, "\n"));
61 if(cvar("sv_eventlog_console"))
63 ServerConsoleEcho(s, check_dangerous);
70 // will be opened later
75 if(logfile_open && logfile >= 0)
82 float math_mod(float a, float b)
84 return a - (floor(a / b) * b);
87 vector find_floor(vector org)
89 traceline(org + '0 0 5', org - '0 0 255', TRUE, self);
90 if (trace_fraction < 1)
96 void relocate_spawnpoint()
101 error_msg = "spawn point too close to a wall";
103 org = find_floor(self.origin) + '0 0 30';
105 traceline(org, org - '18 0 0', TRUE, world);
106 if(trace_fraction < 1)
109 traceline(loc, loc + '36 0 0', TRUE, world);
110 if(trace_fraction >= 1 && !self.noalign)
111 org = loc + '18 0 0';
119 traceline (org, org - '-18 0 0', TRUE, world);
120 if (trace_fraction < 1)
123 traceline (loc, loc + '-36 0 0', TRUE, world);
124 if(trace_fraction >= 1 && !self.noalign)
125 org = loc + '-18 0 0';
133 traceline (org, org - '0 18 0' , TRUE, world);
134 if (trace_fraction < 1)
137 traceline (loc, loc + '0 36 0', TRUE, world);
138 if(trace_fraction >= 1 && !self.noalign)
139 org = loc + '0 18 0';
147 traceline (org, org - '0 -18 0', TRUE, world);
148 if (trace_fraction < 1)
151 traceline (loc, loc + '0 -36 0', TRUE, world);
152 if(trace_fraction >= 1 && !self.noalign)
153 org = loc + '0 -18 0';
162 setorigin(self, org);
165 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
166 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
167 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
168 // BE CONSTANT OR strzoneD!
169 float(string haystack, string needle, float offset) strstr =
173 len = strlen(needle);
174 endpos = strlen(haystack) - len;
175 while(offset < endpos)
177 found = substring(haystack, offset, len);
185 float NUM_NEAREST_ENTITIES = 4;
186 entity nearest_entity[NUM_NEAREST_ENTITIES];
187 float nearest_length[NUM_NEAREST_ENTITIES];
188 entity(vector point, .string field, string value, vector axismod) findnearest =
199 localhead = find(world, field, value);
202 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
203 dist = localhead.oldorigin;
205 dist = localhead.origin;
207 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
210 for(i = 0; i < num_nearest; ++i)
212 if(len < nearest_length[i])
216 // now i tells us where to insert at
217 // INSERTION SORT! YOU'VE SEEN IT! RUN!
218 if(i < NUM_NEAREST_ENTITIES)
220 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
222 nearest_length[j + 1] = nearest_length[j];
223 nearest_entity[j + 1] = nearest_entity[j];
225 nearest_length[i] = len;
226 nearest_entity[i] = localhead;
227 if(num_nearest < NUM_NEAREST_ENTITIES)
228 num_nearest = num_nearest + 1;
231 localhead = find(localhead, field, value);
234 // now use the first one from our list that we can see
235 for(i = 0; i < num_nearest; ++i)
237 traceline(point, nearest_entity[i].origin, TRUE, world);
238 if(trace_fraction == 1)
242 dprint("Nearest point (");
243 dprint(nearest_entity[0].netname);
244 dprint(") is not visible, using a visible one.\n");
246 return nearest_entity[i];
253 dprint("Not seeing any location point, using nearest as fallback.\n");
255 dprint("Candidates were: ");
256 for(j = 0; j < num_nearest; ++j)
260 dprint(nearest_entity[j].netname);
265 return nearest_entity[0];
268 void() target_location =
270 self.classname = "target_location";
271 // location name in netname
272 // eventually support: count, teamgame selectors, line of sight?
275 void() info_location =
277 self.classname = "target_location";
278 self.message = self.netname;
281 string NearestLocation(vector p)
286 loc = findnearest(p, classname, "target_location", '1 1 1');
293 loc = findnearest(p, target, "###item###", '1 1 4');
300 string(string msg) formatmessage =
307 msg_save = strzone(msg);
313 break; // too many replacements
315 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
318 replacement = substring(msg_save, p, 2);
319 escape = substring(msg_save, p + 1, 1);
322 else if(escape == "a")
323 replacement = ftos(floor(self.armorvalue));
324 else if(escape == "h")
325 replacement = ftos(floor(self.health));
326 else if(escape == "l")
327 replacement = NearestLocation(self.origin);
328 else if(escape == "y")
329 replacement = NearestLocation(self.cursor_trace_endpos);
330 else if(escape == "d")
331 replacement = NearestLocation(self.death_origin);
332 else if(escape == "w")
337 wep = self.switchweapon;
340 replacement = W_Name(wep);
342 else if(escape == "W")
344 if(self.items & IT_SHELLS) replacement = "shells";
345 else if(self.items & IT_NAILS) replacement = "bullets";
346 else if(self.items & IT_ROCKETS) replacement = "rockets";
347 else if(self.items & IT_CELLS) replacement = "cells";
348 else replacement = "batteries"; // ;)
350 else if(escape == "x")
352 replacement = self.cursor_trace_ent.netname;
353 if(!replacement || !self.cursor_trace_ent)
354 replacement = "nothing";
356 msg = strcat(substring(msg_save, 0, p), replacement);
357 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
359 msg_save = strzone(msg);
362 msg = strcat(msg_save);
373 >0: receives a cvar from name=argv(f) value=argv(f+1)
375 void GetCvars_handleString(float f, .string field, string name)
380 self.field = argv(f + 1);
383 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
385 void GetCvars_handleFloat(float f, .float field, string name)
390 self.field = stof(argv(f + 1));
393 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
395 void GetCvars(float f)
397 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
398 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
399 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
402 float fexists(string f)
405 fh = fopen(f, FILE_READ);
412 void backtrace(string msg)
415 dev = cvar("developer");
416 cvar_set("developer", "1");
418 dprint("--- CUT HERE ---\nWARNING: ");
421 remove(world); // isn't there any better way to cause a backtrace?
422 dprint("\n--- CUT UNTIL HERE ---\n");
423 cvar_set("developer", ftos(dev));
426 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
438 // p.frags = 0; // do not harm the new team!
439 // return; // won't distribute negative scores
445 f = ceil(factor * p.frags);
446 p.frags = p.frags - f;
449 head = find(world, classname, "player");
453 if(head.team == targetteam)
455 head = find(head, classname, "player");
461 head = find(world, classname, "player");
465 if(head.team == targetteam)
467 d = floor(f / nTeam);
468 head.frags = head.frags + d;
472 head = find(head, classname, "player");
476 error("nPlayers in team changed!");
478 error(strcat("There were ", ftos(f), " frags left. BAD!"));