From 589baa68698eb4109044e67e20385fee3fad53ee Mon Sep 17 00:00:00 2001 From: richard Date: Sun, 19 Apr 2009 01:10:30 +0200 Subject: [PATCH] Made CVAR for class file. Simplified formatting on log messages. --- src/zr/cvars.inc | 2 ++ src/zr/playerclasses/playerclasses.inc | 19 +++++++++---------- src/zr/translation.inc | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/zr/cvars.inc b/src/zr/cvars.inc index 7641d24..81c3c14 100644 --- a/src/zr/cvars.inc +++ b/src/zr/cvars.inc @@ -25,6 +25,7 @@ enum ZRSettings Handle:CVAR_CLASSES_DEFAULT_ZOMBIE, Handle:CVAR_CLASSES_DEFAULT_HUMAN, Handle:CVAR_CLASSES_DEFAULT_ADMIN, + Handle:CVAR_CLASSES_FILE, Handle:CVAR_ZOMBIE_HEALTH, Handle:CVAR_ZOMBIE_SPEED, Handle:CVAR_ZOMBIE_JUMP_DISTANCE, @@ -115,6 +116,7 @@ CreateCvars() gCvars[CVAR_CLASSES_DEFAULT_ZOMBIE] = CreateConVar("zr_classes_default_zombie", "random", "Default zombie class selected for all players when they connect. Use \"random\" to select a random class, or blank to use class config defaults."); gCvars[CVAR_CLASSES_DEFAULT_HUMAN] = CreateConVar("zr_classes_default_human", "random", "Default human class selected for all players when they connect. Use \"random\" to select a random class, or blank to use class config defaults."); gCvars[CVAR_CLASSES_DEFAULT_ADMIN] = CreateConVar("zr_classes_default_admin", "random", "Default admin-only class selected for admins when they connect. Use \"random\" to select a random class, or blank to use class config defaults."); + gCvars[CVAR_CLASSES_FILE] = CreateConVar("zr_classes_file", "configs/zr/playerclasses.txt", "Class data file to read from, in Valves key/values format. The path is relative to the \"sourcemod\" folder."); gCvars[CVAR_ZOMBIE_HEALTH] = CreateConVar("zr_zombie_health", "5000", "The default health of a zombie"); gCvars[CVAR_ZOMBIE_SPEED] = CreateConVar("zr_zombie_speed", "350", "How fast zombies travel (300: Default speed, 600: Double speed)"); gCvars[CVAR_ZOMBIE_JUMP_DISTANCE] = CreateConVar("zr_zombie_jump_distance", "0.1", "How far the zombie jumps, (0: Regular jump distance)"); diff --git a/src/zr/playerclasses/playerclasses.inc b/src/zr/playerclasses/playerclasses.inc index b445aac..955f417 100644 --- a/src/zr/playerclasses/playerclasses.inc +++ b/src/zr/playerclasses/playerclasses.inc @@ -246,14 +246,10 @@ new bool:ClassPlayerAdminMode[MAXPLAYERS + 1]; #include "zr/playerclasses/classcommands" /** - * Loads class attributes from playerclasses.txt into the ClassData array. If - * any error occour the plugin load will fail. - * - * @param classfile Optional. Specifies what file to read from. Valves key/ - * values format. The path is relative to the sourcemod - * folder. + * Loads class attributes from the class file into ClassData array. If any + * error occour the plugin load will fail, and errors will be logged. */ -ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt") +ClassLoad() { // Make sure kvClassData is ready to use. if (kvClassData != INVALID_HANDLE) @@ -262,13 +258,16 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt") } kvClassData = CreateKeyValues("classes"); + decl String:classfile[256]; + GetConVarString(gCvars[CVAR_CLASSES_FILE], classfile, sizeof(classfile)); + // Try to load the class configuration file. decl String:path[PLATFORM_MAX_PATH]; BuildPath(Path_SM, path, sizeof(path), classfile); if (!FileToKeyValues(kvClassData, path)) { - SetFailState("Class data (\"%s\") missing from server.", path); + SetFailState("Could not load class data file (\"%s\"). Check path in zr_classes_file in the configuration file.", path); } // Try to find the first class. @@ -294,7 +293,7 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt") // Maximum classes reached. Write a warning and exit the loop. if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES)) { - ZR_LogMessageFormatted(-1, "classes", "loading classes", "Warning: Maximum classes reached (%d). The rest is skipped.", _, ZR_CLASS_MAX + 1); + ZR_LogMessageFormatted(-1, "Classes", "Load", "Warning: Maximum classes reached (%d). Skipping other classes.", _, ZR_CLASS_MAX + 1); } break; @@ -358,7 +357,7 @@ ClassLoad(const String:classfile[256] = "configs/zr/playerclasses.txt") ClassData[ClassCount][class_enabled] = false; if (LogFlagCheck(LOG_CORE_EVENTS, LOG_MODULE_CLASSES)) { - ZR_LogMessageFormatted(-1, "classes", "load", "Invalid class at index %d. Class error flags: %d.", LOG_FORMAT_TYPE_ERROR, ClassCount, ClassErrorFlags); + ZR_LogMessageFormatted(-1, "Classes", "Load", "Warning: Invalid class at index %d, disabled class. Class error flags: %d.", LOG_FORMAT_TYPE_ERROR, ClassCount, ClassErrorFlags); } } diff --git a/src/zr/translation.inc b/src/zr/translation.inc index b3a546c..6cacc33 100644 --- a/src/zr/translation.inc +++ b/src/zr/translation.inc @@ -143,19 +143,19 @@ stock ZR_LogMessageFormatted(client, const String:module[], const String:block[] case LOG_FORMAT_TYPE_SIMPLE: { VFormat(buffer, sizeof(buffer), message, 6); - Format(text, sizeof(text), "Log -- %s", message); + Format(text, sizeof(text), "%s", message); LogMessage(text); } case LOG_FORMAT_TYPE_FULL: { VFormat(buffer, sizeof(buffer), message, 6); - Format(text, sizeof(text), "Log (%s : %s) -- %s", module, block, buffer); + Format(text, sizeof(text), "\"%s\" : \"%s\" -- %s", module, block, buffer); LogMessage(text); } case LOG_FORMAT_TYPE_ERROR: { VFormat(buffer, sizeof(buffer), message, 6); - Format(text, sizeof(text), "Log (%s : %s) -- %s", module, block, buffer); + Format(text, sizeof(text), "\"%s\" : \"%s\" -- %s", module, block, buffer); LogError(text); } }