21#define PROGS_TIME time
27var
bool autocvar_g_logTimestamps =
false;
32typedef float musictrack_t;
42#define LOGLEVEL_DEFAULT LOGLEVEL_WARNINGS
43var logLevel_t autocvar_g_logLevel = LOGLEVEL_DEFAULT;
45#define printf(...) print(sprintf(__VA_ARGS__))
46#define conprintf(...) localcmd(sprintf(__VA_ARGS__))
57imageToConsole(
string imageName,
int imgSize,
string toolTip)
59 return sprintf(
"^[\\img\\%s\\s\\%i\\tip\\%s^]", imageName, imgSize, toolTip);
62#define CG_LOG imageToConsole("gfx/icon16/monitor", ICN_SIZE, "Client Game Log")
63#define CG_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Client Game Warning")
64#define CG_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Client Game Error")
66#define SV_LOG imageToConsole("gfx/icon16/server", ICN_SIZE, "Server Game Log")
67#define SV_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Server Game Warning")
68#define SV_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Server Game Error")
70#define UI_LOG imageToConsole("gfx/icon16/picture", ICN_SIZE, "Menu Game Log")
71#define UI_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Menu Game Warning")
72#define UI_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Menu Game Error")
74#define RULE_LOG imageToConsole("gfx/icon16/script_go", ICN_SIZE, "RuleC Log")
75#define RULE_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "RuleC Warning")
76#define RULE_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "RuleC Error")
78#define MAP_LOG imageToConsole("gfx/icon16/map_go", ICN_SIZE, "MapC Log")
79#define MAP_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "MapC Warning")
80#define MAP_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "MapC Error")
82#define HUD_LOG imageToConsole("gfx/icon16/monitor_go", ICN_SIZE, "HudC Log")
83#define HUD_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "HudC Warning")
84#define HUD_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "HudC Error")
86#define ADDON_LOG imageToConsole("gfx/icon16/plugin_go", ICN_SIZE, "AddonC Log")
87#define ADDON_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "AddonC Warning")
88#define ADDON_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "AddonC Error")
94 if (autocvar_g_logTimestamps)
95 print(sprintf(
"%s ^9%f ^7%s\n", CG_LOG, PROGS_TIME, msg));
97 print(sprintf(
"%s ^7%s\n", CG_LOG, msg));
100 if (autocvar_g_logTimestamps)
101 print(sprintf(
"%s ^9%f ^7%s\n", SV_LOG, PROGS_TIME, msg));
103 print(sprintf(
"%s ^7%s\n", SV_LOG, msg));
106 if (autocvar_g_logTimestamps)
107 print(sprintf(
"%s ^9%f ^7%s\n", UI_LOG, PROGS_TIME, msg));
109 print(sprintf(
"%s ^7%s\n", UI_LOG, msg));
112 if (autocvar_g_logTimestamps)
113 print(sprintf(
"%s ^9%f ^7%s\n", RULE_LOG, PROGS_TIME, msg));
115 print(sprintf(
"%s ^7%s\n", RULE_LOG, msg));
118 if (autocvar_g_logTimestamps)
119 print(sprintf(
"%s ^9%f ^7%s\n", MAP_LOG, PROGS_TIME, msg));
121 print(sprintf(
"%s ^7%s\n", MAP_LOG, msg));
124 if (autocvar_g_logTimestamps)
125 print(sprintf(
"%s ^9%f ^7%s\n", HUD_LOG, PROGS_TIME, msg));
127 print(sprintf(
"%s ^7%s\n", HUD_LOG, msg));
130 if (autocvar_g_logTimestamps)
131 print(sprintf(
"%s ^9%f ^7%s\n", ADDON_LOG, PROGS_TIME, msg));
133 print(sprintf(
"%s ^7%s\n", ADDON_LOG, msg));
138_ncError(
string functionName,
string msg)
141 if (autocvar_g_logTimestamps)
142 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", CG_ERROR, PROGS_TIME, functionName, msg));
144 print(sprintf(
"%s ^1%s^1: %s\n", CG_ERROR, functionName, msg));
147 if (autocvar_g_logTimestamps)
148 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", SV_ERROR, PROGS_TIME, functionName, msg));
150 print(sprintf(
"%s ^1%s^1: %s\n", SV_ERROR, functionName, msg));
153 if (autocvar_g_logTimestamps)
154 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", UI_ERROR, PROGS_TIME, functionName, msg));
156 print(sprintf(
"%s ^1%s^1: %s\n", UI_ERROR, functionName, msg));
159 if (autocvar_g_logTimestamps)
160 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", RULE_ERROR, PROGS_TIME, functionName, msg));
162 print(sprintf(
"%s ^1%s^1: %s\n", RULE_ERROR, functionName, msg));
165 if (autocvar_g_logTimestamps)
166 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", MAP_ERROR, PROGS_TIME, functionName, msg));
168 print(sprintf(
"%s ^1%s^1: %s\n", MAP_ERROR, functionName, msg));
171 if (autocvar_g_logTimestamps)
172 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", HUD_ERROR, PROGS_TIME, functionName, msg));
174 print(sprintf(
"%s ^1%s^1: %s\n", HUD_ERROR, functionName, msg));
177 if (autocvar_g_logTimestamps)
178 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", ADDON_ERROR, PROGS_TIME, functionName, msg));
180 print(sprintf(
"%s ^1%s^1: %s\n", ADDON_ERROR, functionName, msg));
185_ncWarning(
string functionName,
string msg)
188 if (autocvar_g_logTimestamps)
189 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", CG_WARNING, PROGS_TIME, functionName, msg));
191 print(sprintf(
"%s ^3%s^1: %s\n", CG_WARNING, functionName, msg));
194 if (autocvar_g_logTimestamps)
195 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", SV_WARNING, PROGS_TIME, functionName, msg));
197 print(sprintf(
"%s ^3%s^1: %s\n", SV_WARNING, functionName, msg));
200 if (autocvar_g_logTimestamps)
201 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", UI_WARNING, PROGS_TIME, functionName, msg));
203 print(sprintf(
"%s ^3%s^1: %s\n", UI_WARNING, functionName, msg));
206 if (autocvar_g_logTimestamps)
207 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", RULE_WARNING, PROGS_TIME, functionName, msg));
209 print(sprintf(
"%s ^3%s^1: %s\n", RULE_WARNING, functionName, msg));
212 if (autocvar_g_logTimestamps)
213 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", MAP_WARNING, PROGS_TIME, functionName, msg));
215 print(sprintf(
"%s ^3%s^1: %s\n", MAP_WARNING, functionName, msg));
218 if (autocvar_g_logTimestamps)
219 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", HUD_WARNING, PROGS_TIME, functionName, msg));
221 print(sprintf(
"%s ^3%s^1: %s\n", HUD_WARNING, functionName, msg));
224 if (autocvar_g_logTimestamps)
225 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", ADDON_WARNING, PROGS_TIME, functionName, msg));
227 print(sprintf(
"%s ^3%s^1: %s\n", ADDON_WARNING, functionName, msg));
232_NSAssert(
bool condition,
string function,
string descr)
236 print(strcat(CG_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
242 print(strcat(SV_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
248 print(strcat(UI_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
253 print(strcat(RULE_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
258 print(strcat(MAP_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
263 print(strcat(HUD_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
268 print(strcat(ADDON_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
277#define ncLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _ncLog(sprintf(__VA_ARGS__))
282#define ncLogAlways(...) _ncLog(sprintf(__VA_ARGS__))
288#define ncError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _ncError(__FUNC__, sprintf(__VA_ARGS__))
294#define ncWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _ncWarning(__FUNC__, sprintf(__VA_ARGS__))
301#define NSAssert(condition, ...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
313const entity g_entity_null = __NULL__;
314const float g_float_null = 0.0f;
315const int g_int_null = 0i;
316const string g_string_null =
"";
317const vector g_vec_null = [0.0f, 0.0f, 0.0f];
320InitPrint(
string functionName)
322 static int chars = 51i;
325 string sideLeft =
"";
326 string sideRight =
"";
328 if (functionName == __NULL__) {
329 ncLogAlways(
"---------------------------------------------------");
334 chars = chars - (int)strlen(functionName) - 2i;
335 charsLeft = chars / 2i;
336 charExtra = chars % 2i;
338 for (
int i = 0i; i < charsLeft; i++)
339 sideLeft = strcat(sideLeft,
"-");
341 for (
int i = 0i; i < (charsLeft + charExtra); i++) {
342 sideRight = strcat(sideRight,
"-");
345 ncLogAlways(
"%s %s %s", sideLeft, functionName, sideRight);
348#define InitStart() float local_initTime = gettime(1); InitPrint(__FUNC__)
351_InitEnd(
float oldTime,
string functionName)
353 float endTime = gettime(1);
354 ncLogAlways(
"%s loaded in %.1f seconds", functionName, (endTime - oldTime));
355 ncLogAlways(
"---------------------------------------------------");
358#define InitEnd() _InitEnd(local_initTime, __FUNC__)
361#define entity_def(x, ...) const string x[] = { __VA_ARGS__ }
364#define thread(x) if (fork()) { x; abort(); }
366#define STRING_SET(x) ((x != __NULL__) && (x != ""))
369fileExists(
string filePath)
371 if (!STRING_SET(filePath)) {
376 if not(whichpack(filePath)) {
385fileExtensionFromString(
string inputString)
387 int modelNameLength = strlen(inputString);
390 for (
int i = (modelNameLength - 1); i > 0; i--) {
391 if (str2chr(inputString, i) ==
'.') {
398 return substring(inputString, dotChar + 1, -1);
404#define Util_ExtensionFromString fileExtensionFromString
407wordInString(
string fullString,
string wordToFind)
409 int wordCount = tokenize(fullString);
411 for (
int i = 0; i < wordCount; i++) {
412 if (wordToFind == argv(i)) {
424 return ((random() - 0.5f) * 2.0f);
428basename(
string input)
434 int c = tokenizebyseparator(input,
"/",
"\\ ",
"!");
445 int c = tokenizebyseparator(input,
"/",
"\\ ",
"!");
448 for (
int i = 0; i < (c-1); i++) {
449 newpath = sprintf(
"%s/%s", newpath, argv(i));
453 newpath = substring(newpath, 1, strlen(newpath)-1);
460skimFile(
string filename)
462 filestream fs_mapcycle;
468 fs_mapcycle = fopen(filename, FILE_READ);
470 if (fs_mapcycle < 0) {
471 ncError(
"Missing file %s", filename);
476 while ((temp = fgets(fs_mapcycle))) {
477 tokenize_console(temp);
478 string mapName = argv(0);
480 if (STRING_SET(mapName)) {
490CallSpawnfuncByName(entity target,
string className)
492 entity oldSelf = self;
493 string spawnClass = strcat(
"spawnfunc_", className);
495 callfunction(spawnClass);
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37