VERC: Basing one monster class off another Last edited 22 years ago2002-11-13 00:37:00 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

This article was recovered from an archive and needs to be reviewed

  1. The formatting may be incorrect as it was automatically converted to WikiCode from HTML, it needs to be revised and reformatted
  2. Some information may be out of date as it was written before Half-Life was available on Steam
  3. After the article is re-formatted and updated for Steam HL, remove this notice
  4. Please do not remove the archive notice from the bottom of the article.
  5. Some archive articles are no longer useful, or they duplicate information from other tutorials and entity guides. In this case, delete the page after merging any relevant information into other pages. Contact an admin to delete a page.
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
{
public :
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");
UTIL_SetSize(pev, VEC_HUMAN_HULL_MIN, VEC_HUMAN_HULL_MAX);

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;

MonsterInit();
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 )
{
PRECACHE_MODEL("models/cleansuit_scientist.mdl");
PRECACHE_SOUND("scientist/sci_pain1.wav");
PRECACHE_SOUND("scientist/sci_pain2.wav");
PRECACHE_SOUND("scientist/sci_pain3.wav");
PRECACHE_SOUND("scientist/sci_pain4.wav");
PRECACHE_SOUND("scientist/sci_pain5.wav");

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

CTalkMonster::Precache();
}
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!
This article was originally published on the Valve Editing Resource Collective (VERC).
TWHL only archives articles from defunct websites. For more information on TWHL's archiving efforts, please visit the TWHL Archiving Project page.

Comments

You must log in to post a comment. You can login or register a new account.