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.
This commit is contained in:
Greyscale 2009-06-24 14:45:40 -07:00
parent 1f6932071d
commit 9bc5146b73
6 changed files with 279 additions and 10 deletions

View File

@ -104,9 +104,19 @@
// Commands
"Config command reload syntax"
{
"en" "Syntax: zr_reloadconfig <file alias1> [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 alias1> [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 <hitgroup alias> [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)
// ===========================

View File

@ -35,6 +35,7 @@ CommandsInit()
LogOnCommandsCreate();
ClassOnCommandsCreate();
WeaponsOnCommandsCreate();
HitgroupsOnCommandsCreate();
InfectOnCommandsCreate();
MenuOnCommandsCreate();
ZAdminOnCommandsCreate();

View File

@ -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);
}
/**

View File

@ -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 <hitgroup name> [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;
}

View File

@ -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))