Tutorials

Alternate Zombies in Your Mod



Description

In this tutorial, i'm going to show you how to add more than one type of 'classic' zombie to your mod. We're going to be coding so i assume you have everything setup already. If not here's some links to get you started:
Link to Valve Developer Community:http://developer.valvesoftware.com/wiki/Category:Programming
Link to compiler:http://developer.valvesoftware.com/wiki/Compiler_Choices

Tutorial

Open up your Game_HL2-2008.sln file, or whatever it's name is on your end, might be 2003 or 2005, it depends.
Locate and open the npc_zombie.cpp file. Path in VC++: server_hl2/Source files/HL2 dll/npc_zombie.cpp

In npc_zombie.cpp find " class CZombie : public CAI_BlendingHost<CNPC_BaseZombie> " - Should be near line 81
Then scroll down and find where it says " private: " and under that add:

int                             m_iSkin;


As you probably already know, C++ is CASE SENSITIVE.
What it looks like on my end:
news post image

Then search for " BEGIN_DATADESC( CZombie ) " - No Quotation marks.
In here we'll add the keyvalue so we can change m_iSkin's value in hammer.
After " DEFINE_FIELD( m_flDoorBashYaw, FIELD_FLOAT ), " add:

DEFINE_KEYFIELD( m_iSkin, FIELD_INTEGER, "skin" ),


What it looks like on my end:
news post image

Now we'll get to the 'Selecting model' part.
Find: ' CZombie::SetZombieModel ( void ) '
and replace it with:

void CZombie::SetZombieModel( void )
{
	Hull_t lastHull = GetHullType();

	if ( m_fIsTorso )
	{
		SetModel( "models/zombie/classic_torso.mdl" );
		SetHullType( HULL_TINY );
	}

	if ( !m_fIsTorso && m_iSkin == 1)
	{
		SetModel( "models/zombie/classic.mdl" );
		SetHullType (HULL_HUMAN);
	}
	else if( !m_fIsTorso && m_iSkin == 2)
	{
		SetModel( "models/zombie/zclassic_01.mdl" );
		SetHullType (HULL_HUMAN);
	}
	else if( !m_fIsTorso && m_iSkin == 3)
	{
		SetModel( "models/zombie/zclassic_03.mdl" );
		SetHullType (HULL_HUMAN);
	}




	SetBodygroup( ZOMBIE_BODYGROUP_HEADCRAB, !m_fIsHeadless );

	SetHullSizeNormal( true );
	SetDefaultEyeOffset();
	SetActivity( ACT_IDLE );

	// hull changed size, notify vphysics
	// UNDONE: Solve this generally, systematically so other
	// NPCs can change size
	if ( lastHull != GetHullType() )
	{
		if ( VPhysicsGetObject() )
		{
			SetupVPhysicsHull();
		}
	}
}



news post image

You can add as many other models as you want - Just remember to precache them too!
Which we'll do right now!

Find: ' void CZombie::Precache( void ) ' and add your model names.
Mine are:

	PrecacheModel( "models/zombie/classic.mdl" );
	PrecacheModel( "models/zombie/zclassic_01.mdl" );
        PrecacheModel( "models/zombie/zclassic_03.mdl" );
	PrecacheModel( "models/zombie/classic_torso.mdl" );
	PrecacheModel( "models/zombie/classic_legs.mdl" );



Now compile and remember to copy the dlls into your bin folder in your mod folder!
(My compiler stopped doing that somewhere along the line and it really really foiled my plans for quite awhile, since i didn't realize that it had stopped, so write a batch script to do it for you or manually copy them.)

One last thing before we're ready! We gotta get the new keyvalue into hammer!
So go here: C:\Steam\steamapps\USERNAME\sourcesdk\bin\ep1\bin\
Find the halflife2.fgd file and make a copy and name it after your mod(Or whatever you feel like really).
Now open the .fgd file you've just created and search for npc_zombie
You should find something like:

news post image

What it SHOULD look like when we're done:

news post image
Add this code:

	skin(choices) : "Version" : 3 =
	[
		1 : "Version 1"
		2 : "Version 2"
                3 : "Version 3"
	]


It has to be exactly like that above. You can however change the things in "" as you please and the number of "Version #" too of course. But everything else relates to the code we just wrote, so if you change it, it breaks.

Now save the .fgd file and add it in hammer and you should be done!

If i perhaps missed something, or i didn't explain something clearly enough please don't hesitate to let me know.

- Corewarp

View comments ( 23 )

Back to top