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)
95 t = strcat(t, substring(s, 0, l), "\n");
96 s = substring(s, l+1, strlen(s));
100 // this function seems broken (character wrap, no word wrap)
101 // use WORD wrap instead... importing it from campaign code
103 t = Campaign_wordwrap(s, l);
108 vector find_floor(vector org)
110 traceline(org + '0 0 5', org - '0 0 255', TRUE, self);
111 if (trace_fraction < 1)
117 void relocate_spawnpoint()
122 error_msg = "spawn point too close to a wall";
124 org = find_floor(self.origin) + '0 0 30';
126 traceline(org, org - '18 0 0', TRUE, world);
127 if(trace_fraction < 1)
130 traceline(loc, loc + '36 0 0', TRUE, world);
131 if(trace_fraction >= 1 && !self.noalign)
132 org = loc + '18 0 0';
140 traceline (org, org - '-18 0 0', TRUE, world);
141 if (trace_fraction < 1)
144 traceline (loc, loc + '-36 0 0', TRUE, world);
145 if(trace_fraction >= 1 && !self.noalign)
146 org = loc + '-18 0 0';
154 traceline (org, org - '0 18 0' , TRUE, world);
155 if (trace_fraction < 1)
158 traceline (loc, loc + '0 36 0', TRUE, world);
159 if(trace_fraction >= 1 && !self.noalign)
160 org = loc + '0 18 0';
168 traceline (org, org - '0 -18 0', TRUE, world);
169 if (trace_fraction < 1)
172 traceline (loc, loc + '0 -36 0', TRUE, world);
173 if(trace_fraction >= 1 && !self.noalign)
174 org = loc + '0 -18 0';
183 setorigin(self, org);
186 // NOTE: DO NOT USE THIS FUNCTION TOO OFTEN.
187 // IT WILL MOST PROBABLY DESTROY _ALL_ OTHER TEMP
188 // STRINGS AND TAKE QUITE LONG. haystack and needle MUST
189 // BE CONSTANT OR strzoneD!
190 float(string haystack, string needle, float offset) strstr =
194 len = strlen(needle);
195 endpos = strlen(haystack) - len;
196 while(offset < endpos)
198 found = substring(haystack, offset, len);
206 float NUM_NEAREST_ENTITIES = 4;
207 entity nearest_entity[NUM_NEAREST_ENTITIES];
208 float nearest_length[NUM_NEAREST_ENTITIES];
209 entity(vector point, .string field, string value, vector axismod) findnearest =
220 localhead = find(world, field, value);
223 if((localhead.items == IT_KEY1 || localhead.items == IT_KEY2) && localhead.target == "###item###")
224 dist = localhead.oldorigin;
226 dist = localhead.origin;
228 dist = dist_x * axismod_x * '1 0 0' + dist_y * axismod_y * '0 1 0' + dist_z * axismod_z * '0 0 1';
231 for(i = 0; i < num_nearest; ++i)
233 if(len < nearest_length[i])
237 // now i tells us where to insert at
238 // INSERTION SORT! YOU'VE SEEN IT! RUN!
239 if(i < NUM_NEAREST_ENTITIES)
241 for(j = NUM_NEAREST_ENTITIES - 1; j >= i; --j)
243 nearest_length[j + 1] = nearest_length[j];
244 nearest_entity[j + 1] = nearest_entity[j];
246 nearest_length[i] = len;
247 nearest_entity[i] = localhead;
248 if(num_nearest < NUM_NEAREST_ENTITIES)
249 num_nearest = num_nearest + 1;
252 localhead = find(localhead, field, value);
255 // now use the first one from our list that we can see
256 for(i = 0; i < num_nearest; ++i)
258 traceline(point, nearest_entity[i].origin, TRUE, world);
259 if(trace_fraction == 1)
263 dprint("Nearest point (");
264 dprint(nearest_entity[0].netname);
265 dprint(") is not visible, using a visible one.\n");
267 return nearest_entity[i];
274 dprint("Not seeing any location point, using nearest as fallback.\n");
276 dprint("Candidates were: ");
277 for(j = 0; j < num_nearest; ++j)
281 dprint(nearest_entity[j].netname);
286 return nearest_entity[0];
289 void() target_location =
291 self.classname = "target_location";
292 // location name in netname
293 // eventually support: count, teamgame selectors, line of sight?
296 void() info_location =
298 self.classname = "target_location";
299 self.message = self.netname;
302 string NearestLocation(vector p)
307 loc = findnearest(p, classname, "target_location", '1 1 1');
314 loc = findnearest(p, target, "###item###", '1 1 4');
321 string(string msg) formatmessage =
328 msg_save = strzone(msg);
334 break; // too many replacements
336 p = strstr(msg_save, "%", p); // NOTE: this destroys msg as it's a tempstring!
339 replacement = substring(msg_save, p, 2);
340 escape = substring(msg_save, p + 1, 1);
343 else if(escape == "a")
344 replacement = ftos(floor(self.armorvalue));
345 else if(escape == "h")
346 replacement = ftos(floor(self.health));
347 else if(escape == "l")
348 replacement = NearestLocation(self.origin);
349 else if(escape == "y")
350 replacement = NearestLocation(self.cursor_trace_endpos);
351 else if(escape == "d")
352 replacement = NearestLocation(self.death_origin);
353 else if(escape == "w")
358 wep = self.switchweapon;
361 replacement = W_Name(wep);
363 else if(escape == "W")
365 if(self.items & IT_SHELLS) replacement = "shells";
366 else if(self.items & IT_NAILS) replacement = "bullets";
367 else if(self.items & IT_ROCKETS) replacement = "rockets";
368 else if(self.items & IT_CELLS) replacement = "cells";
369 else replacement = "batteries"; // ;)
371 else if(escape == "x")
373 replacement = self.cursor_trace_ent.netname;
374 if(!replacement || !self.cursor_trace_ent)
375 replacement = "nothing";
377 msg = strcat(substring(msg_save, 0, p), replacement);
378 msg = strcat(msg, substring(msg_save, p+2, strlen(msg_save) - (p+2)));
380 msg_save = strzone(msg);
383 msg = strcat(msg_save);
394 >0: receives a cvar from name=argv(f) value=argv(f+1)
396 void GetCvars_handleString(float f, .string field, string name)
401 self.field = argv(f + 1);
404 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
406 void GetCvars_handleFloat(float f, .float field, string name)
411 self.field = stof(argv(f + 1));
414 stuffcmd(self, strcat("cmd reportcvar ", name, " $", name, "\n"));
416 void GetCvars(float f)
418 GetCvars_handleFloat(f, cvar_cl_playerdetailreduction, "cl_playerdetailreduction");
419 GetCvars_handleFloat(f, cvar_cl_nogibs, "cl_nogibs");
422 float fexists(string f)
425 fh = fopen(f, FILE_READ);