2009-04-15 03:24:02 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
|
|
|
* Zombie:Reloaded
|
|
|
|
*
|
|
|
|
* File: hitgroup.inc
|
|
|
|
* Description: API for loading hitgroup specific settings.
|
|
|
|
*
|
|
|
|
* ============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array to store keyvalue data.
|
|
|
|
*/
|
|
|
|
new Handle:kvHitgroups = INVALID_HANDLE;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Player hitgroup values.
|
|
|
|
*/
|
|
|
|
#define HITGROUP_GENERIC 0
|
|
|
|
#define HITGROUP_HEAD 1
|
|
|
|
#define HITGROUP_CHEST 2
|
|
|
|
#define HITGROUP_STOMACH 3
|
|
|
|
#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
|
|
|
/**
|
|
|
|
* Clears hitgroup data.
|
|
|
|
*/
|
2009-04-15 03:24:02 +02:00
|
|
|
HitgroupsClearData()
|
|
|
|
{
|
2009-04-15 09:42:12 +02:00
|
|
|
// Load hitgroup data.
|
2009-04-15 03:24:02 +02:00
|
|
|
if (kvHitgroups != INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
CloseHandle(kvHitgroups);
|
|
|
|
}
|
|
|
|
|
|
|
|
kvHitgroups = CreateKeyValues("hitgroups");
|
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
|
|
|
* Loads hitgroup data from file.
|
|
|
|
*/
|
2009-04-15 03:24:02 +02:00
|
|
|
HitgroupsLoad()
|
|
|
|
{
|
|
|
|
// Clear hitgroup data
|
|
|
|
HitgroupsClearData();
|
|
|
|
|
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-04-15 03:24:02 +02:00
|
|
|
decl String:path[PLATFORM_MAX_PATH];
|
|
|
|
BuildPath(Path_SM, path, sizeof(path), "configs/zr/hitgroups.txt");
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// If file isn't found, stop plugin.
|
2009-04-15 03:24:02 +02:00
|
|
|
if (!FileToKeyValues(kvHitgroups, path))
|
|
|
|
{
|
2009-04-20 05:43:20 +02:00
|
|
|
if (LogCheckFlag(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS))
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
2009-04-20 05:43:20 +02:00
|
|
|
LogMessageFormatted(-1, "Hitgroups", "Config Validation", "Missing file hitgroups.txt, disabling hitgroup-based modules.", LOG_FORMAT_TYPE_FULL);
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
// Validate hitgroups config.
|
2009-04-15 03:24:02 +02:00
|
|
|
HitgroupsValidateConfig();
|
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
|
|
|
* Validate hitgroup config file and settings.
|
|
|
|
*/
|
2009-04-15 03:24:02 +02:00
|
|
|
HitgroupsValidateConfig()
|
|
|
|
{
|
2009-04-15 09:42:12 +02:00
|
|
|
// If log flag check fails, don't log.
|
2009-04-20 05:43:20 +02:00
|
|
|
if (!LogCheckFlag(LOG_CORE_EVENTS, LOG_MODULE_HITGROUPS))
|
2009-04-15 03:24:02 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
KvRewind(kvHitgroups);
|
|
|
|
if (!KvGotoFirstSubKey(kvHitgroups))
|
|
|
|
{
|
2009-04-20 05:43:20 +02:00
|
|
|
LogMessageFormatted(-1, "Hitgroups", "Config Validation", "No hitgroups listed in hitgroups.txt, disabling hitgroup-based modules.", LOG_FORMAT_TYPE_FULL);
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-15 09:42:12 +02:00
|
|
|
/**
|
|
|
|
* Retrieve hitgroup knockback value.
|
|
|
|
*
|
|
|
|
* @param hitgroup The hitgroup index.
|
2009-04-23 06:39:11 +02:00
|
|
|
* @return The knockback multiplier of the hitgroup.
|
|
|
|
*/
|
2009-04-15 03:24:02 +02:00
|
|
|
Float:HitgroupsGetHitgroupKnockback(hitgroup)
|
|
|
|
{
|
|
|
|
// Reset keyvalue's traversal stack.
|
|
|
|
KvRewind(kvHitgroups);
|
|
|
|
if (KvGotoFirstSubKey(kvHitgroups))
|
|
|
|
{
|
|
|
|
decl String:sHitgroup[4];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvHitgroups, sHitgroup, sizeof(sHitgroup));
|
|
|
|
|
|
|
|
// If this is the right hitgroup, then return knockback for it.
|
|
|
|
if (hitgroup == StringToInt(sHitgroup))
|
|
|
|
{
|
|
|
|
return KvGetFloat(kvHitgroups, "knockback", 1.0);
|
|
|
|
}
|
|
|
|
} while (KvGotoNextKey(kvHitgroups));
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1.0;
|
2009-04-23 06:39:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve hitgroup damage value.
|
|
|
|
*
|
|
|
|
* @param hitgroup The hitgroup index.
|
|
|
|
* @return True if hitgroup can be damaged, false if not.
|
|
|
|
*/
|
|
|
|
bool:HitgroupsCanDamageHitgroup(hitgroup)
|
|
|
|
{
|
|
|
|
// Reset keyvalue's traversal stack.
|
|
|
|
KvRewind(kvHitgroups);
|
|
|
|
if (KvGotoFirstSubKey(kvHitgroups))
|
|
|
|
{
|
|
|
|
decl String:sHitgroup[4];
|
|
|
|
decl String:damage[8];
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
KvGetSectionName(kvHitgroups, sHitgroup, sizeof(sHitgroup));
|
|
|
|
|
|
|
|
// If this is the right hitgroup, then return knockback for it.
|
|
|
|
if (hitgroup == StringToInt(sHitgroup))
|
|
|
|
{
|
|
|
|
// Get config setting string.
|
|
|
|
KvGetString(kvHitgroups, "damage", damage, sizeof(damage), "yes");
|
|
|
|
|
|
|
|
// Return hitgroup's damage setting.
|
|
|
|
return ZRConfigSettingToBool(damage);
|
|
|
|
}
|
|
|
|
} while (KvGotoNextKey(kvHitgroups));
|
|
|
|
}
|
|
|
|
|
|
|
|
// If hitgroup is missing, then default to "yes."
|
|
|
|
return true;
|
2009-04-15 03:24:02 +02:00
|
|
|
}
|