Created
March 16, 2022 00:30
-
-
Save InclementDab/0ac74a9a09a3ee4db1a9f49d793c7eda to your computer and use it in GitHub Desktop.
DayZ Armor Ping Effect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Drop these files into 3_Game on your server mod | |
// Credit: @InclementDab | |
modded class ImpactMaterials | |
{ | |
static bool IsWearingArmor(EntityAI survivor, string dmg_zone) | |
{ | |
EntityAI check_item; | |
switch (dmg_zone) { | |
case "Brain": | |
case "Head": { | |
check_item = survivor.GetInventory().FindAttachment(InventorySlots.GetSlotIdFromString("Headgear")); | |
break; | |
} | |
case "Heart": | |
case "Liver": | |
case "Lungs": | |
case "Spine": | |
case "Torso": { | |
check_item = survivor.GetInventory().FindAttachment(InventorySlots.GetSlotIdFromString("Vest")); | |
break; | |
} | |
} | |
return (check_item && GetGame().ConfigGetFloat(string.Format("CfgVehicles %1 DamageSystem GlobalArmor Projectile Health damage", check_item.GetType())) > 0.15); | |
} | |
static void EvaluateImpactEffect(Object directHit, int componentIndex, string surface, vector pos, int impact_type, vector surfNormal, vector exitPos, vector inSpeed, vector outSpeed, bool deflected, string ammoType, bool isWater) | |
{ | |
bool was_armor_hit; | |
if (directHit.IsInherited(EntityAI) && IsWearingArmor(EntityAI.Cast(directHit), directHit.GetDamageZoneNameByComponentIndex(componentIndex))) { | |
if (surface != "Hit_Metal") { | |
surface = "Hit_Metal"; | |
was_armor_hit = true; | |
} | |
} | |
// No impact effects wanted for this ammo | |
if (m_IgnoredAmmo.Contains(ammoType)) { | |
return; | |
} | |
if (impact_type == ImpactTypes.UNKNOWN) { | |
impact_type = ImpactTypes.STOP; | |
} | |
if (deflected) { | |
impact_type = ImpactTypes.RICOCHET; | |
} | |
else if (outSpeed) { | |
} impact_type = ImpactTypes.PENETRATE; | |
if (isWater) { | |
surface = "Hit_Water"; | |
} | |
EffBulletImpactBase eff = EffBulletImpactBase.Cast(GetImpactEffect(surface, ammoType).Spawn()); | |
if (!eff && surface == "") { | |
eff = EffBulletImpactBase.Cast( surface.ToType().Spawn() ); | |
if (eff) { | |
RegisterSurface(surface); | |
ErrorEx(string.Format("Unregistered surface for bullet impact effect (%1). Register this surface in ImpactMaterials (Script) for better performance.", surface), ErrorExSeverity.WARNING); | |
} else { | |
if (directHit) { | |
string object_type = directHit.GetType(); | |
if (object_type == "") { | |
object_type = "OBJECT_WITHOUT_CONFIG_CLASS"; | |
} | |
ErrorEx(string.Format("Object '%1' with model file: %2.p3d has undefined 'Hit_...' material! Cannot play impact effect.", object_type, directHit.GetModelName())); | |
eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_ErrorNoMaterial", ammoType).Spawn()); | |
} | |
} | |
} | |
if (!eff && surface != "") { | |
ErrorEx(string.Format("Unregistered surface impact material <%1>! Register this surface in ImpactMaterials (Script).", surface)); | |
eff = EffBulletImpactBase.Cast(GetImpactEffect("Hit_Undefined", ammoType).Spawn()); | |
} | |
if (eff) { | |
eff.EvaluateEffect(directHit, componentIndex, pos, impact_type, surfNormal, exitPos, inSpeed, outSpeed, ammoType); | |
eff.SetAutodestroy(true); | |
SEffectManager.PlayInWorld( eff, pos ); | |
if (was_armor_hit) { | |
eff.GetParticle().SetParticleParam(EmitorParam.SIZE, 0.3); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment