Forum posts

Posted 11 months ago2023-11-28 23:20:44 UTC
in Issues with copy-pasted entity code Post #348104
I'm making a simple monster for my mod which is basically a copy of the Barney entity. I copied barney.cpp from the source code, then renamed everything to the name of my custom monster. I took care to make sure that everything was using the right case (i.e. CBarney vs. BARNEY_AE_DRAW vs. monster_barney), that the file paths were correct, and that the code still made sense. Even though it compiles fine and I can't see what I did wrong, I get the error message Can't init monster_custom in the console. This is the code I used (you can see at this point I've just replaced "barney" with the name of the monster):
https://pastebin.com/gicA49DR (using pastebin because the code was too long)

models/custom.mdl and sound/custom/... are real files and directories and have the expected contents.

EDIT: I am a moron. The solution was to actually compile the DLL and fix all the errors. I forgot I didn't even try to recompile first.
Posted 11 months ago2023-11-26 19:16:35 UTC
in How do I override engine (*pfn...) funcs? Post #348097
I'm trying to modify the game_text entity to allow for custom font sizes. I implemented the custom parameter fontSize, but the next step is getting the HUD message system to display my text. I was able to find this cryptic-looking code which writes a message to be displayed on the HUD, and implemented my custom parameter:
void UTIL_HudMessage( CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage )
{
    if ( !pEntity || !pEntity->IsNetClient() )
        return;

    MESSAGE_BEGIN( MSG_ONE, SVC_TEMPENTITY, NULL, pEntity->edict() );
        WRITE_BYTE( TE_TEXTMESSAGE );
        WRITE_BYTE( textparms.channel & 0xFF );

        WRITE_SHORT( FixedSigned16( textparms.x, 1<<13 ) );
        WRITE_SHORT( FixedSigned16( textparms.y, 1<<13 ) );
        WRITE_BYTE( textparms.effect );

        WRITE_BYTE( textparms.r1 );
        WRITE_BYTE( textparms.g1 );
        WRITE_BYTE( textparms.b1 );
        WRITE_BYTE( textparms.a1 );

        WRITE_BYTE( textparms.r2 );
        WRITE_BYTE( textparms.g2 );
        WRITE_BYTE( textparms.b2 );
        WRITE_BYTE( textparms.a2 );

        WRITE_SHORT( FixedUnsigned16( textparms.fadeinTime, 1<<8 ) );
        WRITE_SHORT( FixedUnsigned16( textparms.fadeoutTime, 1<<8 ) );
        WRITE_SHORT( FixedUnsigned16( textparms.holdTime, 1<<8 ) );

        WRITE_SHORT( textparms.fontSize ); // my code

        if ( textparms.effect == 2 )
            WRITE_SHORT( FixedUnsigned16( textparms.fxTime, 1<<8 ) );

        if ( strlen( pMessage ) < 512 )
        {
            WRITE_STRING( pMessage );
        }
        else
        {
            char tmp[512];
            strncpy( tmp, pMessage, 511 );
            tmp[511] = 0;
            WRITE_STRING( tmp );
        }
    MESSAGE_END();
}
I was able to trace the MESSAGE_BEGIN() macro to "enginecallback.h", where the macro is defined to call a function in "eiface.h", which is defined as this:
void (*pfnMessageBegin) (int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);

No matter how hard I looked, though, I couldn't seem to find the body of void pfnMessageBegin(int, int, float, edict_t) that the pfnMessageBegin pointer in "eiface.h" was referencing. How do I change this code to use my custom data?