Barney Reload stucks and does not fire Created 2 years ago2022-11-07 19:31:29 UTC by La Hire La Hire

Created 2 years ago2022-11-07 19:31:29 UTC by La Hire La Hire

Posted 2 years ago2022-11-07 19:31:29 UTC Post #347055
Hello, I am a total noob in C++ and try to do some 'easy' coding for a HL1-mod.
Currently I want to have Barney reload after 2 shots and after some try and error and the tutorial of Shepard62700FR (https://twhl.info/wiki/page/Monsters_Programming_-_Standard_and_Squad_Monsters#Reloading) I got him to do that but, after the reload-sequence, the model points the gun at the next enemy and freezes, no more shots are beeing fired.

Could someone please have a look and point me in the right direction?

In talkmonster.h I declerated the variable from the basemonste.h:
int m_cAmmoLoaded;

And as the initial filling works (Barney fires 2 shots because is spawned with it) *I suspect the issue to be either here:
*
void CBarney::HandleAnimEvent(MonsterEvent_t* pEvent )
{
switch ( pEvent->event )
{
case BARNEY_AE_RELOAD:
{
m_cAmmoLoaded = 2;
ClearConditions(bits_COND_NO_AMMO_LOADED);
break;
}
case BARNEY_AE_SHOOT:
{
BarneyFirePistol();
break;
}

case BARNEY_AE_DRAW:
// barney's bodygroup switches here so he can pull gun from holster
{
pev->body = BARNEY_BODY_GUNDRAWN;
m_fGunDrawn = true;
break;
}
case BARNEY_AE_HOLSTER:
{
// change bodygroup to replace gun in holster
pev->body = BARNEY_BODY_GUNHOLSTERED;
m_fGunDrawn = false;
break;
}
default:
CTalkMonster::HandleAnimEvent(pEvent);
}
}

or maybe here:

Schedule_t* CBarney::GetScheduleOfType(int Type)
{
Schedule_t *psched;
switch (Type)
{
case SCHED_RELOAD:
return slBarneyReload;

break;
...

class CBarney : public CTalkMonster
{
public:
void Spawn() override;
void Precache() override;
void SetYawSpeed() override;
int ISoundMask() override;
void BarneyFirePistol();
void AlertSound() override;
int Classify() override;
void HandleAnimEvent(MonsterEvent_t* pEvent) override;

void CBarney::CheckAmmo()
{
if (m_cAmmoLoaded <= 0)
SetConditions(bits_COND_NO_AMMO_LOADED);
}

Task_t tlBarneyReload[] =
{
{TASK_STOP_MOVING, (float)0},
{TASK_FACE_ENEMY, (float)0},
{TASK_PLAY_SEQUENCE, (float)ACT_RELOAD},

};

Schedule_t slBarneyReload[] =
{
{tlBarneyReload,
ARRAYSIZE(tlBarneyReload),
bits_COND_HEAVY_DAMAGE | bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"Reload"
},
};

DEFINE_CUSTOM_SCHEDULES(CBarney){
...
slBarneyReload,
};

IMPLEMENT_CUSTOM_SCHEDULES(CBarney, CTalkMonster);

void CBarney::RunTask(Task_t* pTask)
{
switch (pTask->iTask)
{

case TASK_RELOAD:
{
if (pTask->iTask == TASK_RELOAD)
{
m_IdealActivity = ACT_RELOAD;
return;
}

case TASK_RANGE_ATTACK1:
if (m_hEnemy != NULL && (m_hEnemy->IsPlayer()))
{
pev->framerate = 1.5;
}
CTalkMonster::RunTask(pTask);
break;
default:
CTalkMonster::RunTask(pTask);
break;


CTalkMonster::RunTask(pTask);
}
}
}

void CBarney::BarneyFirePistol()
{
Vector vecShootOrigin;

UTIL_MakeVectors(pev->angles);
vecShootOrigin = pev->origin + Vector(0, 0, 55);
Vector vecShootDir = ShootAtEnemy(vecShootOrigin);

Vector angDir = UTIL_VecToAngles(vecShootDir);
SetBlending(0, angDir.x);
pev->effects = EF_MUZZLEFLASH;

FireBullets(1, vecShootOrigin, vecShootDir, VECTOR_CONE_2DEGREES, 1024, BULLET_MONSTER_357);
m_cAmmoLoaded--;
int pitchShift = RANDOM_LONG(0, 20);

// Only shift about half the time
if (pitchShift > 10)
pitchShift = 0;
else
pitchShift -= 5;
EMIT_SOUND_DYN(ENT(pev), CHAN_WEAPON, "barney/ba_attack2.wav", 1, ATTN_NORM, 0, 100 + pitchShift);

CSoundEnt::InsertSound(bits_SOUND_COMBAT, pev->origin, 384, 0.3);

}

Schedule_t* CBarney::GetSchedule()
{
{
case MONSTERSTATE_COMBAT:
{
...
if (HasConditions(bits_COND_NO_AMMO_LOADED))
return GetScheduleOfType(SCHED_RELOAD);

return CTalkMonster::GetSchedule();
}
Posted 2 years ago2022-11-08 23:29:47 UTC Post #347063
Ok nevermind, I found the 'Extended Half Life' SDK and used it as reference, so after a re-design is working now:

void CBarney::HandleAnimEvent(MonsterEvent_t* pEvent)
{
switch (pEvent->event)
{
case BARNEY_AE_RELOAD:
...

Task_t tlBarneyReload[] =
{
{TASK_STOP_MOVING, (float)0},
{TASK_FACE_ENEMY, (float)0},
{TASK_PLAY_SEQUENCE, (float)ACT_RELOAD},
};
Schedule_t slBarneyReload[] =
{
{tlBarneyReload,
ARRAYSIZE(tlBarneyReload),
bits_COND_HEAVY_DAMAGE | bits_COND_HEAR_SOUND,
bits_SOUND_DANGER,
"Reload"},
};

case MONSTERSTATE_COMBAT:
...
if (m_cAmmoLoaded <= 0)
{
m_cAmmoLoaded = 2;
return GetScheduleOfType(SCHED_RELOAD);
}
...
Posted 2 years ago2022-11-09 00:22:51 UTC Post #347066
Good to hear 🙂
Oskar Potatis Oskar Potatis🦔
You must be logged in to post a response.