Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CTalkMonster::RunTask does not properly initialize variable #3177

Open
SamVanheer opened this issue Nov 29, 2021 · 0 comments
Open

CTalkMonster::RunTask does not properly initialize variable #3177

SamVanheer opened this issue Nov 29, 2021 · 0 comments

Comments

@SamVanheer
Copy link

CTalkMonster::RunTask does not properly initialize a local variable:

case TASK_TLK_CLIENT_STARE:
case TASK_TLK_LOOK_AT_CLIENT:
edict_t *pPlayer;
// track head to the client for a while.
if ( m_MonsterState == MONSTERSTATE_IDLE &&
!IsMoving() &&
!IsTalking() )
{
// Get edict for one player
pPlayer = g_engfuncs.pfnPEntityOfEntIndex( 1 );
if ( pPlayer )
{
IdleHeadTurn( pPlayer->v.origin );
}
}
else
{
// started moving or talking
TaskFail();
return;
}
if ( pTask->iTask == TASK_TLK_CLIENT_STARE )
{
// fail out if the player looks away or moves away.
if ( ( pPlayer->v.origin - pev->origin ).Length2D() > TLK_STARE_DIST )
{
// player moved away.
TaskFail();
}
UTIL_MakeVectors( pPlayer->v.angles );
if ( UTIL_DotPoints( pPlayer->v.origin, pev->origin, gpGlobals->v_forward ) < m_flFieldOfView )
{
// player looked away
TaskFail();
}
}
if ( gpGlobals->time > m_flWaitFinished )
{
TaskComplete();
}
break;

To fix this the code needs to be changed to this:

	case TASK_TLK_CLIENT_STARE:
	case TASK_TLK_LOOK_AT_CLIENT:
	{
		// Get edict for one player
		edict_t* pPlayer = g_engfuncs.pfnPEntityOfEntIndex(1);

		// track head to the client for a while.
		if (pPlayer &&
			m_MonsterState == MONSTERSTATE_IDLE &&
			!IsMoving() &&
			!IsTalking())
		{
			IdleHeadTurn(pPlayer->v.origin);
		}
		else
		{
			// started moving or talking
			TaskFail();
			return;
		}

		if (pTask->iTask == TASK_TLK_CLIENT_STARE)
		{
			// fail out if the player looks away or moves away.
			if ((pPlayer->v.origin - pev->origin).Length2D() > TLK_STARE_DIST)
			{
				// player moved away.
				TaskFail();
			}

			UTIL_MakeVectors(pPlayer->v.angles);
			if (UTIL_DotPoints(pPlayer->v.origin, pev->origin, gpGlobals->v_forward) < m_flFieldOfView)
			{
				// player looked away
				TaskFail();
			}
		}

		if (gpGlobals->time > m_flWaitFinished)
		{
			TaskComplete();
		}
		break;
	}
LogicAndTrick pushed a commit to LogicAndTrick/halflife-updated that referenced this issue Dec 26, 2021
@SamVanheer SamVanheer reopened this May 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants