From 9bc5146b73f4fdc5787026a21434b46a5d345e20 Mon Sep 17 00:00:00 2001 From: Greyscale Date: Wed, 24 Jun 2009 14:45:40 -0700 Subject: [PATCH] Added hitgroup commands, including zr_hitgroup, zr_hitgroup_enable_all, and zr_hitgroup_headshots_only. Updated hitgroup configs, updated translations Added logging for hitgroups and configs. --- .../addons/sourcemod/configs/zr/hitgroups.txt | 8 +- .../translations/zombiereloaded.phrases.txt | 59 +++++- src/zr/commands.inc | 1 + src/zr/config.inc | 17 +- src/zr/hitgroups.inc | 195 ++++++++++++++++++ src/zr/translation.inc | 9 +- 6 files changed, 279 insertions(+), 10 deletions(-) diff --git a/cstrike/addons/sourcemod/configs/zr/hitgroups.txt b/cstrike/addons/sourcemod/configs/zr/hitgroups.txt index a6e1bea..5965fd9 100644 --- a/cstrike/addons/sourcemod/configs/zr/hitgroups.txt +++ b/cstrike/addons/sourcemod/configs/zr/hitgroups.txt @@ -65,7 +65,7 @@ "knockback" "1.2" } - "Left Arm" + "LeftArm" { // General "index" "4" @@ -77,7 +77,7 @@ "knockback" "1.0" } - "Right Arm" + "RightArm" { // General "index" "5" @@ -89,7 +89,7 @@ "knockback" "1.0" } - "Left Leg" + "LeftLeg" { // General "index" "6" @@ -101,7 +101,7 @@ "knockback" "0.9" } - "Right Leg" + "RightLeg" { // General "index" "7" diff --git a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt index 8cfd4b9..32fd34e 100644 --- a/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt +++ b/cstrike/addons/sourcemod/translations/zombiereloaded.phrases.txt @@ -104,9 +104,19 @@ // Commands "Config command reload syntax" + { + "en" "Syntax: zr_reloadconfig [file alias2] ... - Reloads a config file." + } + + "Config command reload related commands" + { + "en" "Related command(s): zr_config_reloadall" + } + + "Config command reload syntax aliases" { "#format" "{1:s},{2:s},{3:s},{4:s},{5:s}" - "en" "Syntax: zr_reloadconfig [file alias2] ... - Reloads a config file.\n File Aliases:\n * \"{1}\"\n * \"{2}\"\n * \"{3}\"\n * \"{4}\"\n * \"{5}\"" + "en" "File Aliases:\n* \"{1}\"\n* \"{2}\"\n* \"{3}\"\n* \"{4}\"\n* \"{5}\"" } "Config command reload invalid" @@ -716,6 +726,53 @@ "en" "Ammo" } + // =========================== + // Hitgroups (core) + // =========================== + + "Hitgroups command syntax" + { + "en" "Toggles or sets if a zombie's hitgroup can be damaged. Usage: zr_hitgroup [1/0]" + } + + "Hitgroups command related commands" + { + "en" "Related command(s): zr_hitgroup_enable_all, zr_hitgroup_headshots_only" + } + + "Hitgroups command syntax names" + { + "en" "Hitgroup Names:" + } + + "Hitgroups command successful on" + { + "#format" "{1:s}" + "en" "Damage for hitgroup \"{1}\" has been toggled on." + } + + "Hitgroups command successful off" + { + "#format" "{1:s}" + "en" "Damage for hitgroup \"{1}\" has been toggled off." + } + + "Hitgroups command invalid hitgroup" + { + "#format" "{1:s}" + "en" "\"{1}\" is not a valid hitgroup alias. Type zr_hitgroup to view all aliases." + } + + "Hitgroups command enable all successful" + { + "en" "All zombie hitgroups have been enabled for damage." + } + + "Hitgroups command headshots only successful" + { + "en" "Zombies may now only be damaged by headshots." + } + // =========================== // Spawn Protect (module) // =========================== diff --git a/src/zr/commands.inc b/src/zr/commands.inc index 708fbe4..6f343e8 100644 --- a/src/zr/commands.inc +++ b/src/zr/commands.inc @@ -35,6 +35,7 @@ CommandsInit() LogOnCommandsCreate(); ClassOnCommandsCreate(); WeaponsOnCommandsCreate(); + HitgroupsOnCommandsCreate(); InfectOnCommandsCreate(); MenuOnCommandsCreate(); ZAdminOnCommandsCreate(); diff --git a/src/zr/config.inc b/src/zr/config.inc index 6a955ff..ead5501 100644 --- a/src/zr/config.inc +++ b/src/zr/config.inc @@ -797,12 +797,15 @@ public Action:ConfigReloadCommand(client, argc) // If not enough arguments given, then stop. if (argc < 1) { - TranslationReplyToCommand(client, "Config command reload syntax", CONFIG_FILE_ALIAS_MODELS, CONFIG_FILE_ALIAS_DOWNLOADS, CONFIG_FILE_ALIAS_CLASSES, CONFIG_FILE_ALIAS_WEAPONS, CONFIG_FILE_ALIAS_HITGROUPS); + TranslationReplyToCommand(client, "Config command reload syntax"); + TranslationReplyToCommand(client, "Config command reload related commands"); + TranslationPrintToConsole(client, "Config command reload syntax aliases", CONFIG_FILE_ALIAS_MODELS, CONFIG_FILE_ALIAS_DOWNLOADS, CONFIG_FILE_ALIAS_CLASSES, CONFIG_FILE_ALIAS_WEAPONS, CONFIG_FILE_ALIAS_HITGROUPS); return Plugin_Handled; } decl String:filealias[CONFIG_MAX_LENGTH]; decl String:path[PLATFORM_MAX_PATH]; + decl String:logmessage[LOG_MAX_LENGTH_FILE]; new args = GetCmdArgs(); for (new x = 1; x <= args; x++) @@ -824,11 +827,20 @@ public Action:ConfigReloadCommand(client, argc) // Get config file path. ConfigGetConfigPath(config, path, sizeof(path)); + // Format log message + Format(logmessage, sizeof(logmessage), "Admin \"%L\" reloaded config file \"%s\". (zr_config_reload)", client); + // If file isn't loaded then tell client, then stop. if (!loaded) { TranslationReplyToCommand(client, "Config command reload not loaded", filealias); + + // Format a failed attempt string to the end of the log message. + Format(logmessage, sizeof(logmessage), "%s -- attempt failed, config file not loaded", logmessage); } + + // Log action to game events. + LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Config, "Reload Config", logmessage); } return Plugin_Handled; @@ -866,6 +878,9 @@ public Action:ConfigReloadAllCommand(client, argc) TranslationReplyToCommand(client, "Config command reload all stats failed", configalias); } } + + // Log action to game events. + LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Config, "Reload All Config", "Admin \"%L\" reloaded all config files.", client); } /** diff --git a/src/zr/hitgroups.inc b/src/zr/hitgroups.inc index a4de4e8..37c5def 100644 --- a/src/zr/hitgroups.inc +++ b/src/zr/hitgroups.inc @@ -62,6 +62,17 @@ enum HitgroupsData */ new Handle:arrayHitgroups = INVALID_HANDLE; +/** + * Create commands related to config here. + */ +HitgroupsOnCommandsCreate() +{ + // Create config admin commands. + RegAdminCmd("zr_hitgroup", HitgroupsCommand, ADMFLAG_CONFIG, "Toggles or sets if a zombie's hitgroup can be damaged. Usage: zr_hitgroup [1/0]"); + RegAdminCmd("zr_hitgroup_enable_all", HitgroupsEnableAllCommand, ADMFLAG_CONFIG, "Enables all zombie hitgroups to be damaged. Usage: zr_hitgroup_enable_all"); + RegAdminCmd("zr_hitgroup_headshots_only", HitgroupsHeadshotsOnlyCommand, ADMFLAG_CONFIG, "Disables all zombie hitgroups but the head. Usage: zr_hitgroup_headshots_only"); +} + /** * Loads hitgroup data from file. */ @@ -185,6 +196,43 @@ public HitgroupsOnConfigReload(ConfigFile:config) HitgroupsLoad(); } +/** + * Find the index at which the hitgroup's name is at. + * + * @param hitgroup The higroup name. + * @param maxlen (Only if 'overwritename' is true) The max length of the hitgroup name. + * @param overwritename (Optional) If true, the hitgroup given will be overwritten with the name from the config. + * @return The array index containing the given hitgroup name. + */ +stock HitgroupsNameToIndex(String:hitgroup[], maxlen = 0, bool:overwritename = false) +{ + decl String:hitgroupname[HITGROUPS_MAX_LENGTH]; + + // x = Array index. + new size = GetArraySize(arrayHitgroups); + for (new x = 0; x < size; x++) + { + HitgroupsGetName(x, hitgroupname, sizeof(hitgroupname)); + + // If names match, then return index. + if (StrEqual(hitgroup, hitgroupname, false)) + { + // If 'overwrite' name is true, then overwrite the old string with new. + if (overwritename) + { + // Copy config name to return string. + strcopy(hitgroup, maxlen, hitgroupname); + } + + // Return this index. + return x; + } + } + + // Name doesn't exist. + return -1; +} + /** * Find the array index at which the hitgroup index is at. * @@ -300,3 +348,150 @@ stock Float:HitgroupsGetKnockback(index) // Return the knockback multiplier for the hitgroup. return Float:GetArrayCell(arrayHitgroup, _:HITGROUPS_DATA_KNOCKBACK); } + +/** + * Command callback (zr_hitgroup) + * Toggles or sets if a zombie's hitgroup can be damaged. + * + * @param client The client index. + * @param argc Argument count. + */ +public Action:HitgroupsCommand(client, argc) +{ + // If not enough arguments given, then stop. + if (argc < 1) + { + TranslationReplyToCommand(client, "Hitgroups command syntax"); + TranslationReplyToCommand(client, "Hitgroups command related commands"); + TranslationPrintToConsole(client, "Hitgroups command syntax names"); + + // Print all the hitgroup names in the client's console. + decl String:hitgroupname[HITGROUPS_MAX_LENGTH]; + + // x = Hitgroup index. + new size = GetArraySize(arrayHitgroups); + for (new x = 0; x < size; x++) + { + // Get the hitgroups name and print in console. + HitgroupsGetName(x, hitgroupname, sizeof(hitgroupname)); + PrintToConsole(client, "* %s", hitgroupname); + } + + return Plugin_Handled; + } + + // Get hitgroup alias given. + decl String:target[HITGROUPS_MAX_LENGTH]; + GetCmdArg(1, target, sizeof(target)); + + // If the hitgroup is invalid, then stop and tell client. + new hitgroup = HitgroupsNameToIndex(target, sizeof(target), true); + if (hitgroup == -1) + { + TranslationReplyToCommand(client, "Hitgroups command invalid hitgroup", target); + return Plugin_Handled; + } + + new bool:hitgroupdamage; + + // Check if value was given + decl String:value[4]; + GetCmdArg(2, value, sizeof(value)); + if (!value[0]) + { + // Get the opposite value of the current hitgroup value. + hitgroupdamage = !HitgroupsCanDamage(hitgroup); + } + else + { + // Cast the given value to a bool. + hitgroupdamage = bool:StringToInt(value); + } + + // Set new value in the hitgroup data cache. + HitgroupsSetDamage(hitgroup, hitgroupdamage); + + // Tell client the new value of the hitgroup. + if (hitgroupdamage) + { + TranslationReplyToCommand(client, "Hitgroups command successful on", target); + } + else + { + TranslationReplyToCommand(client, "Hitgroups command successful off", target); + } + + // Log action to game events. + LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Hitgroups, "Headshots Toggle", "Admin \"%L\" toggled hitgroup \"%s\" to \"%d\". (zr_hitgroup)", client, target, hitgroupdamage); + + return Plugin_Handled; +} + +/** + * Command callback (zr_hitgroup_enable_all) + * Enables all zombie hitgroups to be damaged. + * + * @param client The client index. + * @param argc Argument count. + */ +public Action:HitgroupsEnableAllCommand(client, argc) +{ + new hitgroup; + + // x = Hitgroup index. + new size = GetArraySize(arrayHitgroups); + for (new x = 0; x < size; x++) + { + // Get CS:S hitgroup index. + hitgroup = HitgroupsGetIndex(x); + + // Set that hitgroup index to true for damage. + HitgroupsSetDamage(hitgroup, true); + } + + // Tell the server that all hitgroups have been enabled. + TranslationPrintToChatAll(true, false, "Hitgroups command enable all successful"); + + // Log action to game events. + LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Hitgroups, "Enable All", "Admin \"%L\" enabled all zombie hitgroups. (zr_hitgroup_enable_all)", client); + + return Plugin_Handled; +} + +/** + * Command callback (zr_hitgroup_enable_all) + * Disables all zombie hitgroups but the head. + * + * @param client The client index. + * @param argc Argument count. + */ +public Action:HitgroupsHeadshotsOnlyCommand(client, argc) +{ + new hitgroup; + + // x = Hitgroup index. + new size = GetArraySize(arrayHitgroups); + for (new x = 0; x < size; x++) + { + // Get CS:S hitgroup index. + hitgroup = HitgroupsGetIndex(x); + + // If this hitgroup is the head, then enable it and stop. + if (hitgroup == HITGROUP_HEAD) + { + HitgroupsSetDamage(hitgroup, true); + continue; + } + + // Set that hitgroup index to true for damage. + HitgroupsSetDamage(hitgroup, false); + } + + // Tell the server that all hitgroups have been enabled. + TranslationPrintToChatAll(true, false, "Hitgroups command headshots only successful"); + + // Log action to game events. + LogEvent(false, LogType_Normal, LOG_GAME_EVENTS, LogModule_Hitgroups, "Headshots Only", "Admin \"%L\" enabled headshots only. (zr_hitgroup_headshots_only)", client); + + return Plugin_Handled; +} diff --git a/src/zr/translation.inc b/src/zr/translation.inc index 3d0333d..f2ae06e 100644 --- a/src/zr/translation.inc +++ b/src/zr/translation.inc @@ -132,6 +132,7 @@ stock TranslationPrintToChat(client, any:...) * Format the string to the plugin's style. * * @param server True to also print text to server console, false just to clients. + * @param admin True to only print text to admins, false to print to everyone. * @param ... Translation formatting parameters. */ stock TranslationPrintToChatAll(bool:server, bool:admin, any:...) @@ -194,7 +195,7 @@ stock TranslationPrintToConsole(client, any:...) SetGlobalTransTarget(client); // Translate phrase. - decl String:translation[TRANSLATION_MAX_LENGTH_CHAT]; + decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE]; VFormat(translation, sizeof(translation), "%t", 2); // Format string to create plugin style. @@ -212,7 +213,7 @@ stock TranslationPrintToConsole(client, any:...) */ stock TranslationPrintToConsoleAll(bool:server, bool:admin, any:...) { - decl String:translation[TRANSLATION_MAX_LENGTH_CHAT]; + decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE]; if (server) { @@ -317,7 +318,7 @@ stock TranslationPrintToServer(any:...) SetGlobalTransTarget(LANG_SERVER); // Translate phrase. - decl String:translation[TRANSLATION_MAX_LENGTH_CHAT]; + decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE]; VFormat(translation, sizeof(translation), "%t", 1); // Format string to create plugin style. @@ -339,7 +340,7 @@ stock TranslationReplyToCommand(client, any:...) SetGlobalTransTarget(client); // Translate phrase. - decl String:translation[TRANSLATION_MAX_LENGTH_CHAT]; + decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE]; VFormat(translation, sizeof(translation), "%t", 2); if (ZRIsClientValid(client))