21#define PROGS_TIME time
27var
bool autocvar_g_logTimestamps =
false;
30typedef float musictrack_t;
40#define LOGLEVEL_DEFAULT LOGLEVEL_WARNINGS
41var logLevel_t autocvar_g_logLevel = LOGLEVEL_DEFAULT;
43#define printf(...) print(sprintf(__VA_ARGS__))
53imageToConsole(
string imageName,
int imgSize,
string toolTip)
55 return sprintf(
"^[\\img\\%s\\s\\%i\\tip\\%s^]", imageName, imgSize, toolTip);
58#define CG_LOG imageToConsole("gfx/icon16/monitor", ICN_SIZE, "Client Game Log")
59#define CG_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Client Game Warning")
60#define CG_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Client Game Error")
62#define SV_LOG imageToConsole("gfx/icon16/server", ICN_SIZE, "Server Game Log")
63#define SV_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Server Game Warning")
64#define SV_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Server Game Error")
66#define UI_LOG imageToConsole("gfx/icon16/picture", ICN_SIZE, "Menu Game Log")
67#define UI_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "Menu Game Warning")
68#define UI_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "Menu Game Error")
70#define RULE_LOG imageToConsole("gfx/icon16/script_go", ICN_SIZE, "RuleC Log")
71#define RULE_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "RuleC Warning")
72#define RULE_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "RuleC Error")
74#define MAP_LOG imageToConsole("gfx/icon16/map_go", ICN_SIZE, "MapC Log")
75#define MAP_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "MapC Warning")
76#define MAP_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "MapC Error")
78#define HUD_LOG imageToConsole("gfx/icon16/monitor_go", ICN_SIZE, "HudC Log")
79#define HUD_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "HudC Warning")
80#define HUD_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "HudC Error")
82#define ADDON_LOG imageToConsole("gfx/icon16/plugin_go", ICN_SIZE, "AddonC Log")
83#define ADDON_WARNING imageToConsole("gfx/icon16/error", ICN_SIZE, "AddonC Warning")
84#define ADDON_ERROR imageToConsole("gfx/icon16/exclamation", ICN_SIZE, "AddonC Error")
90 if (autocvar_g_logTimestamps)
91 print(sprintf(
"%s ^9%f ^7%s\n", CG_LOG, PROGS_TIME, msg));
93 print(sprintf(
"%s ^7%s\n", CG_LOG, msg));
96 if (autocvar_g_logTimestamps)
97 print(sprintf(
"%s ^9%f ^7%s\n", SV_LOG, PROGS_TIME, msg));
99 print(sprintf(
"%s ^7%s\n", SV_LOG, msg));
102 if (autocvar_g_logTimestamps)
103 print(sprintf(
"%s ^9%f ^7%s\n", UI_LOG, PROGS_TIME, msg));
105 print(sprintf(
"%s ^7%s\n", UI_LOG, msg));
108 if (autocvar_g_logTimestamps)
109 print(sprintf(
"%s ^9%f ^7%s\n", RULE_LOG, PROGS_TIME, msg));
111 print(sprintf(
"%s ^7%s\n", RULE_LOG, msg));
114 if (autocvar_g_logTimestamps)
115 print(sprintf(
"%s ^9%f ^7%s\n", MAP_LOG, PROGS_TIME, msg));
117 print(sprintf(
"%s ^7%s\n", MAP_LOG, msg));
120 if (autocvar_g_logTimestamps)
121 print(sprintf(
"%s ^9%f ^7%s\n", HUD_LOG, PROGS_TIME, msg));
123 print(sprintf(
"%s ^7%s\n", HUD_LOG, msg));
126 if (autocvar_g_logTimestamps)
127 print(sprintf(
"%s ^9%f ^7%s\n", ADDON_LOG, PROGS_TIME, msg));
129 print(sprintf(
"%s ^7%s\n", ADDON_LOG, msg));
134_ncError(
string functionName,
string msg)
137 if (autocvar_g_logTimestamps)
138 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", CG_ERROR, PROGS_TIME, functionName, msg));
140 print(sprintf(
"%s ^1%s^1: %s\n", CG_ERROR, functionName, msg));
143 if (autocvar_g_logTimestamps)
144 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", SV_ERROR, PROGS_TIME, functionName, msg));
146 print(sprintf(
"%s ^1%s^1: %s\n", SV_ERROR, functionName, msg));
149 if (autocvar_g_logTimestamps)
150 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", UI_ERROR, PROGS_TIME, functionName, msg));
152 print(sprintf(
"%s ^1%s^1: %s\n", UI_ERROR, functionName, msg));
155 if (autocvar_g_logTimestamps)
156 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", RULE_ERROR, PROGS_TIME, functionName, msg));
158 print(sprintf(
"%s ^1%s^1: %s\n", RULE_ERROR, functionName, msg));
161 if (autocvar_g_logTimestamps)
162 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", MAP_ERROR, PROGS_TIME, functionName, msg));
164 print(sprintf(
"%s ^1%s^1: %s\n", MAP_ERROR, functionName, msg));
167 if (autocvar_g_logTimestamps)
168 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", HUD_ERROR, PROGS_TIME, functionName, msg));
170 print(sprintf(
"%s ^1%s^1: %s\n", HUD_ERROR, functionName, msg));
173 if (autocvar_g_logTimestamps)
174 print(sprintf(
"%s ^9%f ^1%s^1: %s\n", ADDON_ERROR, PROGS_TIME, functionName, msg));
176 print(sprintf(
"%s ^1%s^1: %s\n", ADDON_ERROR, functionName, msg));
181_ncWarning(
string functionName,
string msg)
184 if (autocvar_g_logTimestamps)
185 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", CG_WARNING, PROGS_TIME, functionName, msg));
187 print(sprintf(
"%s ^3%s^1: %s\n", CG_WARNING, functionName, msg));
190 if (autocvar_g_logTimestamps)
191 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", SV_WARNING, PROGS_TIME, functionName, msg));
193 print(sprintf(
"%s ^3%s^1: %s\n", SV_WARNING, functionName, msg));
196 if (autocvar_g_logTimestamps)
197 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", UI_WARNING, PROGS_TIME, functionName, msg));
199 print(sprintf(
"%s ^3%s^1: %s\n", UI_WARNING, functionName, msg));
202 if (autocvar_g_logTimestamps)
203 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", RULE_WARNING, PROGS_TIME, functionName, msg));
205 print(sprintf(
"%s ^3%s^1: %s\n", RULE_WARNING, functionName, msg));
208 if (autocvar_g_logTimestamps)
209 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", MAP_WARNING, PROGS_TIME, functionName, msg));
211 print(sprintf(
"%s ^3%s^1: %s\n", MAP_WARNING, functionName, msg));
214 if (autocvar_g_logTimestamps)
215 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", HUD_WARNING, PROGS_TIME, functionName, msg));
217 print(sprintf(
"%s ^3%s^1: %s\n", HUD_WARNING, functionName, msg));
220 if (autocvar_g_logTimestamps)
221 print(sprintf(
"%s ^9%f ^3%s^1: %s\n", ADDON_WARNING, PROGS_TIME, functionName, msg));
223 print(sprintf(
"%s ^3%s^1: %s\n", ADDON_WARNING, functionName, msg));
228_NSAssert(
bool condition,
string function,
string descr)
232 print(strcat(CG_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
238 print(strcat(SV_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
244 print(strcat(UI_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
249 print(strcat(RULE_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
254 print(strcat(MAP_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
259 print(strcat(HUD_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
264 print(strcat(ADDON_ERROR,
" ^1Assertion failed in ", function,
", reason: ", descr,
"\n"));
273#define ncLog(...) if (autocvar_g_logLevel >= LOGLEVEL_DEBUG) _ncLog(sprintf(__VA_ARGS__))
278#define ncLogAlways(...) _ncLog(sprintf(__VA_ARGS__))
284#define ncError(...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _ncError(__FUNC__, sprintf(__VA_ARGS__))
290#define ncWarning(...) if (autocvar_g_logLevel >= LOGLEVEL_WARNINGS) _ncWarning(__FUNC__, sprintf(__VA_ARGS__))
298#define NSAssert(condition, ...) if (autocvar_g_logLevel >= LOGLEVEL_ERRORS) _NSAssert(condition, __FUNC__, sprintf(__VA_ARGS__))
310const entity g_entity_null = __NULL__;
311const float g_float_null = 0.0f;
312const int g_int_null = 0i;
313const string g_string_null =
"";
314const vector g_vec_null = [0.0f, 0.0f, 0.0f];
317InitPrint(
string functionName)
319 static int chars = 51i;
322 string sideLeft =
"";
323 string sideRight =
"";
325 if (functionName == __NULL__) {
326 ncLog(
"---------------------------------------------------");
331 chars = chars - (int)strlen(functionName) - 2i;
332 charsLeft = chars / 2i;
333 charExtra = chars % 2i;
335 for (
int i = 0i; i < charsLeft; i++)
336 sideLeft = strcat(sideLeft,
"-");
338 for (
int i = 0i; i < (charsLeft + charExtra); i++) {
339 sideRight = strcat(sideRight,
"-");
342 ncLogAlways(
"%s %s %s", sideLeft, functionName, sideRight);
345#define InitStart() float local_initTime = gettime(1); InitPrint(__FUNC__)
348_InitEnd(
float oldTime,
string functionName)
350 float endTime = gettime(1);
351 ncLogAlways(
"%s loaded in %.1f seconds", functionName, (endTime - oldTime));
352 ncLogAlways(
"---------------------------------------------------");
355#define InitEnd() _InitEnd(local_initTime, __FUNC__)
358#define entity_def(x, ...) const string x[] = { __VA_ARGS__ }
361#define thread(x) if (fork()) { x; abort(); }
363#define STRING_SET(x) ((x != __NULL__) && (x != ""))
366fileExists(
string filePath)
368 if (!STRING_SET(filePath)) {
373 if not(whichpack(filePath)) {
382fileExtensionFromString(
string inputString)
384 int modelNameLength = strlen(inputString);
387 for (
int i = (modelNameLength - 1); i > 0; i--) {
388 if (str2chr(inputString, i) ==
'.') {
395 return substring(inputString, dotChar + 1, -1);
401#define Util_ExtensionFromString fileExtensionFromString
404wordInString(
string fullString,
string wordToFind)
406 int wordCount = tokenize(fullString);
408 for (
int i = 0; i < wordCount; i++) {
409 if (wordToFind == argv(i)) {
418CallSpawnfuncByName(entity target,
string className)
420 entity oldSelf = self;
421 string spawnClass = strcat(
"spawnfunc_", className);
423 callfunction(spawnClass);
typedef enumflags
Defines the valid alignment flags for text fields.
Definition: font.h:37