4 void(string s) bcenterprint
7 head = find(world, classname, "player");
10 if(clienttype(head) == CLIENTTYPE_REAL)
12 head = find(head, classname, "player");
16 void(string s, float check_dangerous) ServerConsoleEcho =
19 if (checkextension("DP_SV_PRINT"))
28 ch = substring(s, 0, 1);
29 if(ch != "\"" && ch != "\r" && ch != "\n")
31 s = substring(s, 1, strlen(s) - 1);
42 void(string s, float check_dangerous) GameLogEcho =
47 if(cvar("sv_eventlog_files"))
52 matches = cvar("sv_eventlog_files_counter") + 1;
53 cvar_set("sv_eventlog_files_counter", ftos(matches));
56 fn = strcat(substring("00000000", 0, 8 - strlen(fn)), fn);
57 fn = strcat(cvar_string("sv_eventlog_files_nameprefix"), fn, cvar_string("sv_eventlog_files_namesuffix"));
58 logfile = fopen(fn, FILE_APPEND);
61 fputs(logfile, strcat(s, "\n"));
63 if(cvar("sv_eventlog_console"))
65 ServerConsoleEcho(s, check_dangerous);
72 // will be opened later
77 if(logfile_open && logfile >= 0)
84 float math_mod(float a, float b)
86 return a - (floor(a / b) * b);
89 void relocate_spawnpoint()
91 // nudge off the floor
92 setorigin(self, self.origin + '0 0 1');
94 tracebox(self.origin, PL_MIN, PL_MAXS, self.origin, TRUE, self);
97 objerror("player spawn point in solid, mapper sucks!\n");
102 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
103 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
104 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
105 // BE CONSTANT OR strzoneD!
106 float(string haystack, string needle, float offset) strstr =
110 len = strlen(needle);
111 endpos = strlen(haystack) - len;
112 while(offset <= endpos)
114 found = substring(haystack, offset, len);
122 float NUM_NEAREST_ENTITIES = 4;
123 entity nearest_entity[NUM_NEAREST_ENTITIES];
124 float nearest_length[NUM_NEAREST_ENTITIES];
125 entity(vector point, .string field, string value, vector axismod) findnearest =
136 localhead = find(world, field, value);
139 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
140 dist = localhead.oldorigin;
142 dist = localhead.origin;
144 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
147 for(i = 0; i < num_nearest; ++i)
149 if(len < nearest_length[i])
153 // now i tells us where to insert at
154 // INSERTION SORT! YOU'VE SEEN IT! RUN!
155 if(i < NUM_NEAREST_ENTITIES)
157 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
159 nearest_length[j + 1] = nearest_length[j];
160 nearest_entity[j + 1] = nearest_entity[j];
162 nearest_length[i] = len;
163 nearest_entity[i] = localhead;
164 if(num_nearest < NUM_NEAREST_ENTITIES)
165 num_nearest = num_nearest + 1;
168 localhead = find(localhead, field, value);
171 // now use the first one from our list that we can see
172 for(i = 0; i < num_nearest; ++i)
174 traceline(point, nearest_entity[i].origin, TRUE, world);
175 if(trace_fraction == 1)
179 dprint("Nearest point (");
180 dprint(nearest_entity[0].netname);
181 dprint(") is not visible, using a visible one.\n");
183 return nearest_entity[i];
190 dprint("Not seeing any location point, using nearest as fallback.\n");
192 dprint("Candidates were: ");
193 for(j = 0; j < num_nearest; ++j)
197 dprint(nearest_entity[j].netname);
202 return nearest_entity[0];
205 void() target_location =
207 self.classname = "target_location";
208 // location name in netname
209 // eventually support: count, teamgame selectors, line of sight?
212 void() info_location =
214 self.classname = "target_location";
215 self.message = self.netname;
218 string NearestLocation(vector p)
223 loc = findnearest(p, classname, "target_location", '1 1 1');
230 loc = findnearest(p, target, "###item###", '1 1 4');
237 string(string msg) formatmessage =
244 msg_save = strzone(msg);
250 break; // too many replacements
252 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
255 replacement = substring(msg_save, p, 2);
256 escape = substring(msg_save, p + 1, 1);
259 else if(escape == "a")
260 replacement = ftos(floor(self.armorvalue));
261 else if(escape == "h")
262 replacement = ftos(floor(self.health));
263 else if(escape == "l")
264 replacement = NearestLocation(self.origin);
265 else if(escape == "y")
266 replacement = NearestLocation(self.cursor_trace_endpos);
267 else if(escape == "d")
268 replacement = NearestLocation(self.death_origin);
269 else if(escape == "w")
274 wep = self.switchweapon;
277 replacement = W_Name(wep);
279 else if(escape == "W")
281 if(self.items & IT_SHELLS) replacement = "shells";
282 else if(self.items & IT_NAILS) replacement = "bullets";
283 else if(self.items & IT_ROCKETS) replacement = "rockets";
284 else if(self.items & IT_CELLS) replacement = "cells";
285 else replacement = "batteries"; // ;)
287 else if(escape == "x")
289 replacement = self.cursor_trace_ent.netname;
290 if(!replacement || !self.cursor_trace_ent)
291 replacement = "nothing";
293 else if(escape == "p")
295 if(self.last_selected_player)
296 replacement = self.last_selected_player.netname;
298 replacement = "(nobody)";
300 msg = strcat(substring(msg_save, 0, p), replacement);
301 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
303 msg_save = strzone(msg);
306 msg = strcat(msg_save);
317 >0: receives a cvar from name=argv(f) value=argv(f+1)
319 void GetCvars_handleString(float f, .string field, string name)
324 strunzone(self.field);
331 strunzone(self.field);
332 self.field = strzone(argv(f + 1));
336 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
338 void GetCvars_handleFloat(float f, .float field, string name)
346 self.field = stof(argv(f + 1));
349 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
351 void GetCvars(float f)
353 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
354 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
355 GetCvars_handleFloat(f, cvar_scr_centertime, "scr_centertime");
356 GetCvars_handleFloat(f, cvar_cl_shownames, "cl_shownames");
357 GetCvars_handleString(f, cvar_g_nexuizversion, "g_nexuizversion");
360 float fexists(string f)
363 fh = fopen(f, FILE_READ);
370 void backtrace(string msg)
373 dev = cvar("developer");
374 cvar_set("developer", "1");
376 dprint("--- CUT HERE ---\nWARNING: ");
379 remove(world); // isn't there any better way to cause a backtrace?
380 dprint("\n--- CUT UNTIL HERE ---\n");
381 cvar_set("developer", ftos(dev));
384 void DistributeFragsAmongTeam(entity p, float targetteam, float factor)
396 // p.frags = 0; // do not harm the new team!
397 // return; // won't distribute negative scores
403 f = ceil(factor * p.frags);
404 p.frags = p.frags - f;
407 head = find(world, classname, "player");
411 if(head.team == targetteam)
413 head = find(head, classname, "player");
419 head = find(world, classname, "player");
423 if(head.team == targetteam)
425 d = floor(f / nTeam);
426 head.frags = head.frags + d;
430 head = find(head, classname, "player");
434 error("nPlayers in team changed!");
436 error(strcat("There were ", ftos(f), " frags left. BAD!"));
439 string Team_ColorCode(float teamid)
441 if(teamid == COLOR_TEAM1)
443 else if(teamid == COLOR_TEAM2)
445 else if(teamid == COLOR_TEAM3)
447 else if(teamid == COLOR_TEAM4)
453 string decolorize(string s)
462 ch1 = substring(s, 0, 1);
463 ch2 = substring(s, 1, 1);
468 out = strcat(out, "^^");
492 out = strcat(out, "^^");
494 s = substring(s, n, strlen(s) - n);
498 s = substring(s, 1, strlen(s) - 1);
499 out = strcat(out, ch1);
505 #define CENTERPRIO_POINT 1
506 #define CENTERPRIO_NORMAL 5
507 .float centerprint_priority;
508 .float centerprint_expires;
509 void centerprint_atprio(entity e, float prio, string s)
511 if(time > e.centerprint_expires)
512 e.centerprint_priority = 0;
513 if(prio >= e.centerprint_priority)
515 e.centerprint_priority = prio;
516 e.centerprint_expires = time + e.cvar_scr_centertime;
517 centerprint_builtin(e, s);
520 void centerprint_expire(entity e, float prio)
522 if(prio == e.centerprint_priority)
524 e.centerprint_priority = 0;
525 centerprint_builtin(e, "");
528 void centerprint(entity e, string s)
530 centerprint_atprio(e, CENTERPRIO_NORMAL, s);