Fix potential incorrect facing in scripted sequence - FreeSlave/halflife-updated GitHub Wiki

The Problem

Sometimes a monster may end up facing the wrong direction in scripted_sequence.

This fella wanted to press a button but he missed!

The Research

Without hussle I'll present you the line to blame. It's in the CTalkMonster::Touch method in dlls/talkmonster.cpp

if (speed > 50)
{
	SetConditions(bits_COND_CLIENT_PUSH);
	MakeIdealYaw(pOther->pev->origin); // <---- this one
}

It's a part of a mechanism that makes ally monsters move away when a player tries to push these bothersome Black Mesa employees out of the way. This particular line sets the monster's ideal yaw to face the player. Then it's supposed to be used in TASK_MOVE_AWAY_PATH task to find the opposite direction and move away.

Vector dir = pev->angles;
dir.y = pev->ideal_yaw + 180;

Discussing the horrorness of this hack is not a part of the tutorial, so let's move on.

If player tries to push a monster during his scripted animation the ideal yaw gets changed and TASK_FACE_IDEAL (which is part of script schedule) makes monster to start facing another direction.

The Solution

To fix this issue we need to be more careful with modifying the ideal yaw. In CTalkMonster::Touch apply this patch:

if (speed > 50)
{
-	SetConditions(bits_COND_CLIENT_PUSH);
-	MakeIdealYaw(pOther->pev->origin);
+	if (m_pSchedule != NULL && (m_pSchedule->iInterruptMask & bits_COND_CLIENT_PUSH))
+	{
+		SetConditions(bits_COND_CLIENT_PUSH);
+		MakeIdealYaw(pOther->pev->origin);
+	}
}

This way the monster's ideal yaw will be changed only if its current schedule is interruptible by bits_COND_CLIENT_PUSH condition.

Patch