Lords of Coding, I need help!!11!!one Created 3 years ago2021-02-11 19:10:02 UTC by Alexis_of_Steel Alexis_of_Steel

Created 3 years ago2021-02-11 19:10:02 UTC by Alexis_of_Steel Alexis_of_Steel

Posted 3 years ago2021-02-11 19:10:03 UTC Post #345332
Hey, Lord of coding, I know your knowledge of Half-Life programming is vastly superior to mine. For dat reason, I ask for your help! :D

I want the beam that I have created (simulating the orange beam of the tau cannon) to come out from an $attachment that I defined from the QC file of my model, and not from the model's origin, as you can see in the image that I attach here:
This is the problem!This is the problem!
This is the bunch of code I wrote so far:
void CHEVScientistGauss :: HandleAnimEvent( MonsterEvent_t *pEvent )
(...)
case HEVGAUSS_AE_SHOOT_GAUSS:
{
    if (m_hEnemy != NULL)
    {
        TraceResult tr;
        Vector vecSrc, vecAngles;
        vecAngles = ShootAtEnemy( vecSrc );
        UTIL_TraceLine( vecSrc, vecSrc + vecAngles * 1024, dont_ignore_monsters, ENT( pev ), &tr);
        CBaseEntity *pEntity = CBaseEntity::Instance(tr.pHit);
        if (pEntity != NULL && pEntity->pev->takedamage)
        {
            ClearMultiDamage();
            pEntity->TraceAttack( pev, gSkillData.hevscientistGaussDmg, pev->velocity, &tr, DMG_SHOCK );
            ApplyMultiDamage( pev, pev );
        }
        MESSAGE_BEGIN( MSG_BROADCAST, SVC_TEMPENTITY );
            WRITE_BYTE( TE_BEAMENTPOINT );
            WRITE_SHORT( entindex() );
            WRITE_COORD( tr.vecEndPos.x );
            WRITE_COORD( tr.vecEndPos.y );
            WRITE_COORD( tr.vecEndPos.z );
            WRITE_SHORT( m_iBeam );
            WRITE_BYTE( 0 );
            WRITE_BYTE( 0 );
            WRITE_BYTE( 1 );
            WRITE_BYTE( 10 );
            WRITE_BYTE( 0 );
            WRITE_BYTE( 255 );
            WRITE_BYTE( 128 );
            WRITE_BYTE( 0 );
            WRITE_BYTE( 128 );
            WRITE_BYTE( 0 );
        MESSAGE_END();
        EMIT_SOUND( ENT(pev), CHAN_WEAPON, "weapons/gauss2.wav", 1, ATTN_NORM );
    }
}
break;
Thanks guys for your time. :glad:
Posted 3 years ago2021-02-11 20:42:11 UTC Post #345333
Not the most helpful answer from me here since I'm still learning myself, but have you checked the code used for the HGrunt muzzle flashes etc. ?
Obviously for that animation the origin of the flash is set at the end of the gun attachment, so I imagine you just have to do the exact same thing here.

Anyway sorry if that doesn't help. Hope you get it sorted.
Posted 3 years ago2021-02-12 02:01:32 UTC Post #345334
Hello hermanJnr, thank for your response! I still can't find a solution for my problem :(
Posted 3 years ago2021-02-12 12:11:09 UTC Post #345335
To attach it to an attachment you need to pass the attachment index along like this:
WRITE_SHORT(entindex() + (attachmentIndex << 12));
Where attachmentIndex is the attachment index + 1 (0 means use entity origin).
Posted 3 years ago2021-02-12 15:34:11 UTC Post #345338
Hello Solokiller. Thanks for answering. When I replace WRITE_SHORT( entindex() ); with WRITE_SHORT(entindex() + (attachmentIndex << 12)); it says identifier "attachmentIndex" is undefined. And it fails to compile. :cry:
Posted 3 years ago2021-02-12 16:35:24 UTC Post #345339
You're supposed to replace attachmentIndex with the number matching the attachment.
Posted 3 years ago2021-02-12 20:15:52 UTC Post #345340
Oh, I feel stupid :lol: Thank you, Solokiller. It works! My problem is solved! You're one of those Lords of coding!
Valve, we got a lord of coding here!Valve, we got a lord of coding here!
You must be logged in to post a response.