It's weird because in the HLSDK a trace_texture is done after you fire.
Code:
[...]
if (tr.flFraction != 1.0)
{
CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
if ( iDamage )
{
pEntity->TraceAttack(pevAttacker, iDamage, vecDir, &tr, DMG_BULLET | ((iDamage > 16) ? DMG_ALWAYSGIB : DMG_NEVERGIB) );
TEXTURETYPE_PlaySound(&tr, vecSrc, vecEnd, iBulletType);
DecalGunshot( &tr, iBulletType );
}
[...]
Code:
// play a strike sound based on the texture that was hit by the attack traceline. VecSrc/VecEnd are the
// original traceline endpoints used by the attacker, iBulletType is the type of bullet that hit the texture.
// returns volume of strike instrument (crowbar) to play
float TEXTURETYPE_PlaySound(TraceResult *ptr, Vector vecSrc, Vector vecEnd, int iBulletType)
{
// hit the world, try to play sound based on texture material type
char chTextureType;
float fvol;
float fvolbar;
char szbuffer[64];
const char *pTextureName;
float rgfl1[3];
float rgfl2[3];
char *rgsz[4];
int cnt;
float fattn = ATTN_NORM;
if ( !g_pGameRules->PlayTextureSounds() )
return 0.0;
CBaseEntity *pEntity = CBaseEntity::Instance(ptr->pHit);
chTextureType = 0;
if (pEntity && pEntity->Classify() != CLASS_NONE && pEntity->Classify() != CLASS_MACHINE)
// hit body
chTextureType = CHAR_TEX_FLESH;
else
{
// hit world
// find texture under strike, get material type
// copy trace vector into array for trace_texture
vecSrc.CopyToArray(rgfl1);
vecEnd.CopyToArray(rgfl2);
// get texture from entity or world (world is ent(0))
if (pEntity)
pTextureName = TRACE_TEXTURE( ENT(pEntity->pev), rgfl1, rgfl2 );
else
pTextureName = TRACE_TEXTURE( ENT(0), rgfl1, rgfl2 );
if ( pTextureName )
{
// strip leading '-0' or '+0~' or '{' or '!'
if (*pTextureName == '-' || *pTextureName == '+')
pTextureName += 2;
if (*pTextureName == '{' || *pTextureName == '!' || *pTextureName == '~' || *pTextureName == ' ')
pTextureName++;
// '}}'
strcpy(szbuffer, pTextureName);
szbuffer[CBTEXTURENAMEMAX - 1] = 0;
// ALERT ( at_console, "texture hit: %s\n", szbuffer);
// get texture type
chTextureType = TEXTURETYPE_Find(szbuffer);
}
}
[...]
__________________