2009-04-15 03:24:02 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
2009-05-06 02:28:09 +02:00
|
|
|
* File: hitgroup.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: API for loading hitgroup specific settings.
|
2009-04-15 03:24:02 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2009-05-29 08:43:15 +02:00
|
|
|
* Maximum length for a hitgroup name
|
2009-04-15 03:24:02 +02:00
|
|
|
*/
|
2009-05-29 08:43:15 +02:00
|
|
|
#define HITGROUPS_MAX_LENGTH 32
|
2009-04-15 03:24:02 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Player hitgroup values.
|
|
|
|
*/
|
2009-04-30 07:36:57 +02:00
|
|
|
#define HITGROUP_GENERIC 0
|
|
|
|
#define HITGROUP_HEAD 1
|
|
|
|
#define HITGROUP_CHEST 2
|
|
|
|
#define HITGROUP_STOMACH 3
|
2009-04-15 03:24:02 +02:00
|
|
|
#define HITGROUP_LEFTARM 4
|
|
|
|
#define HITGROUP_RIGHTARM 5
|
|
|
|
#define HITGROUP_LEFTLEG 6
|
|
|
|
#define HITGROUP_RIGHTLEG 7
|
|
|
|
#define HITGROUP_GEAR 10
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
2009-05-29 08:43:15 +02:00
|
|
|
* Hitgroup config data indexes.
|
|
|
|
*/
|
|
|
|
enum HitgroupsData
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
HITGROUPS_DATA_NAME = 0,
|
|
|
|
HITGROUPS_DATA_INDEX,
|
|
|
|
HITGROUPS_DATA_DAMAGE,
|
|
|
|
HITGROUPS_DATA_KNOCKBACK,
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
/**
|
|
|
|
* Array handle to store hitgroups data.
|
|
|
|
*/
|
|
|
|
new Handle:arrayHitgroups = INVALID_HANDLE;
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
|
|
|
* Loads hitgroup data from file.
|
|
|
|
*/
|
2009-04-15 03:24:02 +02:00
|
|
|
HitgroupsLoad()
|
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Register config file.
|
|
|
|
ConfigRegisterConfig(File_Hitgroups, Structure_Keyvalue, CONFIG_FILE_ALIAS_HITGROUPS);
|
2009-05-18 06:26:13 +02:00
|
|
|
|
2009-04-20 02:56:26 +02:00
|
|
|
// If module is disabled, then stop.
|
|
|
|
new bool:hitgroups = GetConVarBool(g_hCvarsList[CVAR_HITGROUPS]);
|
|
|
|
if (!hitgroups)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Get hitgroups config path.
|
|
|
|
decl String:pathhitgroups[PLATFORM_MAX_PATH];
|
|
|
|
new bool:exists = ConfigGetCvarFilePath(CVAR_CONFIG_PATH_HITGROUPS, pathhitgroups);
|
|
|
|
|
2009-04-30 07:36:57 +02:00
|
|
|
// If file doesn't exist, then log and stop.
|
|
|
|
if (!exists)
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-04-30 07:36:57 +02:00
|
|
|
// Log failure.
|
2009-05-14 09:32:01 +02:00
|
|
|
LogPrintToLog(LOG_FORMAT_TYPE_ERROR, "Hitgroups", "Config Validation", "Missing hitgroups config file: %s", pathhitgroups);
|
2009-05-29 08:43:15 +02:00
|
|
|
|
2009-04-15 03:24:02 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Set the path to the config file.
|
|
|
|
ConfigSetConfigPath(File_Hitgroups, pathhitgroups);
|
|
|
|
|
|
|
|
// Load config from file and create array structure.
|
|
|
|
new bool:success = ConfigLoadConfig(File_Hitgroups, arrayHitgroups);
|
|
|
|
|
|
|
|
// Unexpected error, stop plugin.
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
LogPrintToLog(LOG_FORMAT_TYPE_ERROR, "Hitgroups", "Config Validation", "Unexpected error encountered loading: %s", pathhitgroups);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2009-04-30 07:36:57 +02:00
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// Validate hitgroups config.
|
2009-05-29 08:43:15 +02:00
|
|
|
new size = GetArraySize(arrayHitgroups);
|
|
|
|
if (!size)
|
|
|
|
{
|
|
|
|
LogPrintToLog(LOG_FORMAT_TYPE_ERROR, "Hitgroups", "Config Validation", "No usable data found in hitgroups config file: %s", pathhitgroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now copy data to array structure.
|
|
|
|
HitgroupsCacheData();
|
2009-05-18 06:26:13 +02:00
|
|
|
|
|
|
|
// Set config data.
|
2009-05-29 08:43:15 +02:00
|
|
|
ConfigSetConfigLoaded(File_Hitgroups, true);
|
|
|
|
ConfigSetConfigReloadFunc(File_Hitgroups, GetFunctionByName(GetMyHandle(), "HitgroupsOnConfigReload"));
|
|
|
|
ConfigSetConfigHandle(File_Hitgroups, arrayHitgroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Caches hitgroup data from file into arrays.
|
|
|
|
* Make sure the file is loaded before (ConfigLoadConfig) to prep array structure.
|
|
|
|
*/
|
|
|
|
HitgroupsCacheData()
|
|
|
|
{
|
|
|
|
// Get config's file path.
|
|
|
|
decl String:pathhitgroups[PLATFORM_MAX_PATH];
|
|
|
|
ConfigGetConfigPath(File_Hitgroups, pathhitgroups, sizeof(pathhitgroups));
|
|
|
|
|
|
|
|
new Handle:kvHitgroups;
|
|
|
|
new bool:success = ConfigOpenConfigFile(File_Hitgroups, kvHitgroups);
|
|
|
|
|
|
|
|
if (!success)
|
|
|
|
{
|
|
|
|
LogPrintToLog(LOG_FORMAT_TYPE_ERROR, "Hitgroups", "Config Validation", "Unexpected error caching data from hitgroups config file: %s", pathhitgroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
|
|
|
KvRewind(kvHitgroups);
|
|
|
|
if (!KvJumpToKey(kvHitgroups, hitgroupname))
|
|
|
|
{
|
|
|
|
LogPrintToLog(LOG_FORMAT_TYPE_ERROR, "Hitgroups", "Config Validation", "Couldn't cache hitgroup data for: %s (check hitgroup config)", hitgroupname);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// General
|
|
|
|
new index = KvGetNum(kvHitgroups, "index", -1);
|
|
|
|
|
|
|
|
// Damage
|
|
|
|
new bool:damage = ConfigKvGetStringBool(kvHitgroups, "damage", "yes");
|
|
|
|
|
|
|
|
// Knockback (module)
|
|
|
|
new Float:knockback = KvGetFloat(kvHitgroups, "knockback", 1.0);
|
|
|
|
|
|
|
|
new Handle:arrayHitgroup = GetArrayCell(arrayHitgroups, x);
|
|
|
|
|
|
|
|
// Push data into array.
|
|
|
|
PushArrayCell(arrayHitgroup, index); // Index: 1
|
|
|
|
PushArrayCell(arrayHitgroup, damage); // Index: 2
|
|
|
|
PushArrayCell(arrayHitgroup, knockback); // Index: 3
|
|
|
|
}
|
|
|
|
|
|
|
|
// We're done with this file now, so we can close it.
|
|
|
|
CloseHandle(kvHitgroups);
|
2009-05-18 06:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called when configs are being reloaded.
|
|
|
|
*
|
|
|
|
* @param config The config being reloaded. (only if 'all' is false)
|
|
|
|
*/
|
|
|
|
public HitgroupsOnConfigReload(ConfigFile:config)
|
|
|
|
{
|
|
|
|
// Reload hitgroups config.
|
2009-05-29 08:43:15 +02:00
|
|
|
HitgroupsLoad();
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
2009-05-29 08:43:15 +02:00
|
|
|
* Find the array index at which the hitgroup index is at.
|
|
|
|
*
|
|
|
|
* @param hitgroup The hitgroup index to search for.
|
|
|
|
* @return The array index that contains the given hitgroup index.
|
|
|
|
*/
|
|
|
|
stock HitgroupToIndex(hitgroup)
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// x = Array index.
|
|
|
|
new size = GetArraySize(arrayHitgroups);
|
|
|
|
for (new x = 0; x < size; x++)
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Get hitgroup index at this array index.
|
|
|
|
new index = HitgroupsGetIndex(x);
|
|
|
|
|
|
|
|
// If hitgroup indexes match, then return array index.
|
|
|
|
if (hitgroup == index)
|
|
|
|
{
|
|
|
|
return x;
|
|
|
|
}
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
2009-05-29 08:43:15 +02:00
|
|
|
|
|
|
|
// Hitgroup index doesn't exist.
|
|
|
|
return -1;
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
2009-05-29 08:43:15 +02:00
|
|
|
* Gets the name of a hitgroup at a given index.
|
|
|
|
* @param index The hitgroup index.
|
|
|
|
* @param hitgroup The string to return name in.
|
|
|
|
* @param maxlen The max length of the string.
|
|
|
|
*/
|
|
|
|
stock HitgroupsGetName(index, String:hitgroup[], maxlen)
|
|
|
|
{
|
|
|
|
// Get array handle of hitgroup at given index.
|
|
|
|
new Handle:arrayHitgroup = GetArrayCell(arrayHitgroups, index);
|
|
|
|
|
|
|
|
// Get hitgroup name.
|
|
|
|
GetArrayString(arrayHitgroup, _:HITGROUPS_DATA_NAME, hitgroup, maxlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve hitgroup index.
|
2009-04-15 09:42:12 +02:00
|
|
|
*
|
2009-05-29 08:43:15 +02:00
|
|
|
* @param index The array index.
|
|
|
|
* @return The hitgroup index.
|
2009-04-23 06:39:11 +02:00
|
|
|
*/
|
2009-05-29 08:43:15 +02:00
|
|
|
stock HitgroupsGetIndex(index)
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Get array handle of hitgroup at given index.
|
|
|
|
new Handle:arrayHitgroup = GetArrayCell(arrayHitgroups, index);
|
2009-04-15 03:24:02 +02:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Return hitgroup index of the hitgroup.
|
|
|
|
return GetArrayCell(arrayHitgroup, _:HITGROUPS_DATA_INDEX);
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve hitgroup damage value.
|
|
|
|
*
|
2009-05-29 08:43:15 +02:00
|
|
|
* @param index The array index.
|
2009-04-23 06:39:11 +02:00
|
|
|
* @return True if hitgroup can be damaged, false if not.
|
|
|
|
*/
|
2009-05-29 08:43:15 +02:00
|
|
|
stock bool:HitgroupsCanDamage(index)
|
2009-04-23 06:39:11 +02:00
|
|
|
{
|
2009-05-29 08:43:15 +02:00
|
|
|
// Get array handle of hitgroup at given index.
|
|
|
|
new Handle:arrayHitgroup = GetArrayCell(arrayHitgroups, index);
|
|
|
|
|
|
|
|
// Return true if hitgroup can be damaged, false if not.
|
|
|
|
return bool:GetArrayCell(arrayHitgroup, _:HITGROUPS_DATA_DAMAGE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve hitgroup knockback value.
|
|
|
|
*
|
|
|
|
* @param index The array index.
|
|
|
|
* @return The knockback multiplier of the hitgroup.
|
|
|
|
*/
|
|
|
|
stock Float:HitgroupsGetKnockback(index)
|
|
|
|
{
|
|
|
|
// Get array handle of hitgroup at given index.
|
|
|
|
new Handle:arrayHitgroup = GetArrayCell(arrayHitgroups, index);
|
2009-04-23 06:39:11 +02:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Return the knockback multiplier for the hitgroup.
|
|
|
|
return Float:GetArrayCell(arrayHitgroup, _:HITGROUPS_DATA_KNOCKBACK);
|
2009-05-01 11:22:45 +02:00
|
|
|
}
|