Half-Life Re-imagined competition results on their way...
Check out Skewing textures in Hammer, our newest tutorial!
Say hello to csapdani, our newest member!


Site Stuff






Feeling Blue

What's your favourite shade of blue?














4 mins


12 mins


16 mins


17 mins


18 mins


19 mins


29 mins



A gaming and technology blog by TWHL admins Penguinboy and Ant. A music blog by TWHL users Ant and Hugh.

Basing one monster class off another

By Caleb 'Ghoul' Delnay

Ok, so you want two monsters that are actually a lot alike, for example, Human Grunts and Male Assassins (from Gearbox's Opposing Force) or a scientist in a cleansuit (also from Opposing Force). Well, this is actually really simple even if you have the most basic of C++ knowlege.

Now, programming time, let's make a cleansuit scientist. Open up your scientist.cpp file and find the Spawn function of CDeadScientist. After it we want to declare our new scientist, so:

// Clean Suit Scientist

class CCleanSuitScientist : public CScientist
     void Spawn(void);
     void Precache(void);
     BOOL CanHeal(void);

This of course is our class and the functions it has. Notice that it is public CScientist. This gives our CCleanSuitScientist all the same funcions as a normal CScientist. However, we are overriding three of the CScientist functions with our own functions. We need a new Spawn function because this is where the model for the monster is set, and our cleansuit scientist has a cleansuit on, not a normal lab coat. A new Precache is needed because the cleansuits model file is precached here by the engine, and we wouldn't want to precache the wrong model, now would we? Finally, we have an overridden CanHeal function because the normal Opposing Force model doesn't have a needle to even heal you with, so having a cleansuit scientist heal you with nothing wouldn't make sense, right? So, now we need the actual bodies of these functions, which will go right below, but first don't forget the link function which adds your monster to an entity name!

LINK_ENTITY_TO_CLASS( monster_cleansuit_scientist , CCleanSuitScientist);

That should do, now for the three functions.

BOOL CCleanSuitScientist::CanHeal(void)
     return FALSE;

Ok, this is our overridden CanHeal function. It always returns FALSE no matter what, so the scientist will never be able to heal you. Now for the Spawn function.

// Spawn

void CCleanSuitScientist::Spawn(void)
     Precache( );

     SET_MODEL(ENT(pev), "models/cleansuit_scientist.mdl");

     pev->solid               = SOLID_SLIDEBOX;
     pev->movetype          = MOVETYPE_STEP;
     m_bloodColor          = BLOOD_COLOR_RED;
     pev->health               = gSkillData.scientistHealth;
     // position of the eyes relative to monster's origin.
     pev->view_ofs          = Vector ( 0, 0, 50 );

     // NOTE: we need a wide field of view so scientists will notice player and say hello
     m_flFieldOfView          = VIEW_FIELD_WIDE;
     m_MonsterState          = MONSTERSTATE_NONE;

//     m_flDistTooFar          = 256.0;

     m_afCapability          = bits_CAP_HEAR | bits_CAP_TURN_HEAD | bits_CAP_OPEN_DOORS | bits_CAP_AUTO_DOORS | bits_CAP_USE;

     // White hands
     pev->skin = 0;

     if ( pev->body == -1 )
     { // -1 chooses a random head
          // pick a head, any head
          pev->body = RANDOM_LONG(0, NUM_SCIENTIST_HEADS-1);

     // Luther is black, make his hands black
     if ( pev->body == HEAD_LUTHER )
          pev->skin = 1;
     SetUse( FollowerUse );

Notice that it is almost exactly like the normal scientists Spawn function, except we are setting the model to have a different model. Next up is the Precache function!

// Precache - precaches all resources this monster needs

void CCleanSuitScientist::Precache(void)

     // every new scientist must call this, otherwise
     // when a level is loaded, nobody will talk (time is reset to 0)



Again this is almost exactly like the CScientist's Spawn function, but we are precaching our cleansuit model and not the normal scientist model.

Oddly enough, thats it! Now you should be able to add in your monster_cleansuit_scientist entry into the .fgd and place him in a map. All should work fine assuming you have the model in your models directory!

While this technique seems quite a waste compared too the other shorter method of creating such slightly different monsters, it works. However, I find this method perfect when making things very similar like different zombie types, or perhaps new marine types with different settings and the like. Good luck and good programming!