Coding issue: Monster infighting! Created 1 year ago2023-01-07 23:13:58 UTC by Alexis_of_Steel Alexis_of_Steel

Created 1 year ago2023-01-07 23:13:58 UTC by Alexis_of_Steel Alexis_of_Steel

Posted 1 year ago2023-01-07 23:13:58 UTC Post #347222
Hello all, and happy new year!

I want to make an NPC (who is an enemy of the player) attack another NPC who accidentally damaged him. For example, if a monster_zombie is hit by a lightning bolt launched by a monster_alien_slave, then the former starts fighting the latter (ignoring the player momentarily).

So far, I did this that gives me error:

In zombie.cpp:
int CZombie :: TakeDamage( entvars_t *pevInflictor, entvars_t *pevAttacker, float flDamage, int bitsDamageType )
{
    // Trying to accomplish, unsuccessfully, monster infighting
    if ( pevAttacker->flags & FL_MONSTER )
    {
        ALERT( at_console, "Monster infighting!\n" );
        m_hEnemy->pev = pevAttacker;
    }
(...)
}
Once the monster_zombie takes damage from, in this case, a monster_alien_slave that launched its beam, the console displays the following message:
"Host_Error: WriteDest_Parm: not a client". And the game ends.

Maybe what I did is wrong (most likely.) Does anyone know how to achieve the monster infighting in Half-Life (if possible)?
Also, I want that once the monster_zombie has killed the monster_alien_slave (or simply the latter has died for another reason), the former starts attacking the player again.

Thanks in advance.
Posted 1 year ago2023-01-09 20:07:40 UTC Post #347224
I'm not very familiar with the ins and outs of the HL codebase, but m_hEnemy->pev = pevAttacker doesn't look right - you're not checking whether m_hEnemy is null, but also, you're modifying the current target instead of switching to another target. If I understand things correctly then you need to set m_hEnemy to GetMonsterPointer(pevAttacker).

Actually, it looks like CBaseMonster has a mechanism for remembering previous enemies, so I would try using the PushEnemy function instead of changing m_hEnemy directly.
Posted 1 year ago2023-01-11 20:47:45 UTC Post #347228
What you should probably do is take a look at the code for barney getting mad when shot/attacked by the player, im pretty sure it uses monster conditions, so what you probably want to do is: define a new monster condition (or use an existing unused one), then make an exception in the code that checks which monster can attack which (the classify code) so that it can attack any monster as long as it has the condition bit set then set m_hEnemy to GetMonsterPointer(PushEnemy function) like Captain P said
You must be logged in to post a response.