I am creating a plugin that keeps humans from taking headshot damage and 1/2 the normal damage. I am trying to do all this in TraceLine()
The head shot part works fine.
Code:
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
TRACE_LINE(v1, v2, fNoMonsters, pentToSkip, ptr);
// is a human taking headshot damage?
if ( !(ptr->pHit->v.flags & FL_FAKECLIENT) && ((1<<HITGROUP_HEAD) & (1<<ptr->iHitgroup)) )
{
// disallow head shots to humans, return no damage
ptr->flFraction = 1.0;
RETURN_META(MRES_SUPERCEDE);
}
else
{
// bot is taking damage let it rip
RETURN_META(MRES_IGNORED);
}
}
But if I add in this part that ignores every other damage hit to humans the CZ bots go nuts and fire at weird things like doors and walls and only about 1/2 the time attack humans with guns. Very weird!
Code:
// ---------------------------------------------------------------------------------------
// TraceLine()
//
// Disallow headshot damange and skip every other hit to human players
// ---------------------------------------------------------------------------------------
void TraceLine(const float *v1, const float *v2, int fNoMonsters, edict_t *pentToSkip, TraceResult *ptr)
{
static bool skipHit = false;
TRACE_LINE(v1, v2, fNoMonsters, pentToSkip, ptr);
// is a human taking damage?
if ( !(ptr->pHit->v.flags & FL_FAKECLIENT) )
{
// is it a head shot?
if( (1<<HITGROUP_HEAD) & (1<<ptr->iHitgroup) )
{
// disallow head shots to humans, return no damage
ptr->flFraction = 1.0;
RETURN_META(MRES_SUPERCEDE);
}
else if(skipHit)
{
// skip ever other shot!
skipHit = false;
ptr->flFraction = 1.0;
RETURN_META(MRES_SUPERCEDE);
}
else
{
//skipHit = true;
RETURN_META(MRES_IGNORED);
}
}
else
{
// bot is taking damage let it rip
RETURN_META(MRES_IGNORED);
}
}
Does anyone know why this would happen?