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 string linewrap(string s, float l)
94 t = strcat(t, substring(s, 0, l), "\n");
95 s = substring(s, l+1, strlen(s));
100 vector find_floor(vector org)
102 traceline(org + '0 0 5', org - '0 0 255', TRUE, self);
103 if (trace_fraction < 1)
109 void relocate_spawnpoint()
114 error_msg = "spawn point too close to a wall";
116 org = find_floor(self.origin) + '0 0 30';
118 traceline(org, org - '18 0 0', TRUE, world);
119 if(trace_fraction < 1)
122 traceline(loc, loc + '36 0 0', TRUE, world);
123 if(trace_fraction >= 1 && !self.noalign)
124 org = loc + '18 0 0';
132 traceline (org, org - '-18 0 0', TRUE, world);
133 if (trace_fraction < 1)
136 traceline (loc, loc + '-36 0 0', TRUE, world);
137 if(trace_fraction >= 1 && !self.noalign)
138 org = loc + '-18 0 0';
146 traceline (org, org - '0 18 0' , TRUE, world);
147 if (trace_fraction < 1)
150 traceline (loc, loc + '0 36 0', TRUE, world);
151 if(trace_fraction >= 1 && !self.noalign)
152 org = loc + '0 18 0';
160 traceline (org, org - '0 -18 0', TRUE, world);
161 if (trace_fraction < 1)
164 traceline (loc, loc + '0 -36 0', TRUE, world);
165 if(trace_fraction >= 1 && !self.noalign)
166 org = loc + '0 -18 0';
175 setorigin(self, org);
178 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
179 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
180 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
181 // BE CONSTANT OR strzoneD!
182 float(string haystack, string needle, float offset) strstr =
186 len = strlen(needle);
187 endpos = strlen(haystack) - len;
188 while(offset < endpos)
190 found = substring(haystack, offset, len);
198 float NUM_NEAREST_ENTITIES = 4;
199 entity nearest_entity[NUM_NEAREST_ENTITIES];
200 float nearest_length[NUM_NEAREST_ENTITIES];
201 entity(vector point, .string field, string value, vector axismod) findnearest =
212 localhead = find(world, field, value);
215 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
216 dist = localhead.oldorigin;
218 dist = localhead.origin;
220 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
223 for(i = 0; i < num_nearest; ++i)
225 if(len < nearest_length[i])
229 // now i tells us where to insert at
230 // INSERTION SORT! YOU'VE SEEN IT! RUN!
231 if(i < NUM_NEAREST_ENTITIES)
233 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
235 nearest_length[j + 1] = nearest_length[j];
236 nearest_entity[j + 1] = nearest_entity[j];
238 nearest_length[i] = len;
239 nearest_entity[i] = localhead;
240 if(num_nearest < NUM_NEAREST_ENTITIES)
241 num_nearest = num_nearest + 1;
244 localhead = find(localhead, field, value);
247 // now use the first one from our list that we can see
248 for(i = 0; i < num_nearest; ++i)
250 traceline(point, nearest_entity[i].origin, TRUE, world);
251 if(trace_fraction == 1)
255 dprint("Nearest point (");
256 dprint(nearest_entity[0].netname);
257 dprint(") is not visible, using a visible one.\n");
259 return nearest_entity[i];
266 dprint("Not seeing any location point, using nearest as fallback.\n");
268 dprint("Candidates were: ");
269 for(j = 0; j < num_nearest; ++j)
273 dprint(nearest_entity[j].netname);
278 return nearest_entity[0];
281 void() target_location =
283 self.classname = "target_location";
284 // location name in netname
285 // eventually support: count, teamgame selectors, line of sight?
288 void() info_location =
290 self.classname = "target_location";
291 self.message = self.netname;
294 string NearestLocation(vector p)
299 loc = findnearest(p, classname, "target_location", '1 1 1');
306 loc = findnearest(p, target, "###item###", '1 1 4');
313 string(string msg) formatmessage =
320 msg_save = strzone(msg);
326 break; // too many replacements
328 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
331 replacement = substring(msg_save, p, 2);
332 escape = substring(msg_save, p + 1, 1);
335 else if(escape == "a")
336 replacement = ftos(floor(self.armorvalue));
337 else if(escape == "h")
338 replacement = ftos(floor(self.health));
339 else if(escape == "l")
340 replacement = NearestLocation(self.origin);
341 else if(escape == "y")
342 replacement = NearestLocation(self.cursor_trace_endpos);
343 else if(escape == "d")
344 replacement = NearestLocation(self.death_origin);
345 else if(escape == "w")
350 wep = self.switchweapon;
353 replacement = W_Name(wep);
355 else if(escape == "W")
357 if(self.items & IT_SHELLS) replacement = "shells";
358 else if(self.items & IT_NAILS) replacement = "bullets";
359 else if(self.items & IT_ROCKETS) replacement = "rockets";
360 else if(self.items & IT_CELLS) replacement = "cells";
361 else replacement = "batteries"; // ;)
363 else if(escape == "x")
365 replacement = self.cursor_trace_ent.netname;
366 if(!replacement || !self.cursor_trace_ent)
367 replacement = "nothing";
369 msg = strcat(substring(msg_save, 0, p), replacement);
370 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
372 msg_save = strzone(msg);
375 msg = strcat(msg_save);
386 >0: receives a cvar from name=argv(f) value=argv(f+1)
388 void GetCvars_handleString(float f, .string field, string name)
393 self.field = argv(f + 1);
396 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
398 void GetCvars_handleFloat(float f, .float field, string name)
403 self.field = stof(argv(f + 1));
406 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
408 void GetCvars(float f)
410 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");